【发布时间】:2011-04-04 20:39:46
【问题描述】:
我想使用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 是一个包含所有PDF 文件的ArrayList<String>。
当我运行上述内容时,我总是得到:
org.apache.pdfbox.exceptions.COSVisitorException: Bad file descriptor
我做错了吗?还有其他方法吗?
【问题讨论】:
-
有人指出 iText [java-x.blogspot.com/2006/11/merge-pdf-files-with-itext.html] 然后删除了答案。它奏效了,谢谢。
-
link 可能会帮助寻找答案的人。