如何使用iText使用XFA表单对PDF文件进行数字签名 [英] How to digitally sign PDF files with XFA forms using iText
问题描述
iText发行说明提到,iText版本5.4.2和5.4.3支持使用XFA表单签署PDF:
iText release notes mention that signing of PDFs with XFA forms is supported from iText versions 5.4.2 and 5.4.3:
http://itextpdf.com/history/?branch=54&node=542
http://itextpdf.com/history/? branch = 54& node = 543
在某处有文档如何使用Java进行签名?
Is there a documentation somewhere how to do the signing in Java?
我特别感兴趣的是用XFA签名PDF,其中有一个准备好的签名字段。
I am specifically interested in signing PDFs with XFA where there is a prepared field for signature.
推荐答案
这是一个显示如何使用XmlDSig签名的小例子:
This is a small example showing how to sign using XmlDSig:
PdfReader reader =new PdfReader(src);
FileOutputStream os =new FileOutputStream(dest);
PdfStamper stamper = PdfStamper.createXmlSignature(reader, os);
XmlSignatureAppearance appearance = stamper.getXmlSignatureAppearance();
appearance.setXmlLocator(new XfaXmlLocator(stamper));
appearance.setXpathConstructor(new XfaXpathConstructor(XfaXpathConstructor.XdpPackage.Datasets));
ExternalSignature signature =new PrivateKeySignature(pk, digestAlgorithm,"BC");
//use signXmlDSig or signXades
MakeXmlSignature.signXmlDSig(appearance, signature, chain);
您也可以使用XAdES进行签名,但之后您将无法在Adobe中验证签名软件,因为我不认为Adobe已经支持XAdES(如果我错了,请纠正我)。
You can also sign using XAdES, but then you won't be able to validate the signature in Adobe software because I don't think Adobe already supports XAdES (please correct me if I'm wrong).
这篇关于如何使用iText使用XFA表单对PDF文件进行数字签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!