jeudi 29 mars 2018

iTextSharp Checkbox disappers in pdf when saving

I'm using itext sharp to fill my form fields on my template with values. Some of this fields should be flatten so that the user can't edit it. The rest of the fields should be filled by the user and my program can read out the data and insert it in the database.

My Solution works fine with Abobe Reader DC, but i have problems with Adobe Reader X An update of the version on the clients isn't possible.

So i enabled usage rights in the pdf template. Problem is that with itextsharp i have to enable append on the PdfStamper If this is enabled it's not possible to flatten a part of the form because of the Adobe signature on the document.

Now i have following idea: I split my template in two documents. The first document is filled by my code and Formflattening is true.

Following Code:

            MemoryStream outstream = new MemoryStream();

            Document document = new Document();
            PdfSmartCopy writer = new PdfSmartCopy(document, outstream);
            document.Open();

            //newFileStream is the flattend Form
            pdfReader = new PdfReader(newFileStream.ToArray());
            writer.AddDocument(pdfReader);

            PdfReader reader = new PdfReader(Properties.Resources.PdfForm);
            writer.AddDocument(reader);

            reader.Close();
            writer.Close();
            document.Close();

            return outstream.ToArray();

Now i merge the document with my second template and save it. Now i have the document that i want. First page ist 'readonly' and the second page has formfields.

My problem is now that the user can fill the document (checkboxes and textboxes) but if the user save the document the filled checkboxes disappears. So if the user send me back the document thera a no checkboxes in it.

I don't understand why only checkboxes disappear.




Aucun commentaire:

Enregistrer un commentaire