MisterMister
2021-07-05 17:56
采纳率: 66.7%
浏览 74
已采纳

itext 合并pdf 后签字域丢失,救我

public static boolean mergePdfs(String pdfpath,String pdfname,List paths){
boolean result = true;
PdfReader pdfreader = null;
Document document = null;
FileOutputStream outputStream = null;
PdfCopy copy = null;
try {
pdfreader = new PdfReader(pdfpath + "0.pdf");
document = new Document(pdfreader.getPageSize(1));
outputStream = new FileOutputStream(pdfpath + pdfname);
copy = new PdfCopy(document, outputStream);
document.open();
int i = 0;
while(i <= paths.size() - 1){
PdfReader tempReader = new PdfReader(paths.get(i));
int n = tempReader.getNumberOfPages();
for (int j = 1; j <= n; j++) {
document.newPage();
PdfImportedPage page = copy.getImportedPage(tempReader, j);
copy.addPage(page);
}
tempReader.close();
i++;
}
copy.close();
outputStream.close();
document.close();
pdfreader.close();
} catch (Exception e) {
logger.error("PdfUtils.mergePdfs异常[{}]",e);
return false;
}finally {
try {
copy.close();
outputStream.close();
document.close();
pdfreader.close();
} catch (IOException e) {
logger.error("PdfUtils.getBusOrderPaths异常:[{}]", e);
}
}
return result;
}

以上代码合并pdf,原有的pdf有签字域,合并生成的新pdf,签字域丢失(java代码获取不到签字域),哪位大佬看下

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • MisterMister 2021-07-06 11:05
    已采纳

    靠人不如靠自己啊
    PdfCopy copy = new PdfSmartCopy(document, new FileOutputStream(pdfdpath + pdfname));
    copy.setMergeFields();

    完美解决

    点赞 1 打赏 评论

相关推荐 更多相似问题