user147031
user147031

Reputation: 203

How can I repeat the headers of an iTextSharp PdfPTable on each page?

How can I get iTextSharp to repeat the headers of a PdfPTable on each page of the generated PDF?

Upvotes: 19

Views: 27535

Answers (2)

Firas Shrourou
Firas Shrourou

Reputation: 715

You can use the HeaderRows as follows:

            var dataDetails = new PdfPTable(6);
            dataDetails.HorizontalAlignment = 0;
            dataDetails.WidthPercentage = 100;
            dataDetails.SpacingBefore = 10;
            dataDetails.SpacingAfter = 10;
            dataDetails.DefaultCell.Border = 0;
            dataDetails.HeaderRows = 1;
            dataDetails.SetWidths(new int[] { 1, 3, 1, 1, 1, 1 });

Upvotes: 1

Jay Riggs
Jay Riggs

Reputation: 53593

You just need to set the PdfPTable.HeaderRows property to the number of rows in your PdfPTable's header like this:

table.HeaderRows = 1;

Upvotes: 38

Related Questions