VintaSoft Imaging .NET SDK 11.0
In This Topic
    PDF: Import and export data of PDF interactive form
    In This Topic

    The PdfInteractiveFormDataXfdfCodec class allows to export/import the field values of PDF interactive form in XFDF format.

    Here is an example that demonstrates how to export/import the data of PDF interactive form:

    ' The project, which uses this code, must have references to the following assemblies:
    ' - Vintasoft.Imaging
    ' - Vintasoft.Imaging.Pdf
    
    ''' <summary>
    ''' Exports the form data to the specified stream.
    ''' </summary>
    ''' <param name="document">The PDF document.</param>
    ''' <param name="stream">The stream, where form data must be exported.</param>
    Public Shared Sub ExportFormData(document As Vintasoft.Imaging.Pdf.PdfDocument, stream As System.IO.Stream)
        If document.InteractiveForm IsNot Nothing Then
            Dim xfdfCodec As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec()
            xfdfCodec.ExportFieldsWithoutValue = False
            xfdfCodec.Export(document.InteractiveForm, stream)
        End If
    End Sub
    
    ''' <summary>
    ''' Imports the form data from the specified stream.
    ''' </summary>
    ''' <param name="document">The PDF document.</param>
    ''' <param name="stream">The stream from which the form data must be imported.</param>
    Public Shared Sub ImportFormData(document As Vintasoft.Imaging.Pdf.PdfDocument, stream As System.IO.Stream)
        If document.InteractiveForm IsNot Nothing Then
            Dim xfdfCodec As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec()
            xfdfCodec.Import(document.InteractiveForm, stream)
            document.InteractiveForm.UpdateAppearances()
        End If
    End Sub
    
    // The project, which uses this code, must have references to the following assemblies:
    // - Vintasoft.Imaging
    // - Vintasoft.Imaging.Pdf
    
    /// <summary>
    /// Exports the form data to the specified stream.
    /// </summary>
    /// <param name="document">The PDF document.</param>
    /// <param name="stream">The stream, where form data must be exported.</param>
    public static void ExportFormData(
        Vintasoft.Imaging.Pdf.PdfDocument document, 
        System.IO.Stream stream)
    {
        if (document.InteractiveForm != null)
        {
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec xfdfCodec = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec();
            xfdfCodec.ExportFieldsWithoutValue = false;
            xfdfCodec.Export(document.InteractiveForm, stream);
        }
    }
    
    /// <summary>
    /// Imports the form data from the specified stream.
    /// </summary>
    /// <param name="document">The PDF document.</param>
    /// <param name="stream">The stream from which the form data must be imported.</param>
    public static void ImportFormData(
        Vintasoft.Imaging.Pdf.PdfDocument document, 
        System.IO.Stream stream)
    {
        if (document.InteractiveForm != null)
        {
            Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec xfdfCodec = 
                new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormDataXfdfCodec();
            xfdfCodec.Import(document.InteractiveForm, stream);
            document.InteractiveForm.UpdateAppearances();
        }
    }