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();
}
发表回复