Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
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.AddItem("India"); cmbBox.AddItem("Germany"); cmbBox.AddItem("Russia"); cmbBox.AddItem("USA"); 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() == frm[cmbBox.FieldName]) { // 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 = PDFFormFieldActionType.Submit_Action; pushBtn.SubmitUrl = // Update! Update! Update! "http://localhost:8080/save_pdf.ashx"; 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 doc.AddFormField(txtFld); doc.AddFormField(cmbBox); doc.AddFormField(pushBtn); doc.AddFormField(pushBtn2); // Write the forms document to the browser context.Response.ContentType = "application/pdf"; doc.Save(context.Response.OutputStream); context.Response.Flush(); context.Response.End(); // Close the document doc.Close(); }
---o0O0o---
Our .NET Developer Tools | |
---|---|
![]() Gnostice Document Studio .NETMulti-format document-processing component suite for .NET developers. |
![]() PDFOne .NETA .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 | |
---|---|
![]() Gnostice Document Studio DelphiMulti-format document-processing component suite for Delphi/C++Builder developers, covering both VCL and FireMonkey platforms. |
![]() eDocEngine VCLA Delphi/C++Builder component suite for creating documents in over 20 formats and also export reports from popular Delphi reporting tools. |
![]() PDFtoolkit VCLA Delphi/C++Builder component suite to edit, enhance, view, print, merge, split, encrypt, annotate, and bookmark PDF documents. |
Our Java developer tools | |
---|---|
![]() Gnostice Document Studio JavaMulti-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 | |
---|---|
![]() StarDocsCloud-hosted and On-Premises REST-based document-processing and document-viewing APIs |
Privacy | Legal | Feedback | Newsletter | Blog | Resellers | © 2002-2023 Gnostice Information Technologies Private Limited. All rights reserved. |