I am using iTextSharp to generate a PDF on the fly. I am using the ColumnText
class in text mode using the ColumnText.SetColumns()
method to define column boundaries using code like the following:
myColumnText.SetColumns(leftCoords, rightCoords)
myColumnText.AddText(New Chunk("Lorem ipsum..."))
myColumnText.AddText(Chunk.NEWLINE))
myColumnText.AddText(Chunk.NEWLINE))
myColumnText.AddText(New Chunk("Lorem ipsum..."))
myColumnText.AddText(Chunk.NEWLINE))
myColumnText.AddText(Chunk.NEWLINE))
As you can see, I emit a block of text and then two Chunk.NEWLINE
s to add whitespace between paragraphs.
I then use ColumnText.Go
to emit the content, creating new pages as needed, like so:
While ColumnText.HasMoreText(myColumnText.Go())
myDocument.NewPage()
myColumnText.SetColumns(leftCoords, rightCoords)
End While
The problem I am running into is that depending on the content in the ColumnText
object a page break might occur right at the end of a chunk of text but before the Chunk.NEWLINE
s, meaning that the content on the next page starts with two Chunk.NEWLINE
s rather than at the top of the page.
Is there a way to somehow suppress Chunk.NEWLINE
s if they are the first things emitted on a new page? My thought was that if I could somehow see the text that was about to be emitted by ColumnText.Go
I could see if I was about to emit a Chunk.NEWLINE
and remove it from the content stream or something...
Thanks