asp.net, itextshape format

Posted on 2012-09-13
Medium Priority
Last Modified: 2012-09-24
I have the following code working fine to create table with itextsharp,
my question is i will have more tables like table1, table2 for something.
How can i make default format for all of the table?
like I want all of the table has totalwidth = 540f?


PdfPTable table = new PdfPTable(2); //Table with 2 columns
            //table format
            table.TotalWidth = 540f;
            table.LockedWidth = true;
            var titleFont = FontFactory.GetFont("Arial", 18, Font.BOLD);
            var subTitleFont = FontFactory.GetFont("Arial", 14, Font.BOLD);
            var boldTableFont = FontFactory.GetFont("Arial", 12, Font.BOLD);
            var endingMessageFont = FontFactory.GetFont("Arial", 10, Font.ITALIC);
            var bodyFont = FontFactory.GetFont("Arial",8, Font.NORMAL);
            table.HorizontalAlignment = 0;
            table.SpacingBefore = 10;
            table.SpacingAfter = 10;
            table.DefaultCell.Border = 1;
            //table.SetWidths(new int[] { 1, 4 });
Question by:solution1368
LVL 44

Accepted Solution

Karl Heinz Kremer earned 2000 total points
ID: 38399404
You cant. The default width for a table is 80% of the available width (e.g. page width minus margins). You want a different width, so you have to override the default (as you are doing).

You could create your own table class, derived from PdfPTable and then in the constructor set your width, or, you could write a function that creates a table for you with all the settings that you need.

Author Comment

ID: 38400151
so if we have 100 tables(PdfPTable table = new PdfPTable(2)) to be created.

do we have any options to set master settings like

            table.SpacingBefore = 10;
            table.SpacingAfter = 10;
            table.DefaultCell.Border = 1;

If yes, how to do that? Thanks

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Inserting page numbers in Portable Document Files not only enhances manageability but also makes them look professional. With numbered pages, the file appears more organized and it becomes easier to search for a particular page. The size and the vol…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
We often encounter PDF files that are pure images, that is, they do not have text characters, but instead contain only raster graphics. The most common causes of this are document scanning software and faxing software/services that create image-only…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question