Generate PDF from HTML with C# in ASP.NET

PDF Duo .Net is a converting component for use in"<br><i>HTML table Example</i>";try
ASP.NET (VB, C# etc.) and enables to convert HTML{conv.OpenHTML(html);conv.SavePDF(MapPath("~
to PDF. The main class HtmlToPdf provides severalReports/") + pdf);
methods and properties to enable multi-purpose}catch (Exception ex)
customization of the resulting PDF. Main functions allow{throw ex;
to convert HTML represented as a File, Page from Url}
address, Stream or as a String.}
Developers can easily invoke the converting}
component in their own application or website projectsAdobe's PDF format is one of the most widely
on base of ASP.NET. To deploy the PDF Duo .Netaccepted document formats in use today. Most users
component you will need only three lines of code.and clients expect that the software you write will be
Installing package is provided with fully featured demosable to generate and work with PDFs. Unfortunately,
written in both C# and Visual Basic. Simple exampleshowever, Adobe does not offer a free SDK that you
with source code help you using the PDF Duo .Netcan download and use; you have to pay to license the
component to successfully convert HTML to PDF.API.
I have used PDFDuo-NET.dll (version 2.3) in my projectStatically creating PDF files is quite simple. Applications,
which is very useful. First, you need to convert contentsuch as OpenOffice.org Writer, give the user options
of your ASPX to HTML and then converted thatto export a word processor document as a PDF file.
HTML content into a PDF file or another way which IUsers can even find utilities that allow them to "print"
use is to create a simple HTML string and thendirectly to a PDF file. Features like these are
convert it.well-known to end users and are useful for creating a
See below C# code:using System;usingPDF based off a document originally created in
System.Web;using System.Web.UI;usinganother format.
System.IO;using DuoDimension;public partial classBut what about dynamic PDF generation? Some
_Default : System.Web.UI.Pageprograms need to be able to write out PDF files. PDF
{protected void Page_Load(object sender, EventArgsDuo .NET alleviates this problem. It will give you the
e)ability to add PDF functionality to your applications.
{string html = "<table width='240'>" +Using PDF Duo .NET, you can create PDF by
"<tr style='background-color:#00AAFF'><tdconverting HTML string or file, so you can deliver the
width='50%'>Product</td><tdfunctionality your users expect.
width='25%'>Quantity</td><td>Cost<It is up to you how you generate your HTML from
td></tr>" +your data source and then convert it to PDF or
"<tr><td>Product Name 1</td><td>5<another option is to convert your ASPX to HTML first
td><td>$100</td></tr>" +and then to PDF. This need to be done because PDF
"<tr><td>Product Name 2<Duo .NET component can only works with clear html
td><td>15</td><td>$300</td><format. It did not support for asp:control and
tr>" +runat=server tag for now. You can apply styleshhet to
"<tr><td>Product Name 3<tables, h1, h2, paragraph, and all others necessary
td><td>55</td><td>$500</td><stylesheet tag to complete your PDF.
tr>" +PDF Duo .NET is absolutely independent, doesn't
"</table>";string pdf = "pdf_file.pdf";require any additional components and really
DuoDimension.HtmlToPdf conv = newappropriate for ASP.NET websites. The component is
DuoDimension.HtmlToPdf();conv.PageInfo.PageFormatwritten entirely in C# for the .NET platform. PDF Duo
= ePageFormat.A4;conv.PdfDocumentInfo.Title =.NET is a library that allows you to generate (convert)
"Generate PDF from HTML source";conv.Header =PDF documents from HTML web page.