iTextSharp: table row gets pushed to new page if it doesn't fit on the current one

Shagglez picture Shagglez · Jun 23, 2011 · Viewed 10.9k times · Source

I'm using iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(TextReader reader, StyleSheet style) to convert an html table into a pdf doc. Some rows contain a lot of data, and may not fit on the current page, so iTextSharp creates a new page and places the row there. If the row doesn't fit on the next page, it splits it correctly.

Is there a way to tell it to not use these page breaks? Here is what it looks like:

Row gets dropped to the next page by iTextSharp

Answer

Chris Haas picture Chris Haas · Jun 23, 2011

The trick that worked for me is to inspect the results of ParseToList() and look for any elements that are of type PdfPTable. If you see one set its SplitLate property to False. Here's some VB that you should be able to convert to C# fairly easily:

Dim Elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(SR, Nothing)
For Each El In Elements
    If TypeOf El Is PdfPTable Then
        DirectCast(El, PdfPTable).SplitLate = False
    End If
    Doc.Add(El)
Next