How to digitally sign PDF files with XFA forms usi

2019-05-30 12:57发布

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

Is there a documentation somewhere how to do the signing in Java?

I am specifically interested in signing PDFs with XFA where there is a prepared field for signature.

1条回答
混吃等死
2楼-- · 2019-05-30 13:34

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);

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).

查看更多
登录 后发表回答