使用PDFBox从特定页面读取文本 [英] read text from a particular page using PDFBox

查看:1354
本文介绍了使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆