Fill in Form and then sign
- From: "Paulo Soares" <psoares (at) consiste.pt>
- Date: Wed, 14 Jun 2006 14:43:11 +0100
Call SetEncryption() right after creating the PdfStamper.
Paulo
> -----Original Message-----
> From: itext-questions-bounces@lists.sourceforge.net
> [mailto:itext-questions-bounces@lists.sourceforge.net] On
> Behalf Of Eliasen Jan
> Sent: Wednesday, June 14, 2006 1:01 PM
> To: Post all your questions about iText here
> Subject: [iText-questions] Fill in Form and then sign
>
> Hi
>
> I am trying to open up a PDF document, fill in some values
> into some form fields and then sign the document at the end.
>
> Unfortunately, I can not get it to work.
>
> My code looks like this:
>
> string alias = null;
>
> string keyPath =
> @"D:\Work\Projekter\DubliNet\Sikkerhed\Certifikatet\PrivateKey
> WithCert.p12";
>
> PKCS12Store pk12 = new PKCS12Store(new FileStream(keyPath,
> FileMode.Open, FileAccess.Read), "TooHot4u".ToCharArray());
>
> IEnumerator i = pk12.aliases();
>
> while (i.MoveNext())
>
> {
>
> alias = ((string)i.Current);
>
> if (pk12.isKeyEntry(alias))
>
> break;
>
> }
>
> AsymmetricKeyParameter akp = pk12.getKey(alias).getKey();
>
> X509CertificateEntry[] ce = pk12.getCertificateChain(alias);
>
> X509Certificate[] chain = new X509Certificate[ce.Length];
>
> for (int k = 0; k < ce.Length; ++k)
>
> chain[k] = ce[k].getCertificate();
>
> PdfReader reader = new PdfReader(new
> FileStream(@"D:\Work\Projekter\DubliNet\Blanketter\20050104
> TakeBack filled out.pdf", FileMode.Open, FileAccess.Read));
>
> string filename =
> @"D:\Work\Projekter\DubliNet\Blanketter\20050104 TakeBack
> filled out SIGNED.pdf";
>
> System.IO.MemoryStream memStamp = new MemoryStream();
>
> PdfStamper st = PdfStamper.CreateSignature(reader, new
> FileStream(filename, FileMode.Create, FileAccess.Write), '\0');
>
> AcroFields form = st.AcroFields;
>
> form.SetField("b_dd","15");
>
> int perm = PdfWriter.AllowPrinting;
>
> st.SetEncryption(true, null, "lhkjshdfkjhsadfasdkljncaef", perm);
>
> PdfSignatureAppearance sap = st.SignatureAppearance;
>
> sap.SetCrypto(akp, chain, null, PdfSignatureAppearance.WINCER_SIGNED);
>
> sap.Reason = "I am approving this document";
>
> sap.Location = "Danish immigration Service";
>
> sap.SetVisibleSignature("signature");
>
> st.Close();
>
>
> The exception occurs at the line where I create the
> PdfSignatureAppearance - and the exception is this:
> -- BEGIN
> An unhandled exception of type
> 'iTextSharp.text.DocumentException' occurred in itextsharp.dll
>
> Additional information: Content was already written to the output
> -- END
>
> Thanks in advance!
>
> Med venlig hilsen
> ________________________________________
> Jan Eliasen
>
> WM-data
> Fredrik Bajers Vej 1
> 9220 Aalborg Ãst
> Tel.: +45 9630 5800, direkte: +45 9630 5818
> Mobil: +45 2518 8024, fax: +45 9630 5805
> mailto: jaela@wmdata.com
> http://www.wmdata.dk
>
>
>
Aviso Legal:
Esta mensagem à destinada exclusivamente ao destinatÃrio. Pode conter informaÃÃo confidencial ou legalmente protegida. A incorrecta transmissÃo desta mensagem nÃo significa a perca de confidencialidade. Se esta mensagem for recebida por engano, por favor envie-a de volta para o remetente e apague-a do seu sistema de imediato. à proibido a qualquer pessoa que nÃo o destinatÃrio de usar, revelar ou distribuir qualquer parte desta mensagem.
Disclaimer:
This message is destined exclusively to the intended receiver. It may contain confidential or legally protected information. The incorrect transmission of this message does not mean the loss of its confidentiality. If this message is received by mistake, please send it back to the sender and delete it from your system immediately. It is forbidden to any person who is not the intended receiver to use, distribute or copy any part of this message.
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions