用PDFBOX读取PDF内容

12次阅读

共计 558 个字符,预计需要花费 2 分钟才能阅读完成。

PDFBox(一个 BSD 许可下的源码开放项目)是一个为开发人员读取和创建 PDF 文档而准备的纯 Java 类库。
主要功能:提取文本,包括 Unicode 字符和 Jakarta Lucene 等文本搜索引擎的整合过程十分简单加密 / 解密 PDF 文档从 PDF 和 XFDF 格式中导入或导出表单数据向已有 PDF 文档中追加内容将一个 PDF 文档切分为多个文档覆盖 PDF 文档
示例代码使用的 jar
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.14</version>
</dependency>
1. 读取 PDF 内容
PDDocument helloDocument = null;
try {
helloDocument = PDDocument.load(new File(“XXX.pdf”));

PDFTextStripper textStripper = new PDFTextStripper();
System.out.println(textStripper.getText(helloDocument));

helloDocument.close();
} catch (IOException e) {
e.printStackTrace();
}

正文完
 0