How to digitally sign PDF files with XFA forms using iText

独自空忆成欢 提交于 2019-12-23 04:08:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!