Is it possible to find text position with iText

前端 未结 1 432
你的背包
你的背包 2021-01-14 17:41

Is it possible to find the text position using iText? I saw the RenderListener interface that has beginTextBlock, renderText and endTextBlock but

相关标签:
1条回答
  • 2021-01-14 18:33

    The TextRenderInfo parameter passed to renderText() contains that information. Specifically, you need to look at the return values from getBaseLine() and getAscentLine().

    These two line segments are in User Space (what you see on the page). They define the bounding box of the current chunk of text. Kind of a goofy way of presenting it, but it works.

    Note that stuffing the end points into a Rectangle may not work depending on how the text is rotated. If you're not worried about rotation, then it's no big deal. If you are, you need to start monkeying with trig. Have "fun".

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