Developer Tools
|
Office Productivity Applications
|
Enterprise Solutions
|
|||||||||||||||||||||||







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 Developer Tools | |
|---|---|
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. |
XtremePDFConverter VCLA Delphi/C++Builder component to intelligently convert PDF to user-friendly Word RTF documents. |
|
PDFOne .NETA .NET PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, and bookmark PDF documents in .NET applications. |
XtremeDocumentStudio .NETMulti-format document-processing component suite for .NET developers |
PDFOne (for Java™)A Java™ PDF component suite to create, edit, view, print, reorganize, encrypt, annotate, bookmark PDF documents in Java™ applications. |
XtremeFontEngine (for Java)Java font engine to render glyphs from Type 1, Type 2 (CFF), and TrueType fonts |
| Our Office Productivity Applications |
|---|
Free PDF ReaderA free, fast, and portable application for viewing, printing and converting PDF documents. |
| Privacy | Legal | Feedback | Newsletter | Resellers | © 2002-2013 Gnostice Information Technologies Private Limited. All rights reserved. |
This site is best viewed on a screen with minimum resolution of 1152 x 864 pixels. Windows XP users are advised to use Microsoft ClearType Tuning for optimal experience. Also, please use the latest version of a standards-compliant browser such as Firefox, Opera, or Dragon (Chromium).