wpf-114496-controls-and-libraries-pdf-viewer-examples-interactive-form-how-to-import-the-acroform-data.md
This example demonstrates how to import AcroForm data (interactive form data) from XML or FDF format to a PDF document.
Load a document with interactive forms (e.g., from a file path) into the PDF Viewer using the DocumentViewerControl.OpenDocument method.
Call the PdfViewerControl.ImportFormData method in the PdfViewerControl.DocumentLoadedEvent event handler.
To save the imported document, (e.g., to a file), call the PdfViewerControl.SaveDocument method with a specified file name, including a file path where the imported document will be located.
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