Dav*_*ave 15 c# pdf itextsharp
我正在使用iTextSharp和reader.GetPageContent方法从PDF中提取文本.我需要找到文档中找到的每个单词的矩形/位置.有没有办法使用iTextSharp获取PDF中单词的矩形/位置?
Mar*_*rer 21
就在这里.text.pdf.parser具体来说,请查看包装LocationTextExtractionStrategy.实际上,这可能也不行.你可能想写自己的东西TextExtractionStrategy来输入PdfTextExtractor:
MyTexExStrat strat = new MyTexExStrat();
PdfTextExtractor.getTextFromPage(reader, pageNum, strat);
// get the strings-n-rects from strat.
public class MyTexExStrat implements TextExtractionStrategy {
void beginTextBlock() {}
void endTextBlock() {}
void renderImage(ImageRenderInfo info) {}
void renderText(TextRenderInfo info) {
// track text and location here.
}
}
Run Code Online (Sandbox Code Playgroud)
您可能希望查看LocationTextExtractionStrategy的源代码,以了解它如何组合共享基线的文本.您甚至可以修改LTES以存储字符串和rects的并行数组.
PS:要构建rects,你可以获得AscentLine和DescentLine并使用这些坐标作为顶角和底角:
Vector bottomLeft = info.getDescentLine().getStartPoint();
Vector topRight = info.getAscentLine().getEndPoint();
Rectangle rect = new Rectangle(bottomLeft.get(Vector.I1),
bottomLeft.get(Vector.I2),
topRight.get(Vector.I1),
topRight.get(Vector.I2));
Run Code Online (Sandbox Code Playgroud)
警告:上面的代码说明文本是水平的,从左到右进行.旋转的文本会将其搞砸,垂直文本或从右到左(阿拉伯语,希伯来语)文本也是如此.对于大多数应用程序,上面应该没问题,但知道它的限制.
好狩猎.
| 归档时间: |
|
| 查看次数: |
28057 次 |
| 最近记录: |