问题
I'd like to sign PDF documents created in Adobe Livecycle (it is XFA form) programmatically.
I know about iText library for manipulating with PDFs, but I haven't found any example how to sign it yet.
Maybe its not supported yet. Do you know any other Java library which can do that? Or do you know a way how to sign it?
I know, my question is similar to this opened question, but I don't need the use of iText.
Thank you very much for your help!
回答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/21749485/digital-signing-of-xfa-forms