Is it possible to flatten specific fields on form and not all fields

Dear support,

I'm wondering if its possible to flatten specific fields on PDF and not the whole form. If yes, would you please share a sample code to achieve that

Best regards,

Fady


1 Reply

MK Moorthy Karunanithi Syncfusion Team February 16, 2023 07:16 AM UTC

Thank you for contacting Syncfusion Support.

Yes, we do have support for flattening specific fields from PDF documents. To achieve this, please refer to the example code below.


            //Load the PDF document.

            PdfLoadedDocument loadedDocument = new PdfLoadedDocument("input.pdf");

            //Get the loaded form.

            PdfLoadedForm loadedForm = loadedDocument.Form;

 

            //Get the field using the index

            PdfLoadedField loadedField = loadedForm.Fields[2] as PdfLoadedField;           

            if(loadedField!=null)

            {

                loadedField.Flatten = true;

            }

 

            //Get the field using a field name

            loadedForm.Fields.TryGetField("employeesRadioList", out loadedField);

            if (loadedField != null)

            {

                loadedField.Flatten = true;

            }

 

            MemoryStream memoryStream = new MemoryStream();

            //Save the document.

            loadedDocument.Save(memoryStream);

            //close the document.

            loadedDocument.Close(true);


Please let us know if you need any further assistance


Loader.
Up arrow icon