使用PDFBox从特定页面读取文本 [英] read text from a particular page using PDFBox
问题描述
我知道如何使用 PDFTextStripper.getText(PDDocument)
来阅读整个pdf文件的文本。
<我还有一个关于如何使用
PDDocumentCatalog.getAllPages()得到对特定页面的对象引用的示例.get(i)
。 如何使用PDFBox获取一个页面的文本,因为我在 PDPage
类中没有看到任何此类方法?
您可以在 PDFTextStripper
阅读特定页面:
PDDocument doc; //文件
int i; //页面没有
PDFTextStripper reader = new PDFTextStripper();
reader.setStartPage(i);
reader.setEndPage(i);
String pageText = reader.getText(doc);
据我所知, PDPage
更多地用于表示屏幕上的页面,而不是而不是提取文本。因此,我不建议使用它来提取文本。
I know how to read text of an entire pdf file usinf PDFBox using PDFTextStripper.getText(PDDocument)
.
I also have a sample on how to get an object reference to a particular page using PDDocumentCatalog.getAllPages().get(i)
.
How do I get the text of just one page using PDFBox as I dont see any such method on PDPage
class?
You can set parameters on the PDFTextStripper
to read particular pages:
PDDocument doc; // document
int i; // page no.
PDFTextStripper reader = new PDFTextStripper();
reader.setStartPage(i);
reader.setEndPage(i);
String pageText = reader.getText(doc);
As far as I'm aware, PDPage
is more used with representing a page onscreen, rather than extracting text. As such, I wouldn't recommend using this to extract text.
这篇关于使用PDFBox从特定页面读取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!