0
我想合并PDF文件,但在打开文件时出现错误。我的代码是:合并Pdf:错误:打开此文档时出错无法打开,因为它没有页面
public void merge(){
byte[] pdf1 = tobyte("hello");
byte[] pdf2 = tobyte("world");
PDFMergerUtility merger = new PDFMergerUtility();
merger.addSource(new ByteArrayInputStream(pdf1));
merger.addSource(new ByteArrayInputStream(pdf2));
merger.setDestinationFileName("final.pdf");
merger.mergeDocuments();
}
static byte[] tobyte(String message) {
PDDocument doc = new PDDocument();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.save(baos);
return baos.toByteArray();
}
)的代码,我就指出,你不使用''里面tobyte message'('。 – shmosel
谢谢@shmosel。它的一个愚蠢的错误。 –
“这个文档文件无法打开,因为它没有页面”是真实的。您自己生成的文档没有页面。 –