Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
AcroForms or PDF forms are one of the reasons why PDF documents are so popular on the Internet. As they have a uniform appearance when they are viewed on a computer and when they are printed on paper, AcroForms are favored by government departments and other institutions.
Usually, when a PDF forms document is submitted online, the Web server that accepts the form simply stores the submitted values to a database. Some organizations save the submitted values back to a copy of the original form and then store the whole document in their database. This latter approach allows them to use such filled-in forms alongside printed forms that were simply scanned and stored as images.
In a Web application, you can serve either static (pre-built) or dynamically generated PDF forms. If you are serving static PDF forms, then you need to simply store the PDF forms document in some public location on your server and provide the link to that file on a web page.
If you need to serve dynamically generated PDF files, then you would not want to store it temporarily on the server. Instead, you would prefer to simply write the PDF document as a binary stream to the browser. In this article, we will see more about this.
To dynamically serve PDF forms in ASP.NET, you need to have the PDF forms document as a memory stream object and then write that memory stream to your ASPX page's response stream (System.Web.Page.Response
property, an object of the type System.Web.HttpResponse.OutputStream
.)
PDFOne .NET allows you to save PDF documents to files, memory streams, and byte arrays. So, the solution would be to use the Gnostice.PDFOne.PDFDocument.Save(Stream)
method to write the forms document to the ASPX page's HTTP response stream.
To create a sample C# PDF forms-generating Web application, perform the steps mentioned below.
Using
directives.
using System.Drawing;
using Gnostice.PDFOne;
protected void Button1_Click(object sender, EventArgs e) { // Create a document PDFDocument doc = new PDFDocument("your-license-key"); doc.ApplyFormAppearances = true; doc.OpenAfterCreate = false; // Following code adds form fields to the document. // For dynamic PDF generation, the choice of the form // fields should be based on the requirements of your // application at run-time. // Write labels doc.WriteText("Enter your name", 1, 1); doc.WriteText("Select your country", 1, 2); // Create a text field PDFFormTextField txtFld = new PDFFormTextField(); // Location of the form field txtFld.Rectangle = new RectangleF(3, 1, 1.6f, 0.25f); txtFld.FieldValue = "John Doe"; txtFld.ToolTip = "Enter your name here"; // Specify a name for the form field. (To obtain their values, // form fields are identified by their name.) txtFld.FieldName = "TxtFld1"; txtFld.BorderColor = Color.Black; txtFld.NameAsUnicode = false; // Add the text field to the document doc.AddFormField(txtFld); // Create a list box PDFFormListBox lstBox = new PDFFormListBox(); lstBox.Rectangle = new RectangleF(3, 2, 0.6f, 0.5f); lstBox.AddItem("India"); lstBox.AddItem("Germany"); lstBox.AddItem("Russia"); lstBox.SelectedItemIndex = 0; lstBox.FieldName = "LstBox1"; lstBox.NameAsUnicode = false; lstBox.BorderColor = Color.Black; // Add the list box to the document doc.AddFormField(lstBox); // Create the push button and set it to submit // form contents to a website URL that will // process the form contents PDFFormPushButton pushBtn = new PDFFormPushButton(); pushBtn.Rectangle = new RectangleF(3, 3, 1.6f, 0.4f); pushBtn.BorderWidth = 2; // Specify that the form must be submitted when // the button is clicked. pushBtn.ActionType = PDFFormFieldActionType.Submit_Action; // Specify the web page to which the form is // submitted. pushBtn.SubmitUrl = "http://www.gnostice.com/newsletters" + "/demos/200804/forms_test.asp"; pushBtn.NormalCaption = "Submit"; pushBtn.FieldName = "PshBtn1"; pushBtn.BorderColor = Color.Black; pushBtn.NameAsUnicode = false; // Specify form submission method pushBtn.SubmitActionType = PDFSubmitActionType.HTTP_Post; // Add the push button to the document doc.AddFormField(pushBtn); // Get the page's output stream ready Response.Clear(); Response.BufferOutput = true; // Make the browser display the forms document // using a PDF plug-in. (If no plug in is available, // the browser will show the File -> Save As dialog box. Response.ContentType = "application/pdf"; // Write the forms document to the browser doc.Save(Response.OutputStream); doc.Close(); doc.Dispose(); Response.Flush(); Response.Close(); }
Here is the output when you run the application.
---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-2024 Gnostice Information Technologies Private Limited. All rights reserved. |