PDF: Изменение значения поля в интерактивной PDF форме
В этом разделе
Чтобы изменить значение поля PDF формы, необходимо сделать следующее:
Чтобы изменить значение поля формы по умолчанию, необходимо сделать следующее:
Вот C#/VB.NET код, который демонстрирует, как изменить значение текстового поля в PDF форме:
/// <summary>
/// Changes the text field value.
/// </summary>
/// <param name="document">The PDF document.</param>
/// <param name="fieldFullName">Full name of the field.</param>
/// <param name="newValue">The new value of the field.</param>
/// <returns>
/// <b>true</b> - field value is changed successfully;
/// <b>false</b> - field value is NOT changed.
/// </returns>
public static bool ChangeTextFieldValue(
Vintasoft.Imaging.Pdf.PdfDocument document,
string fieldFullName,
string newValue)
{
// if PDF document has PDF interactive form
if (document.InteractiveForm != null)
{
// find field by name
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField field =
document.InteractiveForm.FindField(fieldFullName);
// if field is found
if (field != null)
{
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField textField =
field as Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField;
// if field is text field
if (textField != null)
{
// set new value of the field
textField.Value =
new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextFieldStringValue(document, newValue);
return true;
}
}
}
return false;
}
''' <summary>
''' Changes the text field value.
''' </summary>
''' <param name="document">The PDF document.</param>
''' <param name="fieldFullName">Full name of the field.</param>
''' <param name="newValue">The new value of the field.</param>
''' <returns>
''' <b>true</b> - field value is changed successfully;
''' <b>false</b> - field value is NOT changed.
''' </returns>
Public Shared Function ChangeTextFieldValue(document As Vintasoft.Imaging.Pdf.PdfDocument, fieldFullName As String, newValue As String) As Boolean
' if PDF document has PDF interactive form
If document.InteractiveForm IsNot Nothing Then
' find field by name
Dim field As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormField = document.InteractiveForm.FindField(fieldFullName)
' if field is found
If field IsNot Nothing Then
Dim textField As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField = TryCast(field, Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextField)
' if field is text field
If textField IsNot Nothing Then
' set new value of the field
textField.Value = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormTextFieldStringValue(document, newValue)
Return True
End If
End If
End If
Return False
End Function