Form Filling in PDF Files in WPF Pdf Viewer

9 Aug 20213 minutes to read

PDF Viewer provides the ability to Fill, Edit, Flatten, and Save the AcroForm fields in PDF files.

WPF PDF Viewer Form Filling

Supported form fields

You can load and fill the following form fields in a PDF document using the PDF Viewer.

  1. Text box.
  2. Password box.
  3. Checkbox.
  4. Radio button.
  5. Combo box.
  6. List box.

Retrieve the details of text box form field

You can retrieve the details of a text box form field through the FormFieldClicked event of PdfViewerControl by simply clicking on the field. The FormField property of the FormFieldClickedEventArgs needs to be typecast to the TextBox control as shown in the following code.

//Wire the `FormFieldClicked` event.
pdfViewer.FormFieldClicked += PdfViewer_FormFieldClicked;

private void PdfViewer_FormFieldClicked(object sender, FormFieldClickedEventArgs args)
{
	//Typecast the `FormField` property to `System.Windows.Controls.TextBox`
	TextBox textBox = args.FormField as TextBox;

	//Retrive the `Text` property
	string text = textBox.Text;

	//{Insert your code here}
}

NOTE

The sample project of PDF form filling using the Syncfusion PDF Viewer is available in the GitHub.

Import and Export Form Data

In WPF, the PDF viewer allows the users to import and export form data to and from the PDF documents.

Import Form Data

Follow the below steps to import date to PDF document with AcroForm.

  1. Click the form data tool button in the left pane, the form data toolbar will appear as a secondary toolbar in the PdfViewerControl.
  2. Select Import option in form data toolbar to import the PDF form data.

WPF PDF Viewer Import Form Data

The following code shows how to import form data in code behind.

private void button1_Click(object sender, RoutedEventArgs e)
{
    //Import PDF form data
    pdfviewer.ImportFormData("Import.fdf", Syncfusion.Pdf.Parsing.DataFormat.Fdf);
}
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
    'Import PDF form data
    pdfviewer.ImportFormData("Import.fdf", Syncfusion.Pdf.Parsing.DataFormat.Fdf)
End Sub

Export Form Data

Follow the below steps to export data from PDF document

  1. Select Export option in the form data toolbar, to save the completed PDF form data as a file in another file format.
  2. In Export Form Data As dialog box, you can select the desired format to save the form data (FDF, XFDF, XML, and JSON).

NOTE

If the PDF document is loaded as a stream, the PdfViewerControl will request for the form name when exporting.

The following code shows how to export form data in code behind.

private void button1_Click(object sender, RoutedEventArgs e)
{
    //Export PDF form data
    pdfviewer.ExportFormData("Export.fdf", Syncfusion.Pdf.Parsing.DataFormat.Fdf, "SourceForm.pdf");
}
Private Sub button1_Click(sender As Object, e As RoutedEventArgs)
    'Export PDF form data
    pdfviewer.ExportFormData("Export.fdf", Syncfusion.Pdf.Parsing.DataFormat.Fdf, "SourceForm.pdf")
End Sub

NOTE

You can refer to our WPF PDF Viewer feature tour page for its groundbreaking feature representations. You can also explore our WPF PDF Viewer example to know how to render and configure the pdfviewer.