Back to Devexpress

How to: Import the AcroForm Data

wpf-114496-controls-and-libraries-pdf-viewer-examples-interactive-form-how-to-import-the-acroform-data.md

latest3.5 KB
Original Source

How to: Import the AcroForm Data

  • May 24, 2019
  • 2 minutes to read

This example demonstrates how to import AcroForm data (interactive form data) from XML or FDF format to a PDF document.

View Example: WPF PDF Viewer - Import/Export the AcroForm Data

xaml
<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>
csharp
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;
        }
    }
}
vb
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