So, I am writing some text into a PDF file using iTextSharp.
After having added a few paragraphs and phrases to the PDF document, I want to:
Draw the next piece
Seems that you are looking for the Chunk.setBackground() method. This draws a colored background underneath some text. There's also a variation of the method that takes extra parameters if you need a larger or smaller rectangle.
Suppose that you don't want a colored rectangle, but a custom type of shape, then you'd use the page event onGenericTag(). See Chunk > Generic tag for more info.
The onGenericTag()
method is triggered every time a Chunk
that is marked as generic (using the setGenericTag() method) is rendered to a page. Your implementation of the page event can then use the Rectangle
value that is passed to the event method. It is important to understand that a single Chunk
marked as a generic tag can result in multiple invocations of this method: if the contents of a single Chunk
needs to be distributed over different lines, the event will be triggered as many times as there are lines (giving you a separate Rectangle
value for every separate line).