, itextshape format

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 });
Who is Participating?
Karl Heinz KremerCommented:
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.
solution1368Author Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.