Developer Tools
|
Office Productivity Applications
|
Platform-Agnostic APIs
|
Home | Online Demos | Downloads | Buy Now | Support | About Us | News | Working Together | Contact Us
PDFOne .NET can be used in "Win-Forms" and ASP.NET applications to generate and process PDF documents. You can also use PDFOne in ASP.NET MVC application. In this article, we will see how to use it in a sample ASP.NET MVC 3 web application.
In the following C# example, our MVC3 application will generate a simple HTML form that pretends to be a online money transfer application of a bank. After the form is posted, the application will generate a PDF purportedly containing the details of the transaction and send it down to the browser.
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace BankTransfer.Models { public class TransferDetails { public string PayeeName { get; set; } public string AccountNumber { get; set; } public string Amount { get; set; } } }
HomeController.cs
). This will have a built-in Index()
action method.
public ActionResult Index() {
return View();
}
using BankTransfer.Models; using Gnostice.PDFOne;
index.cshtml
) linked to our model for this Index()
action.@model BankTransfer.Models.TransferDetails @{ Layout = null; } <html> <head> <title>Bank of Money - Initiate Money Transfer</title> </head> <body> <div> <h1>Initiate Money Transfer</h1> @using (Html.BeginForm()) { <p>Enter payee account #: @Html.TextBox("AccountNumber")</p> <p>Enter payee name #: @Html.TextBox("PayeeName")</p> <p>Enter amount #: @Html.TextBox("Amount")</p> <input type="submit" value="Make Transfer" /> } </div> </body> </html>
HttpGet
attribute
to the existing Index()
action method. This will make the
controller use the method only to handle simple HTTP GET requests.
[HttpGet] public ActionResult Index() { return View(); }
Index()
action
and give it a HttpPost
attribute. This
will make the controller use this only method to process
the "posted" form contents and generate the transaction
statement.
[HttpPost] public void Index(TransferDetails td) { // Create a PDF document PDFDocument doc = new PDFDocument("your-license-key"); doc.WriteText("Bank of Money", 1, 1); doc.WriteText("---------------------------------", 1, 1.1f); // Render text PDFFont fntCourier = new PDFFont(StdType1Font.Courier, 16); doc.WriteText("Payee account # :", fntCourier, 1, 1.4f); doc.WriteText("Payee name :", fntCourier, 1, 1.7f); doc.WriteText("Amount transferred:", fntCourier, 1, 2f); doc.WriteText("Transaction # :", fntCourier, 1, 2.3f); doc.WriteText("Date and Time # :", fntCourier, 1, 2.6f); doc.WriteText(td.AccountNumber, fntCourier, 4, 1.4f); doc.WriteText(td.PayeeName, fntCourier, 4, 1.7f); doc.WriteText("Rs. " + td.Amount, fntCourier, 4, 2f); doc.WriteText((new Random()).Next(199999, 599999).ToString(), fntCourier, 4, 2.3f); doc.WriteText(DateTime.Now.ToString(), fntCourier, 4, 2.7f); // Write the document to the browser this.Response.Clear(); this.Response.ContentType = "application/pdf"; doc.Save(this.Response.OutputStream); doc.Close(); }The values that the action method writes to the PDF are bound to the properties of the
TransferDetails
instance passed to it.
---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. |