Wayne
Wayne

Reputation: 109

How to flatten some PDF form fields but not all of them

I am using C# and iTextSharp for PDFs. I have a PDF template that has form fields for information and also form fields for electronic signatures. I need to be able to have staff fill our part of the form, then in code, flatten that part (leaving the signature fields alone) and then I will be passing off the PDF to DocuSign's API to have the user sign the document electronically.

I have requirements that only the fields that should be editable by the user (signature) are form fields when they reach the DocuSign API. I have to flatten all the other fields before passing it to the DocuSign API (DocuSign automatically can Tag form fields for Signature).

Does anyone know how to do this? I have thought about getting the position of the signature fields, and after flattening the whole PDF adding the form fields back in with iTextSharp, but I feel that is a hack.

Upvotes: 2

Views: 5824

Answers (4)

Daniil Grankin
Daniil Grankin

Reputation: 3933

For XFA form you get

Partial form flattening is not supported with XFA forms.

exception if you use PartialFormFlattening.

To flat some fields I used

stamper.AcroFields.SetFieldProperty(fieldName, "setfflags", PdfFormField.FF_READ_ONLY, null);

make sure you use full fieldName (for instance for W-9 Name field use "topmostSubform[0].Page1[0].f1_1[0]" not "f1_1") otherwise it won't work.

I also tried remove XFA with

PdfDictionary acro =
   (PdfDictionary)PdfReader.GetPdfObject(
           pdfReader.Catalog.Get(PdfName.ACROFORM));
                acro.Remove(PdfName.XFA);

as it described here but I got the same exception.

Upvotes: 0

Ergin
Ergin

Reputation: 9356

Please see the following page from DocuSign's REST API guide as it has some good info on what you can do with the Adobe form fields and some special cases:

http://www.docusign.com/p/RESTAPIGuide/Content/REST%20API%20References/Document%20Parameters.htm

Upvotes: 0

ovaltein
ovaltein

Reputation: 1215

If you would like to flatten a specific field rather than the whole document then I believe you can use the following:

Stamper.FormFlattening = true;
Stamper.PartialFormFlattening("FieldName");

The only downside to this method is that you need to list every field that needs to be flattened. I think they are required to contain a value as well (i.e. you can't flatten a blank field).

Upvotes: 4

COLD TOLD
COLD TOLD

Reputation: 13569

Yes you can specify the names of the filed you want to update just take a look at the following example.

https://web.archive.org/web/20211020001747/https://www.4guysfromrolla.com/articles/030211-1.aspx

Upvotes: 0

Related Questions