问题
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:
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).
来源:https://stackoverflow.com/questions/19030113/how-to-digitally-sign-pdf-files-with-xfa-forms-using-itext