解决方法
我想你正在寻找用PDF标记页面的水.请查看下面的代码.您也可以使用Watermarker类.
PdfReader reader = new PdfReader("text.pdf"); int n = reader.getNumberOfPages(); // Create a stamper that will copy the document to a new file PdfStamper stamp = new PdfStamper(reader,new FileOutputStream("text1.pdf")); int i = 1; PdfContentByte under; PdfContentByte over; Image img = Image.getInstance("watermark.jpg"); BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,BaseFont.WINANSI,BaseFont.EMBEDDED); img.setAbsolutePosition(200,400); while (i < n) { // Watermark under the existing page under = stamp.getUnderContent(i); under.addImage(img); // Text over the existing page over = stamp.getOverContent(i); over.beginText(); over.setFontAndSize(bf,18); over.showText("page " + i); over.endText(); i++; } stamp.close();
问候,阿卜杜勒·奥拉卡拉