Класс PdfSubmitFormAction
В этом разделе
Представляет действие отправки формы.
Объектная модель
Синтаксис
Ремарки
Действие отправки формы передает имена и значения выбранных полей интерактивной формы на указанный унифицированный указатель ресурсов (URL), предположительно адрес веб-сервера, который обработает их и отправит ответ.
Пример
Вот пример, показывающий, как отправить данные формы на определенный URL:
''' <summary>
''' Adds a submit button to a PDF document.
''' </summary>
''' <param name="pdfFilename">The filename of PDF document.</param>
''' <param name="url">URL to submit form.</param>
Public Shared Sub AddSubmitFormButton(pdfFilename As String, url As String)
' open PDF document
Using document As New Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename)
' create new PDF page
Dim page As New Vintasoft.Imaging.Pdf.Tree.PdfPage(document, Vintasoft.Imaging.PaperSizeKind.A6)
' add page to PDF document
document.Pages.Add(page)
' create a button and add button to PDF page
Dim button As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField = CreateButtonAndAddToPdfPage(page, "Submit")
' create submit action
Dim action As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfSubmitFormAction(document)
' specify that all fields of document must be submitted
action.Fields = document.InteractiveForm.Fields
' specify submit URL
action.Url = url
' specify the submit format
action.SubmitFormat = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldSubmitFormat.HTML
' set the button action
button.Annotation.ActivateAction = action
' save changes to a file
document.SaveChanges()
End Using
End Sub
''' <summary>
''' Creates button and adds it to PDF page.
''' </summary>
''' <param name="page">PDF page.</param>
''' <param name="caption">Caption of button.</param>
Public Shared Function CreateButtonAndAddToPdfPage(page As Vintasoft.Imaging.Pdf.Tree.PdfPage, caption As String) As Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField
' PDF document
Dim document As Vintasoft.Imaging.Pdf.PdfDocument = page.Document
' button position on PDF page
Dim rect As New System.Drawing.RectangleF(50, page.Size.Height - 150, 200, 100)
' create button
Dim button As New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(document, "button", rect)
' set the border style
button.Annotation.BorderStyle = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document)
button.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled
button.Annotation.BorderStyle.Width = 2
' set the appearance characteristics
button.Annotation.AppearanceCharacteristics = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document)
button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray
button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = caption
' set the text default appearance
Dim font As Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont = document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman)
button.SetTextDefaultAppearance(font, 15F, System.Drawing.Color.Black)
' if PDF document does NOT have interactive form
If document.InteractiveForm Is Nothing Then
' create interactive form in PDF document
document.InteractiveForm = New Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document)
End If
' add button to the interactive form of PDF document
document.InteractiveForm.Fields.Add(button)
' if PDF page does NOT have annotation list
If page.Annotations Is Nothing Then
' create annotation list for PDF page
page.Annotations = New Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document)
End If
' add the button annotation to PDF page
page.Annotations.Add(button.Annotation)
' update field appearance
button.UpdateAppearance()
' return the button
Return button
End Function
/// <summary>
/// Adds a submit button to a PDF document.
/// </summary>
/// <param name="pdfFilename">The filename of PDF document.</param>
/// <param name="url">URL to submit form.</param>
public static void AddSubmitFormButton(string pdfFilename, string url)
{
// open PDF document
using (Vintasoft.Imaging.Pdf.PdfDocument document =
new Vintasoft.Imaging.Pdf.PdfDocument(pdfFilename))
{
// create new PDF page
Vintasoft.Imaging.Pdf.Tree.PdfPage page = new Vintasoft.Imaging.Pdf.Tree.PdfPage(
document, Vintasoft.Imaging.PaperSizeKind.A6);
// add page to PDF document
document.Pages.Add(page);
// create a button and add button to PDF page
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField button =
CreateButtonAndAddToPdfPage(page, "Submit");
// create submit action
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfSubmitFormAction action =
new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfSubmitFormAction(document);
// specify that all fields of document must be submitted
action.Fields = document.InteractiveForm.Fields;
// specify submit URL
action.Url = url;
// specify the submit format
action.SubmitFormat = Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormFieldSubmitFormat.HTML;
// set the button action
button.Annotation.ActivateAction = action;
// save changes to a file
document.SaveChanges();
}
}
/// <summary>
/// Creates button and adds it to PDF page.
/// </summary>
/// <param name="page">PDF page.</param>
/// <param name="caption">Caption of button.</param>
public static Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField CreateButtonAndAddToPdfPage(
Vintasoft.Imaging.Pdf.Tree.PdfPage page, string caption)
{
// PDF document
Vintasoft.Imaging.Pdf.PdfDocument document = page.Document;
// button position on PDF page
System.Drawing.RectangleF rect = new System.Drawing.RectangleF(50, page.Size.Height - 150, 200, 100);
// create button
Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField button =
new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormPushButtonField(document, "button", rect);
// set the border style
button.Annotation.BorderStyle = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyle(document);
button.Annotation.BorderStyle.Style = Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationBorderStyleType.Beveled;
button.Annotation.BorderStyle.Width = 2;
// set the appearance characteristics
button.Annotation.AppearanceCharacteristics =
new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationAppearanceCharacteristics(document);
button.Annotation.AppearanceCharacteristics.BackgroundColor = System.Drawing.Color.LightGray;
button.Annotation.AppearanceCharacteristics.ButtonNormalCaption = caption;
// set the text default appearance
Vintasoft.Imaging.Pdf.Tree.Fonts.PdfFont font =
document.FontManager.GetStandardFont(Vintasoft.Imaging.Pdf.Tree.Fonts.PdfStandardFontType.TimesRoman);
button.SetTextDefaultAppearance(font, 15f, System.Drawing.Color.Black);
// if PDF document does NOT have interactive form
if (document.InteractiveForm == null)
// create interactive form in PDF document
document.InteractiveForm = new Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfDocumentInteractiveForm(document);
// add button to the interactive form of PDF document
document.InteractiveForm.Fields.Add(button);
// if PDF page does NOT have annotation list
if (page.Annotations == null)
// create annotation list for PDF page
page.Annotations = new Vintasoft.Imaging.Pdf.Tree.Annotations.PdfAnnotationList(document);
// add the button annotation to PDF page
page.Annotations.Add(button.Annotation);
// update field appearance
button.UpdateAppearance();
// return the button
return button;
}
Иерархия наследования
Требования
Целевые платформы: .NET 8; .NET 7; .NET 6; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5
Смотрите также