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

Fill PDF and Flatten option


Hello,

We're working with a PDF file : We need to fill and print it.

it's a official document (from French gvt) and we need to fill it.

We succeed to fill it but not to "Flatten" it (if flattened, all fields are blank in the result document).
We're using a workaround : Set the final document as Readonly but we have then another problem to print it : All fields are blank on the printed document.

==> My question is : How can i completely "Flatten" this PDF document to be able to correctly print it.

I joined a test project :
It's a console program which will be start (with parameters) by another application.
You will find 2 commands : FILL and PRINT
- FILL which will fill the empty document and save it to the result document
- PRINT will print any of the 2 documents to a printer

In the Main() function your will find 2 block of code to test the FILL command and the PRINT command.

Please let the project in debug mode to test it.

Thanks in advance for your help,

Best regards,

Benjamin

Attachment: PDFUtils_78f8705a.zip

5 Replies

SK Surya Kumar Syncfusion Team May 25, 2017 02:29 PM UTC

Hi Benjamin, 
 
Thank you for using Syncfusion products. 
 
We have analyzed the document which you have given, it is found that the document was XFA document which contains XFA form fields, since we do not have support to flatten the XFA form fields, we have created a work around to flatten the fields. 
 
The XFA forms can be flattened when, the XFA document is imported and saved as normal document then the saved document can be used to filling forms and flattening it directly, please find the code snippet for the same below: 
  
            //Load the XFA document 
            PdfLoadedDocument lDoc = new PdfLoadedDocument(source); 
 
            //Create new document to save the imported document 
            PdfDocument document = new PdfDocument(); 
            //Imports the pages from the lDoc 
 
            document.ImportPageRange(lDoc, 0, lDoc.Pages.Count - 1); 
 
            //Saves the document 
 
            document.Save("sample.pdf"); 
 
We have altered the sample which you have posted in last update with the workaround mentioned above, please find the sample from the below link: 
 
Please let us know if you need any further information. 
 
Regards, 
Surya Kumar 



BE Benjamin May 26, 2017 03:50 PM UTC

Hello, With your workaround, we can fill the PDF document and display it.But we still have the print problem : When we try to silently print the filled document, all fields are empty (but inserted images are present).Edit : Another question, how can i know that a PDF document is a XFA document ?I joined a PDF exemple to this message.Thanks in advance for your help, Best regards, Benjamin Attachment: cerfa2_1e165816.zip


BE Benjamin replied to Thierry BRUSTIS May 26, 2017 03:51 PM UTC

Hello, With your workaround, we can fill the PDF document and display it.But we still have the print problem : When we try to silently print the filled document, all fields are empty (but inserted images are present).Edit : Another question, how can i know that a PDF document is a XFA document ?I joined a PDF exemple to this message.Thanks in advance for your help, Best regards, Benjamin Attachment: cerfa2_1e165816.zip

The "Edit" function massacred my message.

I join here the PDF document.

Attachment: cerfa2_9894b506.zip


SK Surya Kumar Syncfusion Team May 29, 2017 12:59 PM UTC

Hi Benjamin, 
 
We can use the below code snippet to find whether the loaded document is normal or XFA document. 
 
private bool IsXFADocument (string filePath) 
{ 
            bool isXfa = false; 
 
        PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(filePath); 
            //Get the loaded XFA form. 
 
            PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; 
 
            int count = loadedForm.Fields.Count; 
        //If the loaded field count is greater than zero then its a XFA document. 
            if (count > 0) 
                isXfa = true; 
            return isXfa; 
        loadedDocument.Close(); 
 
} 
 
We have created the support incident for the issue with “The flatten form fields value become empty when Silent printed the particular PDF document” it can be tracked through below link: 
  
  
Let us know if you need any further information in this. 
Regards, 
Surya Kumar. 



SK Surya Kumar Syncfusion Team May 29, 2017 01:10 PM UTC

Hi Benjamin, 
 
We can use the below code snippet to find whether the loaded document is normal or XFA document. 
 
private bool IsXFADocument (string filePath) 
{ 
            bool isXfa = false; 
 
           PdfLoadedXfaDocument loadedDocument = new PdfLoadedXfaDocument(filePath); 
         //Get the loaded XFA form. 
 
            PdfLoadedXfaForm loadedForm = loadedDocument.XfaForm; 
 
            loadedDocument.Close(); 
 
            int count = loadedForm.Fields.Count; 
        //If the loaded field count is greater than zero then its a XFA document. 
            if (count > 0) 
                isXfa = true; 
            return isXfa; 
 
} 
 
 
We have created the support incident for the issue with “The flatten form fields value become empty when Silent printed the particular PDF document” it can be tracked through below link: 
 
Let us know if you need any further information in this. 
 
Regards, 
Surya Kumar. 


Loader.
Up arrow icon