VintaSoft Imaging .NET SDK 12.4: Documentation for .NET developer
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 C#/VB.NET code that demonstrates how to export/import the data of PDF interactive form:
    /// <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();
        }
    }
    
    ''' <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