【Java】PDFBox 一个开源的PDF支持库
前言
因为 billhelp 项目需要增加一个pdf合并的功能,故而有了这次的改造之旅
这里我用了pdfbox
支持库,
The Apache PDFBox library is an open source Java tool for working with PDF documents. This project allows creation of new PDF documents, manipulation of existing documents and the ability to extract content from documents. PDFBox also includes several command line utilities. PDFBox is published under the Apache License, Version 2.0.
maven引用
<!-- https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox -->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.26</version>
</dependency>
gradle引用
// https://mvnrepository.com/artifact/org.apache.pdfbox/pdfbox
implementation group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.26'
代码示例
/** * 合并pdf * @return */
private static int mergePDF(String path) throws IOException{
PDFMergerUtility pdfMerger= new PDFMergerUtility();
File f=new File(path);
File[] pdffiles=f.listFiles();
for (File file : pdffiles) {
pdfMerger.addSource(file);
}
pdfMerger.setDestinationFileName(path+"\\merger.pdf");
pdfMerger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
return 0;
}
参考
Maven Repository
Getting Started
合并pdf示例
本文来自:【Java】PDFBox 一个开源的PDF支持库-小码农,转载请保留本条链接,感谢!
温馨提示:
本文最后更新于 2022年10月27日,已超过 756 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我。
正文到此结束
- 本文标签: PDF pdfbox
- 本文链接: https://djc8.cn/archives/java-pdfbox-is-an-open-source-pdf-support-library.html
- 版权声明: 本文由小码农原创发布,转载请遵循《署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)》许可协议授权