栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

iText Stamping-Java

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

iText Stamping-Java

我做到了’:)

这是用于使用iText将自定义文本添加到文档而不使数字签名无效的代码。

//Read the source PDFPdfReader reader = new PdfReader(inputstream);//Create PdfStamp objectstamp = new PdfStamper(reader, new FileOutputStream(file), '', true);//Create the proper annotationPdfAnnotation annot = PdfAnnotation.createFreeText(stamp.getWriter(),  new Rectangle(150, 150, 200, 200), "Annotation 1", pcb);annot.setFlags(PdfAnnotation.FLAGS_PRINT);//Insert the annotation         stamp.addAnnotation(annot, 1);//Close the stampstamp.close();  

编辑:

为了在不使数字签名无效的情况下将图像图章插入文档,我使用了以下代码:

//Read the pdf PdfReader reader = new PdfReader(inputstream);//Use PdfStamper in append modestamp = new PdfStamper(reader, new FileOutputStream(file), '', true); //Read the imageImage img = Image.getInstance(ImageIO.read(imgStream), null);float w = img.getScaledWidth();float h = img.getScaledHeight();Rectangle location = new Rectangle(70, 770 - h, 70 + w, 770);//Create stamp annotationPdfAnnotation stampAnnot = PdfAnnotation.createStamp(stamp.getWriter(), location, null, "ITEXT");img.setAbsolutePosition(0, 0);//Create new PdfContentByte from the stamp writer//If you use cd = stamp.getOverContent(1) - you'll invalidate the signaturesPdfContentByte cb = new PdfContentByte(stamp.getWriter());PdfAppearance app = cb.createAppearance(w, h);app.addImage(img);stampAnnot.setAppearance(PdfName.N, app);stampAnnot.setFlags(PdfAnnotation.FLAGS_PRINT);stamp.addAnnotation(stampAnnot, 1);reader.close();


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/470102.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号