在linux环境下,对文件增加水印会导致内存占用增加(非jvm内存占用)
public static void main(String[] args) throws IOException {
for (int i = 0; i < 50; i++) {
FileInputStream pdfInput = new FileInputStream("C:\\Users\\hy\\Desktop\\aaa.pdf");
// Create PdfFileStamp object
PdfFileStamp fileStamp = new PdfFileStamp();
// Open Document
fileStamp.bindPdf(pdfInput);
//创建图章
FileInputStream imageInput = new FileInputStream("C:\\Users\\hy\\Desktop\\水印.jpg");
// Create stamp
Stamp stamp = new Stamp();
stamp.setImageSize(500,100);
stamp.bindImage(imageInput);
stamp.setOrigin(10, 200);
stamp.setRotation(45.0F);
stamp.setBackground(false);
imageInput.close();
// Add stamp to PDF file
fileStamp.addStamp(stamp);
// Save updated PDF file
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
fileStamp.save(byteArrayOutputStream);
InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
byteArrayOutputStream.close();
pdfInput.close();
stamp.close();
// Close fileStamp
fileStamp.close();
inputStream.close();
}
}