我正在使用PDFMergerUtility
Java 合并 PDF 内容。
PDFMergerUtility bundle= new PDFMergerUtility();
bundle.addSource(new ByteArrayInputStream(contentService.retrieveData(transaction1);
bundle.addSource(new ByteArrayInputStream(contentService.retrieveData(transaction2);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream()
bundle.setDestinationStream(outputStream); // setting outputstream
bundle.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
return outputStream.toByteArray(); // returning result
但默认情况下,当我尝试打开生成的 PDF 时,它会在 PDF 的最后一页打开。我没有为这些使用 PDocument,因为这些是基于实体的文档。因此无法使用以下方法。您能否建议任何方法来直接设置打开的页码PDFMergerUtility
。
PDPageXYZDestination destination = new PDPageXYZDestination();
destination .setPageNumber(num);
PDActionGoTo action = new PDActionGoTo();
action.setDestination(destination );
pdf.getDocumentCatalog().setOpenAction(action);