PDF Mosaic: How to submit and reset form actions


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code

 

This sample shows how to use Submit-Form and Reset-Form actions.

A Submit-Form action (PDFSubmitFormAction class) transmits the names and values of associated controls to a specified uniform resource identifier (URI), presumably the address of a Web server that will process them and send back a response.

A Reset-Form action (PDFResetFormAction class) resets associated controls to their default values.

C# :

using PDFMosaic;
using System;
 
namespace SubmitResetFormActions
{
  class SubmitResetFormActions
  {
    static void Main(string[] args)
    {
      PDFDocument document = new PDFDocument();
      PDFPage page = new PDFPage(PDFPaperFormat.A4);
 
      PDFFont fnt = new PDFFont(PDFStandardFont.Helvetica, 8);
      PDFBrush br = new PDFSolidBrush();
 
      PDFEditBox textBox = new PDFEditBox(20, 40, 100, 20, "edit1");
      textBox.Text = "Hello";
      page.Annotations.Add(textBox);
 
      PDFCheckBox checkBox = new PDFCheckBox(20, 70, 15, 15, "checkBox1");
      page.Annotations.Add(checkBox);
      page.Canvas.DrawString("Check box", fnt, br, 40, 72);
 
      PDFRadioButton radioButton1 = new PDFRadioButton(20, 95, 15, 15, "radio", "val1");
      page.Annotations.Add(radioButton1);
      radioButton1.Checked = true;
      page.Canvas.DrawString("Value 1", fnt, br, 40, 97);
 
      PDFRadioButton radioButton2 = new PDFRadioButton(20, 110, 15, 15, "radio", "val2");
      page.Annotations.Add(radioButton2);
      page.Canvas.DrawString("Value 2", fnt, br, 40, 112);
 
      PDFPushButton resetButton = new PDFPushButton(20, 133, 40, 12, "btn1");
      resetButton.Caption = "Reset";
      resetButton.Font.Size = 6;
      page.Annotations.Add(resetButton);
 
      PDFPushButton submitButton = new PDFPushButton(70, 133, 40, 12, "btn2");
      submitButton.Caption = "Submit";
      submitButton.Font.Size = 6;
      page.Annotations.Add(submitButton);
 
      PDFResetFormAction resetAction = new PDFResetFormAction();
      resetAction.Fields.Add(textBox);
      resetAction.Fields.Add(checkBox);
      resetAction.Fields.Add(radioButton1);
      resetAction.Fields.Add(radioButton2);
      resetButton.OnActivated = resetAction;
 
      PDFSubmitFormAction submitAction = new PDFSubmitFormAction(new Uri("https://www.pdfmosaic.com/login"));
      submitAction.SubmitFormat = PDFSubmitDataFormat.HTML;
      submitAction.SubmitMethod = PDFSubmitMethod.Get;
      submitAction.Fields.Add(textBox);
      submitAction.Fields.Add(checkBox);
      submitAction.Fields.Add(radioButton1);
      submitAction.Fields.Add(radioButton2);
      submitButton.OnActivated = submitAction;
 
      document.Pages.Add(page);
      document.Save("SubmitResetFormActions.pdf", true);
    }
  }
}

 

Visual Basic :

Imports PDFMosaic
Imports System
 
Module SubmitResetFormActions
  Sub Main()
    Dim document As New PDFDocument()
    Dim page As New PDFPage(PDFPaperFormat.A4)
 
    Dim fnt As New PDFFont(PDFStandardFont.Helvetica, 8)
    Dim br As New PDFSolidBrush()
 
    Dim textBox As New PDFEditBox(20, 40, 100, 20, "edit1")
    textBox.Text = "Hello"
    page.Annotations.Add(textBox)
 
    Dim checkBox As New PDFCheckBox(20, 70, 15, 15, "checkBox1")
    page.Annotations.Add(checkBox)
    page.Canvas.DrawString("Check box", fnt, br, 40, 72)
 
    Dim radioButton1 As New PDFRadioButton(20, 95, 15, 15, "radio", "val1")
    page.Annotations.Add(radioButton1)
    radioButton1.Checked = True
    page.Canvas.DrawString("Value 1", fnt, br, 40, 97)
 
    Dim radioButton2 As New PDFRadioButton(20, 110, 15, 15, "radio", "val2")
    page.Annotations.Add(radioButton2)
    page.Canvas.DrawString("Value 2", fnt, br, 40, 112)
 
    Dim resetButton As New PDFPushButton(20, 133, 40, 12, "btn1")
    resetButton.Caption = "Reset"
    resetButton.Font.Size = 6
    page.Annotations.Add(resetButton)
 
    Dim submitButton As New PDFPushButton(70, 133, 40, 12, "btn2")
    submitButton.Caption = "Submit"
    submitButton.Font.Size = 6
    page.Annotations.Add(submitButton)
 
    Dim resetAction As New PDFResetFormAction()
    resetAction.Fields.Add(textBox)
    resetAction.Fields.Add(checkBox)
    resetAction.Fields.Add(radioButton1)
    resetAction.Fields.Add(radioButton2)
    resetButton.OnActivated = resetAction
 
    Dim submitAction As New PDFSubmitFormAction(New Uri("https://www.pdfmosaic.com/login"))
    submitAction.SubmitFormat = PDFSubmitDataFormat.HTML
    submitAction.SubmitMethod = PDFSubmitMethod.Get
    submitAction.Fields.Add(textBox)
    submitAction.Fields.Add(checkBox)
    submitAction.Fields.Add(radioButton1)
    submitAction.Fields.Add(radioButton2)
    submitButton.OnActivated = submitAction
 
    document.Pages.Add(page)
    document.Save("SubmitResetFormActions.pdf", True)
  End Sub
End Module

 


Home       Features       Download       Tutorial       Version History       License       PDF Mosaic Blog       Source Code