Solved, itextshape format

Posted on 2012-09-13
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

    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

    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Power PDF ( is the newest product from the Document Imaging division of Nuance Communications ( It is available in two editions — …
    *Adobe Acrobat 9 was used for this article.  Particular steps may vary depending on software versions. Adobe Acrobat has many, many variables that my be utilized to customize your forms for clarity and ease of use. The Form Editing Tool will be y…
    In this third video of the Xpdf series, we discuss and demonstrate the PDFtoText utility, which converts PDF files into plain text files. Download and install the software.: You may have already downloaded and installed the Xpdf tools while watching…
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now