PDF: Импорт и экспорт данных интерактивной PDF формы
В этом разделе
Класс
PdfInteractiveFormDataXfdfCodec позволяет экспортировать/импортировать значения полей интерактивной PDF формы в формат XFDF.
Вот C#/VB.NET код, который демонстрирует, как экспортировать/импортировать данные интерактивной 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();
}
}
''' <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