怎么样使用itext对PDF生成叠加签名

J2EE 码拜 8年前 (2016-03-15) 2351次浏览
目前已实现生成一个签名,但若要叠加签名,该怎么样实现?求高手支招!
解决方案

95

最近正好在研究Itext源码,5.5.9的,可以一起讨论
源码中是这样的
public static PdfStamper createSignature(final PdfReader reader, final OutputStream os, final char pdfVersion) throws DocumentException, IOException {
return createSignature(reader, os, pdfVersion, null, false);
}
下面是demo和参数注释
/**
* Applies a digital signature to a document. The returned PdfStamper
* can be used normally as the signature is only applied when closing.
* <p>
* Note that the pdf is created in memory.
* <p>
* A possible use is:
* <p>
* <pre>
* KeyStore ks = KeyStore.getInstance(“pkcs12”);
* ks.load(new FileInputStream(“my_private_key.pfx”), “my_password”.toCharArray());
* String alias = (String)ks.aliases().nextElement();
* PrivateKey key = (PrivateKey)ks.getKey(alias, “my_password”.toCharArray());
* Certificate[] chain = ks.getCertificateChain(alias);
* PdfReader reader = new PdfReader(“original.pdf”);
* FileOutputStream fout = new FileOutputStream(“signed.pdf”);
* PdfStamper stp = PdfStamper.createSignature(reader, fout, “\0”);
* PdfSignatureAppearance sap = stp.getSignatureAppearance();
* sap.setCrypto(key, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
* sap.setReason(“I”m the author”);
* sap.setLocation(“Lisbon”);
* // comment next line to have an invisible signature
* sap.setVisibleSignature(new Rectangle(100, 100, 200, 200), 1, null);
* stp.close();
* </pre>
* @param reader the original document
* @param os the output stream
* @param pdfVersion the new pdf version or “\0” to keep the same version as the original
* document
* @throws DocumentException on error
* @throws IOException on error
* @return a <CODE>PdfStamper</CODE>
*/

5

其实就是在图形上再绘制文字就好。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明怎么样使用itext对PDF生成叠加签名
喜欢 (0)
[1034331897@qq.com]
分享 (0)