【问题标题】:how to get the TextRenderInfo from pdfpage in iText7如何从 iText7 中的 pdfpage 获取 TextRenderInfo
【发布时间】:2017-05-03 17:58:26
【问题描述】:

如何使用 iText 7 从 pdf 页面获取 TextRenderInfo。我需要查找是否存在文本并得出该 pdf 页面的 y 坐标。请问有什么建议吗?

任何带有..的选项

ITextExtractionStrategy textStrategy = new SimpleTextExtractionStrategy();
ITextExtractionStrategy locationStrategy = new LocationTextExtractionStrategy();

【问题讨论】:

  • "如何使用 iText 7 从 pdf 页面获取 TextRenderInfo" - 究竟是哪个 TextRenderInfo?通常页面内容解析会导致该类的很多实例......

标签: itext7


【解决方案1】:

简单, 实现 ITextExtractionStrategy (或扩展现有实现)。 接口有如下方法

@Override
public void eventOccurred(IEventData data, EventType type) {

     // you can first check the type of the event
     if (!type.equals(EventType.RENDER_TEXT))
        return;

     // now it is safe to cast
     TextRenderInfo renderInfo = (TextRenderInfo) data;
}

一旦有了这样的实现,就需要使用

MyCustomStrategy strategy = new MyCustomStrategy(); // this is the class I described earlier
PdfTextExtractor.getTextFromPage(doc.getPage(pageNr), strategy);

然后可以简单地对您的自定义 ITextExtractionStrategy 进行编程以存储所有 TextRenderInfo 对象。并提供一个简单的吸气剂。

【讨论】:

    猜你喜欢
    • 2017-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多