We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How do I flatten a PDF Form

I am being dense I guess, but I just do not see how to flatten a PDF form. Can you tell me?

5 Replies

DG Divya G Syncfusion Team November 19, 2009 07:41 AM UTC


Hi Ronald,

Thank you for using Syncfusion products.
Regarding Issue : How do flatten a PDF Form

Here is a sample code for your reference.

(C#)
PdfLoadedDocument doc = new PdfLoadedDocument(@"..\..\data\401k.pdf");
PdfLoadedForm form = doc.Form;
form.Flatten = true;
doc.Save("Sample.pdf");


Please take a look into it and let me know if you have any queries.

Regards,
DivyaGovindaraju.


RA Ron Alan Sawyer November 19, 2009 11:01 AM UTC

Thank you for your response. That is exactly how I would have expected it to work. However, when I place the line of code form.Flatten = true; into my code, I receive an error on the line doc.Save("Sample.pdf");

The error says that "value cannot be null" parameter name: text.

If I comment out form.Flatten = true, the code works and the PDF is saved.

I will try to create a small application that shows this later this morning and update you with it at that time.


DG Divya G Syncfusion Team November 25, 2009 12:22 PM UTC

Hi Ronald,
Did you flatten the PDF form? Let me know the status and if you have any queries.
Regards,
Divya.G


JL Jéan Labuschagne November 29, 2017 06:03 AM UTC

Hi 

I have tried the method you provided, it saves the new file successfully but when I try and open it i get an error. I have attached a screenshot of this error. 

Thank you for your assistance,
kind regards Jéan

Attachment: ErrorImage_67f9741f.rar


SP Sathya Ponnusamy Syncfusion Team November 29, 2017 10:20 AM UTC

Hi Jéan Labuschagne, 

We suspect that the input document you are using is enabled with extended functionalities, we cannot edit the PDF document with extended feature enabled, so the error message throws when flatten the PDF document. 
As a work around we can remove this extended functionalities by using below code snippet, 

Code snippet: 
// Create Pdf Document. 
PdfDocument doc = new PdfDocument(); 
 
//Load the existing Document. 
PdfLoadedDocument ldoc = new PdfLoadedDocument(@"../../Data/input.pdf"); 
 
// Import the loaded Document. 
doc.ImportPageRange(ldoc, 0, ldoc.Pages.Count - 1); 
PdfForm form = doc.Form; 
 
form.Flatten = true; 
 
doc.Save("output.pdf"); 
doc.Close(true); 
Process.Start("output.pdf"); 

Please try this in your side, if the issue is not resolved, please send us the input document which is helpful to proceed further in this. 

Regards, 
Sathya 


Loader.
Live Chat Icon For mobile
Up arrow icon