2017-05-03 14 views
-1

iText 7を使用してpdfページからTextRenderInfoを取得する方法。テキストが存在するかどうかを調べ、そのpdfページのy座標を導出する必要があります。何か提案してください?iText7のpdfpageからTextRenderInfoを取得する方法

..

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

*「iText 7を使用してpdfページからTextRenderInfoを取得する方法」* - どの「TextRenderInfo」が正確にですか?通常、ページコンテンツの解析により、そのクラスの非常に多くのインスタンスが生成されます... – mkl

答えて

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; 
} 

を以下している、あなたはITextExtractionStrategyは、単にすべてのTextRenderInfoオブジェクトを格納するようにプログラムすることができ

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

カスタムを使用する必要があります。そして単純にゲッターを提供する。

関連する問題