PDF: Получение информации о полях интерактивной PDF формы
В этом разделе
Список всех полей интерактивной PDF формы можно получить с помощью свойства
PdfDocumentInteractiveForm.Fields.
Поле формы интерактивной PDF формы можно найти по полному имени поля с помощью метода
PdfDocumentInteractiveForm.FindField.
Все конечные поля PDF интерактивной формы можно получить с помощью метода
PdfDocumentInteractiveForm.GetTerminalFields. Все поля с цифровой подписью можно получить с помощью метода
PdfDocumentInteractiveForm.GetSignatureFields.
Вот C#/VB.NET код, который демонстрирует, как вывести информацию обо всех полях интерактивной PDF формы:
/// <summary>
/// Prints information about interactive form of PDF document.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
public static void PrintInformationAboutPdfInteractiveForm(string pdfFilename)
{
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document =
new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
{
// if PDF document has interactive form
if (document.InteractiveForm != null)
{
// get reference to the interactive form
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm form = document.InteractiveForm;
// get an array that contains all interactive form fields of PDF document
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField[] formFields = form.GetTerminalFields();
// print information abount field count
System.Console.WriteLine("Interactive Form Field Count: {0}", formFields.Length);
// for each interactive field
foreach (Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField field in formFields)
{
// output information about interactive field
System.Console.WriteLine("\tName={0,-18} TypeName={1,-33} TextQuadding={2,-14} IsReadOnly={3,-5}",
field.FullyQualifiedName, field.GetType().Name, field.TextQuadding, field.IsReadOnly);
}
}
}
}
/* This code example produces the following output:
Interactive Form Field Count: 13
Name=TextField1 TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=False
Name=TextField2 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
Name=TextField3 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
Name=TextField4 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
Name=TextField5 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
Name=TextField6 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
Name=NumericField TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
Name=FileSelect TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
Name=browseButton TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified IsReadOnly=False
Name=Calculator.Left TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=False
Name=Calculator.Right TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=False
Name=Calculator.Result TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=True
Name=ResetButton TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified IsReadOnly=False
*/
''' <summary>
''' Prints information about interactive form of PDF document.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
Public Shared Sub PrintInformationAboutPdfInteractiveForm(pdfFilename As String)
' open PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
' if PDF document has interactive form
If document.InteractiveForm IsNot Nothing Then
' get reference to the interactive form
Dim form As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm = document.InteractiveForm
' get an array that contains all interactive form fields of PDF document
Dim formFields As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField() = form.GetTerminalFields()
' print information abount field count
System.Console.WriteLine("Interactive Form Field Count: {0}", formFields.Length)
' for each interactive field
For Each field As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField In formFields
' output information about interactive field
System.Console.WriteLine(vbTab & "Name={0,-18} TypeName={1,-33} TextQuadding={2,-14} IsReadOnly={3,-5}", field.FullyQualifiedName, field.[GetType]().Name, field.TextQuadding, field.IsReadOnly)
Next
End If
End Using
End Sub
' This code example produces the following output:
' Interactive Form Field Count: 13
' Name=TextField1 TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=False
' Name=TextField2 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
' Name=TextField3 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
' Name=TextField4 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
' Name=TextField5 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
' Name=TextField6 TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
' Name=NumericField TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
' Name=FileSelect TypeName=PdfInteractiveFormTextField TextQuadding=LeftJustified IsReadOnly=False
' Name=browseButton TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified IsReadOnly=False
' Name=Calculator.Left TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=False
' Name=Calculator.Right TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=False
' Name=Calculator.Result TypeName=PdfInteractiveFormTextField TextQuadding=Centered IsReadOnly=True
' Name=ResetButton TypeName=PdfInteractiveFormPushButtonField TextQuadding=LeftJustified IsReadOnly=False
'