pdf头签名异步

t1qtbnec  于 2021-06-26  发布在  Java
关注(0)|答案(0)|浏览(180)

当asynchronous不适用时,此代码没有问题,但在添加asynchronous(@async)操作后偶尔会出现问题;错误是 reader = new PdfReader(pdfInputStream); ```
@Async
public static void pdfAddWaterMark(InputStream pdfInputStream, Image image, BufferedOutputStream bos){
PdfReader reader = null;
PdfStamper stamper = null;
try {
reader = new PdfReader(pdfInputStream);
stamper = new PdfStamper(reader, bos);
int total = reader.getNumberOfPages();
PdfContentByte content;
for (int i = 0; i < total; i++) {
content = stamper.getOverContent(i + 1);
image.scaleToFit(450, 450);
image.setAbsolutePosition(60, 150);
content.addImage(image);
}
} catch (IOException | DocumentException e) {
e.printStackTrace();
}finally {
try {
stamper.close();
reader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题