Draw a rectangle at the *current position* and then get its position coordinates

前端 未结 1 1400
清歌不尽
清歌不尽 2021-01-28 18:45

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

相关标签:
1条回答
  • 2021-01-28 19:09

    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).

    0 讨论(0)
提交回复
热议问题