700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > iText中给pdf内容添加水印

iText中给pdf内容添加水印

时间:2021-06-13 03:39:07

相关推荐

iText中给pdf内容添加水印

/** * 给pdf文件添加水印 * @param InPdfFile 要加水印的原pdf文件路径 * @param outPdfFile 加了水印后要输出的路径 * @param markImagePath 水印图片路径 * @param pageSize 原pdf文件的总页数 * @throws Exception */ public static void addPdfMark(String InPdfFile, String outPdfFile, String markImagePath, int pageSize) throws Exception { PdfReader reader = new PdfReader(InPdfFile, "PDF".getBytes()); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outPdfFile)); Image img = Image.getInstance(markImagePath);// 插入水印img.setAbsolutePosition(150, 100); for(int i = 1; i <= pageSize; i++) { PdfContentByte under = stamp.getUnderContent(i); under.addImage(img); } stamp.close();// 关闭 File tempfile = new File(InPdfFile); if(tempfile.exists()) { tempfile.delete(); } } [java] view plaincopyprint?/** * 给pdf文件添加水印 * @param InPdfFile 要加水印的原pdf文件路径 * @param outPdfFile 加了水印后要输出的路径 * @param markImagePath 水印图片路径 * @param pageSize 原pdf文件的总页数 * @throws Exception */ public static void addPdfMark(String InPdfFile, String outPdfFile, String markImagePath, int pageSize) throws Exception { PdfReader reader = new PdfReader(InPdfFile, "PDF".getBytes()); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outPdfFile)); Image img = Image.getInstance(markImagePath);// 插入水印img.setAbsolutePosition(150, 100); for(int i = 1; i <= pageSize; i++) { PdfContentByte under = stamp.getUnderContent(i); under.addImage(img); } stamp.close();// 关闭 File tempfile = new File(InPdfFile); if(tempfile.exists()) { tempfile.delete(); }

转自:/huiwenjie168/article/details/7616983

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。