是否可以使用iText查找文本位置 [英] Is it possible to find text position with iText
问题描述
是否可以使用iText找到文本位置?我看到 beginTextBlock的 RenderListener 界面, renderText 和 endTextBlock 但它们似乎对查找文本的位置没有用。如果使用iText是不可能的:它是否存在另一个能够做到的开源Java库?
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?
推荐答案
TextRenderInfo
传递给的参数renderText()
包含该信息。具体来说,您需要查看 getBaseLine()
和 getAscentLine()
的返回值。
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.
请注意将终点填充到 Rectangle
可能无法正常工作,具体取决于文本的旋转方式。如果你不担心轮换,那就没什么大不了的。如果你是,你需要开始使用trig进行monkeying。有乐趣。
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".
这篇关于是否可以使用iText查找文本位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!