form flatten

Is form flattening available create with ui interaction? if available please say how to achieve that



1 Reply

DM Dhivyabharathi Mohan Syncfusion Team March 16, 2022 10:09 AM UTC

Hi Vignesh, 
  
Syncfusion PDF VIEWER does not have direct support to flatten the form fields in UI. However, you can flatten the form fields using the Syncfusion PDF Base library. We have shared the sample and code snippets for flattening the form fields while downloading the document from the PDF Viewer.  
  
 
  
Run the web service and then run the React sample 
  
 
 
 
Code snippets for flattening the PDF document: 
public IActionResult Download([FromBody] Dictionary<string, string> jsonObject) 
        { 
            MemoryStream stream = new MemoryStream(); 
            PdfRenderer pdfviewer = new PdfRenderer(_cache); 
            string documentBase = pdfviewer.GetDocumentAsBase64(jsonObject); 
            string base64String = documentBase.Split(new string[] { "data:application/pdf;base64," }, StringSplitOptions.None)[1]; 
            if (base64String != null || base64String != string.Empty) 
            { 
                byte[] byteArray = Convert.FromBase64String(base64String); 
                //Create the form if the form does not exist in the loaded document 
                PdfLoadedDocument loadedDocument = new PdfLoadedDocument(byteArray); 
                //Get the loaded form. 
 
                PdfLoadedForm loadedForm = loadedDocument.Form; 
 
                PdfLoadedFormFieldCollection fields = loadedForm.Fields; 
 
               //Flatten the whole form. 
 
                loadedForm.Flatten = true; 
 
                //Save the document into stream 
                loadedDocument.Save(stream); 
                stream.Position = 0; 
 
                loadedDocument.Close(); 
 
                documentBase = string.Concat("data:application/pdf;base64,", Convert.ToBase64String(stream.ToArray())); 
 
        } 
            return Content(documentBase); 
    } 
 
  
Please try this and revert to us, if you need further assistance. 
  
 
Regards, 
Dhivya. 


Loader.
Up arrow icon