我想使用 PDFBox 将许多 PDF 文件合并为一个,这就是我所做的:
PDDocument document = new PDDocument();
for (String pdfFile: pdfFiles) {
PDDocument part = PDDocument.load(pdfFile);
List<PDPage> list = part.getDocumentCatalog().getAllPages();
for (PDPage page: list) {
document.addPage(page);
}
part.close();
}
document.save("merged.pdf");
document.close();
其中 pdfFiles
是 ArrayList<String>
包含所有 PDF 文件。
当我运行上述内容时,我总是得到:
org.apache.pdfbox.exceptions.COSVisitorException: Bad file descriptor
难道我做错了什么?还有其他方法吗?
原文由 Lipis 发布,翻译遵循 CC BY-SA 4.0 许可协议
为什么不使用 pdfbox 的 PDFMergerUtility ?