wpf-114492-controls-and-libraries-pdf-viewer-interactive-forms-export-and-import-of-interactive-form-data.md
This document describes how to import and export AcroForm data (interactive forms that contain PDF fields used to gather information from the user) in FDF and XML formats.
If your document contains an interactive form, the Form Data ribbon tab or bar group becomes available. Click Import to invoke the Open dialog.
Select a data file (e.g., in the FDF format) to import data and click Open.
The imported interactive form data will be shown in the PDF Viewer.
Call the PdfViewerControl.ImportFormData in the PdfViewerControl.DocumentLoaded event handler to import AcroForm data.
The method invokes the Open dialog window, where you can specify a file name and file format (XML or FDF) from which a PDF document with interactive form is loaded.
View Example: WPF PDF Viewer - Import/Export the AcroForm Data
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxpdf="http://schemas.devexpress.com/winfx/2008/xaml/pdf"
x:Class="ImportFormData.MainWindow"
Title="MainWindow" Height="450" Width="600">
<Grid>
<dxpdf:PdfViewerControl x:Name="Viewer"
DocumentLoaded="Viewer_DocumentLoaded"
DocumentClosing="Viewer_DocumentClosing"/>
</Grid>
</Window>
using DevExpress.Xpf.PdfViewer;
using System.Windows;
namespace ImportFormData {
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
//Load a PDF file with an interactive form
Viewer.OpenDocument("..\\..\\FormFillDemo.pdf");
}
private void Viewer_DocumentLoaded(object sender, RoutedEventArgs e)
{
//Import data for an interactive form and save the result
Viewer.ImportFormData();
Viewer.SaveDocument("..\\..\\ImportedDocument.pdf");
}
//Disable the Save File dialog
private void Viewer_DocumentClosing(DependencyObject d, DocumentClosingEventArgs e)
{
e.SaveDialogResult = MessageBoxResult.Cancel;
e.Handled = true;
}
}
}
Imports DevExpress.Xpf.PdfViewer
Imports System.Windows
Namespace ImportFormData
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
' Load a PDF file with an interactive form
Viewer.OpenDocument("..\..\FormFillDemo.pdf")
End Sub
Private Sub Viewer_DocumentLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Import data for an interactive form and save the result
Viewer.ImportFormData()
Viewer.SaveDocument("..\..\ImportedDocument.pdf")
End Sub
' Disable the Save File dialog
Private Sub Viewer_DocumentClosing(ByVal d As DependencyObject, ByVal e As DocumentClosingEventArgs)
e.SaveDialogResult = MessageBoxResult.Cancel
e.Handled = True
End Sub
End Class
End Namespace
If your document contains an interactive form, the Form Data ribbon tab or bar group becomes available. Click the Export button to export interactive form data from a PDF document to one of supported formats.
Specify a name and the format (FDF or XML) to export the form in the invoked dialog, and click Save.
Call the PdfViewerControl.ExportFormData method in the PdfViewerControl.DocumentLoaded event handler to export interactive form data.
This method invokes the Save As dialog window, where you can specify the desired file format (XML or FDF) and a file name to export interactive form data.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dxpdf="http://schemas.devexpress.com/winfx/2008/xaml/pdf"
x:Class="ExportFormData.MainWindow"
Title="MainWindow" Height="350" Width="525">
<Grid>
<dxpdf:PdfViewerControl x:Name="Viewer" DocumentLoaded="Viewer_DocumentLoaded" />
</Grid>
</Window>
using System.Windows;
namespace ExportFormData
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
//Load a PDF file with an interactive form
Viewer.OpenDocument("..\\..\\FormFillDemo.pdf");
}
private void Viewer_DocumentLoaded(object sender, RoutedEventArgs e)
{
//Load a PDF file with an interactive form
Viewer.ExportFormData();
}
}
}
Imports System.Windows
Namespace ExportFormData
Partial Public Class MainWindow
Inherits Window
Public Sub New()
InitializeComponent()
' Load a PDF file with an interactive form
Viewer.OpenDocument("..\..\FormFillDemo.pdf")
End Sub
Private Sub Viewer_DocumentLoaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Load a PDF file with an interactive form
Viewer.ExportFormData()
End Sub
End Class
End Namespace
You can use DevExpress.Pdf.PdfViewerExtensions methods to import or export interactive form data with specified format settings. Add DevExpress.Docs reference to your application to access extension methods.
Important
You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use this member in production code. Refer to the DevExpress Subscription page for pricing information.
The code samples below show how to use PdfViewerExtensions.Import and PdfViewerExtensions.Export methods to work with interactive form data.
// Load a PDF document with AcroForm data.
pdfViewer1.LoadDocument("..\\..\\InitialAcroForm.pdf");
// Import data from an XML format.
pdfViewer1.Import("..\\..\\FilledAcroForm.xml");
...
// Save the imported document.
pdfViewer1.SaveDocument("..\\..\\ImportedAcroForm.pdf");
// Export data to the XML format.
pdfViewer1.Export("..\\..\\AcroForm.xml", PdfFormDataFormat.Xml);
' Load a PDF document with AcroForm data
pdfViewer1.LoadDocument("..\..\AcroForm.pdf")
' Import the document from an XML format.
pdfViewer1.Import("..\..\FilledAcroForm.xml")
...
' Save the imported document.
pdfViewer1.SaveDocument("..\..\ImportedAcroForm.pdf")
' Export data to the XML format
pdfViewer1.Export("..\..\AcroForm.xml", PdfFormDataFormat.Xml)