Justin C
Justin C

Reputation: 1924

itextSharp: Table disappears when added to Paragraph with KeepTogether=true

I am exporting some data to a PDF and I have been using iTextSharp with a lot of success, but I just hit a wall.

I have a group of information I need to keep on a single page. This information includes a handful of other Paragraph objects and tables. I can add 3 Paragraphs to another parent Paragraph and set that parent's KeepTogether property to true and everything works great.

When I add a PdfPTable to the Paragraph with KeepTogether set to true, the table disappears. No Exceptions or error messages, the table just disappears.

Any clue as to what is happening? Is there a work around? Should I be coding differently, like is there a better parent control than Paragraph to keep text and tables together on one page?

Upvotes: 1

Views: 2777

Answers (1)

Justin C
Justin C

Reputation: 1924

So I fixed the issue by approaching it a different way. Now I make sure to never set a KeepTogether property to true for paragraphs or tables.

Then, when I want a Paragraph that contains child paragraphs and PdfPTables, I add it to a one column, one cell, PdfPTable with its KeepTogether flag set to true.

So that works perfectly, just a little dirty.

Upvotes: 2

Related Questions