[英]pdfbox merge pdf with form
I have a simple pdf file (a.pdf) and a pdf file with some forms in it (checkboxes, textfields, ...). 我有一个简单的pdf文件(a.pdf)和一个带有某些形式的pdf文件(复选框,文本字段等)。 I want to merge them:
我要合并它们:
public void merge () throws IOException, COSVisitorException, CryptographyException, InvalidPasswordException {
PDFMergerUtility merger = new PDFMergerUtility();
PDDocument arg0 = PDDocument.load("C:\\Users\\...\\Desktop\\a.pdf");
PDDocument arg1 = PDDocument.load("C:\\Users\\...\\Desktop\\b.pdf");
if (arg1.isEncrypted()) {
arg1.decrypt("consol");
arg1.setAllSecurityToBeRemoved(true);
}
merger.appendDocument(arg0, arg1);
arg0.save("C:\\Users\\...\\Desktop\\xout.pdf");
arg0.close();
arg1.close();
}
This basically works however the forms are not included in the target pdf file anymore. 这基本上是可行的,但是表格不再包含在目标pdf文件中。 Do you have any hints for me?
你对我有什么提示吗?
try this out : 试试看:
try {
PDFMergerUtility mpdf = new PDFMergerUtility();
String folder = "C:/Users/.../Desktop";
String destinationFileName = "output.pdf"; //say
File folderFile = new File(folder);
if (folderFile.isDirectory()) {
mpdf.addSource(folder + "/" + "a.pdf");
mpdf.addSource(folder+ "/"+"b.pdf");
mpdf.setDestinationFileName(folder + "/"+ destinationFileName);
mpdf.mergeDocuments();
} catch(Exception ex) {
logger.error(ex);
}
Hope, this will help.... 希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.