/** * 图片水印 * @param pdfBty * @param imagePath * @return * @throws Exception */ public byte[] imageWatermark(byte[] pdfBty, String imagePath) throws Exception { PdfReader reader=null; PdfStamper stamp=null; try{ reader = new PdfReader(pdfBty); ByteArrayOutputStream out = new ByteArrayOutputStream(); stamp = new PdfStamper(reader, out); PdfGState gs1 = new PdfGState(); gs1.setFillOpacity(1f); Image image = Image.getInstance(IOUtils.toByteArray(new FileInputStream(imagePath))); int n = reader.getNumberOfPages(); for (int i = 1; i <= n; i++) { PdfContentByte pdfContentByte = stamp.getUnderContent(i); pdfContentByte.setGState(gs1); /* 设置图片的位置 */ image.setAbsolutePosition(0, 0); /* 设置图片的大小 (A4)*/ image.scaleAbsolute(595
itext添加水印
最新推荐文章于 2024-05-15 15:20:17 发布