Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » iText »

[iText-questions] Fill in Form and then sign

Eliasen Jan

2006-06-14


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\PrivateKeyWithCert.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

 
_______________________________________________
iText-questions mailing list
iText-questions@(protected)
https://lists.sourceforge.net/lists/listinfo/itext-questions
©2008 junlu.com - Jax Systems, LLC, U.S.A.