alessmar
alessmar

Reputation: 4727

Is it possible to find text position with iText

Is it possible to find the text position using iText? I saw the RenderListener interface that has beginTextBlock, renderText and endTextBlock but they seems to be not useful to find text's position. If it's not possible with iText: does it exist another open source Java library that is able to do it?

Upvotes: 2

Views: 8562

Answers (1)

Mark Storer
Mark Storer

Reputation: 15890

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

Upvotes: 6

Related Questions