Sign XFA form

Mihai Lica Pura <[email protected]> Tue, 21 Oct 2014 21:38:18 +0300
Newsgroups gmane.comp.java.lib.itext.general
Message-ID <CAO_QK2-oKm=H1T=L59mp_N0QOAS6DKyQknKYb5ySKLxC=GHUbg@mail.gmail.com>
Hello,

I have a PDF with two AcroFields that are signature fields and and XFA
form. Some of the fields of the XFA form are filled and the first signature
field is signed using Adobe Reader. The filled XFA fields are signed by
that signature. Please see attached PDF sample (confirmare.pdf).

I fill the rest of the XFA fields (please see filled.pdf sample) using
itext, and than I need to sign the XFA form, but place the signature in the
second signature field (AcroField) already present in the PDF. If I use the
code from the documentation, the signature is OK but in the signed version
the fields of XFA form that I filled before signing are empty. So they were
not actually signed. Please see third PDF sample.

reader = new PdfReader(CalePtSalvareaCererii);
fs = new FileStream(CalePtSalvareaCererii.Replace(".pdf", "_sig.pdf"),
FileMode.Create);
stamper = PdfStamper.CreateSignature(reader, fs, '\0', null, true);

X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2Collection sel =
X509Certificate2UI.SelectFromCollection(store.Certificates, null, null,
X509SelectionFlag.SingleSelection);

X509Certificate2 cert = sel[0];

Org.BouncyCastle.X509.X509CertificateParser cp = new
Org.BouncyCastle.X509.X509CertificateParser();
Org.BouncyCastle.X509.X509Certificate[] chain = new
Org.BouncyCastle.X509.X509Certificate[] {

cp.ReadCertificate(cert.RawData)};

iTextSharp.text.pdf.security.IExternalSignature externalSignature = new
iTextSharp.text.pdf.security.X509Certificate2Signature(cert, "SHA-1");

PdfSignatureAppearance appearance = stamper.SignatureAppearance;
appearance.SetVisibleSignature("form1[0].body[0].Confirmare[0].SignatureField1[0]");
appearance.CertificationLevel =
PdfSignatureAppearance.CERTIFIED_FORM_FILLING_AND_ANNOTATIONS;
iTextSharp.text.pdf.security.MakeSignature.SignDetached(appearance,
externalSignature, chain, null, null, null, 0,
iTextSharp.text.pdf.security.CryptoStandard.CMS);

stamper.Close();
reader.Close();
fs.Close();

Can someone help me to solve the issue?

Thank you in advance!

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho

_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions

iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples: http://itextpdf.com/themes/keywords.php
confirmare03032014.pdf (application/pdf, 160.5 KB) - not displayed
filled.pdf (application/pdf, 190.1 KB) - not displayed
signed.pdf (application/pdf, 211.8 KB) - not displayed