VintaSoft Imaging .NET SDK v8.6
Vintasoft.Imaging.Pdf.Tree.InteractiveForms Namespace / PdfSubmitFormAction Class
Members Example



In This Topic
    PdfSubmitFormAction Class
    In This Topic
    Represents a submit-form action.
    Object Model
    PdfSubmitFormAction ClassPdfBasicObject ClassPdfDocument ClassPdfInteractiveFormFieldList ClassPdfInteractiveFormField ClassPdfIndirectReference ClassPdfUrlSpecification Class
    Syntax
    'Declaration
     
    Public Class PdfSubmitFormAction 
       Inherits PdfInteractiveFormAction
    public class PdfSubmitFormAction : PdfInteractiveFormAction 
    public __gc class PdfSubmitFormAction : public PdfInteractiveFormAction 
    public ref class PdfSubmitFormAction : public PdfInteractiveFormAction 
    Remarks
    A submit-form action transmits the names and values of selected interactive form fields to a specified uniform resource locator (URL), presumably the address of a Web server that will process them and send back a response.
    Example
    This example shows how to send a form data to a certain 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;
    }
    Inheritance Hierarchy

    System.Object
       Vintasoft.Imaging.Pdf.Tree.PdfTreeNodeBase
          Vintasoft.Imaging.Pdf.Tree.PdfAction
             Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfInteractiveFormAction
                Vintasoft.Imaging.Pdf.Tree.InteractiveForms.PdfSubmitFormAction

    Requirements

    Target Platforms: Windows 10, Windows 8, Windows 7, Windows Vista, Windows XP, Windows Server 2012, Windows Server 2008, Windows Server 2003

    See Also