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?
Share
The
TextRenderInfoparameter passed torenderText()contains that information. Specifically, you need to look at the return values fromgetBaseLine()andgetAscentLine().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
Rectanglemay 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”.