Articles in this section
Category / Section

How to preserve the form fields when silent printing the PDF document?

1 min read

PdfViewerControl does not preserve form field data when silent printing the PDF document. However, these details can be preserved by flattening the form fields before silent printing the PDF document.

Refer to the following code snippet.

//Load the template document           
PdfLoadedDocument doc = new PdfLoadedDocument(@"..\..\Data\FormFillingDocument.pdf");
PdfLoadedForm form = doc.Form;
//Fill the fields from the first page  
(form.Fields["Name"] as PdfLoadedTextBoxField).Text = "xxx";
(form.Fields["Email"] as PdfLoadedTextBoxField).Text = "yyy";
//Flatten the form fields
doc.Form.Flatten = true;
MemoryStream stream = new MemoryStream();
//Save the changes
doc.Save(stream);
PdfViewerControl viewer = new PdfViewerControl();
viewer.Load(stream);
//Initialize print dialog.
PrintDialog dialog = new PrintDialog();
//Get the list of installed printers in a list.
List<string> printersList = new List<string>();
foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
     printersList.Add(printer);
}
dialog.AllowPrintToFile = true;
dialog.AllowSomePages = true;
dialog.AllowCurrentPage = true;
dialog.Document = viewer.PrintDocument;
//Assign any of the printers you wish to print to the printer settings  
dialog.Document.PrinterSettings.PrinterName = printersList[1];
dialog.Document.Print();

 

Sample link:
http://www.syncfusion.com/downloads/support/directtrac/general/ze/SampleWF-619293102https://www.syncfusion.com/downloads/support/directtrac/general/ze/SampleWF-619293102

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied