0

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.NEWLINEs 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.NEWLINEs, meaning that the content on the next page starts with two Chunk.NEWLINEs rather than at the top of the page.

Is there a way to somehow suppress Chunk.NEWLINEs 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

4

0 回答 0