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
PdfViewerControl viewer = new PdfViewerControl();
//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)
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];


Sample link:

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