合并两个pdf
这里用到的第三方工具包:点此下载。实践证明,用maven的形式无法成功添加jar包。本人是将jar包下载后手动添加到本地maven仓库,然后再在pom.xml文件中引用。手动向本地maven库添加jar包教程
/**
* @Description: 合并两个pdf文件
* @Param: [合并后pdf文件路径及名称, 输入pdf文件1, 输入pdf文件2]
* @return: java.lang.String
* @Date: 2020/11/24
*/
@SneakyThrows
public static String mergeFiles(String outPdfPathAndName, String inPdfPathAndName1, String inPdfPathAndName2) {
FileInputStream stream1 = new FileInputStream(new File(inPdfPathAndName1));
FileInputStream stream2 = new FileInputStream(new File(inPdfPathAndName2));
InputStream[] streams = new FileInputStream[]{stream1, stream2};
PdfDocumentBase doc = PdfDocument.mergeFiles(streams);
doc.save(outPdfPathAndName);
doc.close();
return outPdfPathAndName;
}