Powerful all-in-one PDF library for .NET
VS 2005/2008/2010/2012/2013

An ASP.NET handler to create a personalized PDF form that will mail itself to an e-mail address

Using PDFOne .NET

In a previous article, I have demonstrated how to create personalized PDF forms using an generic ASPX handler. There is a StackOverFlow.com question where they requirement is to create a form that will also mail itself to preconfigured e-mail address.

Acrobat JavaScript has a mailDoc() method for its Document object. This method will do the job. So, the handler was further modified to add a new button that will execute the mailDoc() method.

Here is a sample PDF that was created by the handler.

public void ProcessRequest(HttpContext context) {
  context.Response.Buffer = true;
  NameValueCollection frm = context.Request.Form;

  int i, n = frm.Count;

  // Create a document
  PDFDocument doc = new PDFDocument(PDFOne_License.KEY);

  doc.ApplyFormAppearances = true;
  doc.OpenAfterCreate = false;

  // Render text  identifying the form fields
  doc.WriteText("Enter your name", 1, 1);
  doc.WriteText("Select your country", 1, 2);

  // Create a text field
  PDFFormTextField txtFld = new PDFFormTextField();
  txtFld.Rectangle = new RectangleF(3, 1, 1.6f, 0.25f);
  txtFld.ToolTip = "Enter your name here";
  txtFld.FieldName = "TxtFld1";
  txtFld.BorderColor = Color.Black;
  txtFld.NameAsUnicode = false;

  // Create a list box
  PDFFormComboBox cmbBox = new PDFFormComboBox();
  cmbBox.Rectangle = new RectangleF(3, 2, 1f, 0.25f);
  cmbBox.AddItem("Select an option");
  cmbBox.FieldName = "cmbBox1";
  cmbBox.NameAsUnicode = false;
  cmbBox.BorderColor = Color.Black;

  // If the form was submitted, update the default values
  if (context.Request.Form.Count > 0)
      // Set submitted text form field value as default
      txtFld.FieldValue = frm[txtFld.FieldName];

      // Set the submitted list box option as selected
      for (i = 0; i < cmbBox.OptionList.Count; i++)
          // Check if current item in OptionList array list
          // matches the submitted combo box option
          if (cmbBox.OptionList[i].ToString() ==
          {  // same as frm["cmbBox1"]
              cmbBox.SelectedItemIndex = i;

  // Create the push button and set it to submit
  // form contents to the handler's URL
  PDFFormPushButton pushBtn = new PDFFormPushButton();
  pushBtn.Rectangle = new RectangleF(2, 3, 1.6f, 0.4f);
  pushBtn.BorderWidth = 2;
  pushBtn.ActionType =
  pushBtn.SubmitUrl =
      // Update! Update! Update!
  pushBtn.NormalCaption = "Save";
  pushBtn.FieldName = "PshBtn1";
  pushBtn.BorderColor = Color.Black;
  pushBtn.SubmitActionType = PDFSubmitActionType.HTTP_Post;

  // Javascript script for button
  string sJs =
  "try { " +
  "  this.mailDoc({" + 
       "bUI: false, " + 
       "cTo: \"johndoe@example.com\", " +
       "cSubject: \"Form completed\", " +
       "cMsg: \"PFA completed form.\" " + 
       " }); " +
  "} catch (e) { app.alert(e); }";

  // Button that will make the viewer application execute the script
  PDFFormPushButton pushBtn2 = new PDFFormPushButton();
  pushBtn2.Rectangle = new RectangleF(4, 3, 1.6f, 0.4f);
  pushBtn2.BorderWidth = 2;
  pushBtn2.BorderColor = Color.Black;
  pushBtn2.ActionType = PDFFormFieldActionType.Javascript_Action;
  pushBtn2.NormalCaption = "Mail";
  pushBtn2.ToolTip = "Click to e-mail the completed form.";
  pushBtn2.FieldName = "PshBtn2";
  pushBtn2.JavaScript = sJs;

  // Add form fields to the document

  // Write the forms document to the browser
  context.Response.ContentType = "application/pdf";


  // Close the document


Our .NET Developer Tools
XtremeDocumentStudio .NET

Multi-format document-processing component suite for .NET developers.


A .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications.

Our Delphi/C++Builder developer tools
XtremeDocumentStudio Delphi

Multi-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms.

eDocEngine VCL

A Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools.

PDFtoolkit VCL

A Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents.

Our Java developer tools
XtremeDocumentStudio (for Java)

Multi-format document-processing component suite for Java developers.

PDFOne (for Java)

A Java PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java applications.

Our Platform-Agnostic Cloud and On-Premises APIs

Cloud-hosted and On-Premises REST-based document-processing and document-viewing APIs

Privacy | Legal | Feedback | Newsletter | Blog | Resellers © 2002-2018 Gnostice Information Technologies Private Limited. All rights reserved.