Generate PDF from HTML with C# in ASP.NET

01/07/2010

PDF Duo .Net is a converting component for use in ASP.NET (VB, C# etc.) and enables toconvert HTML to PDF. The main class HtmlToPdf provides several methods and properties to enable multi-purpose customization of the resulting PDF. Main functions allow 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 projects on base of ASP.NET. To deploy the PDF Duo .Net component you will need only three lines of code. Installing package is provided with fully featured demos written in both C# and Visual Basic. Simple examples with source code help you using the PDF Duo .Net component to successfully convert HTML to PDF.

I PDFDuo used NET.dll (version 2.3) in my project, which is very useful. First you need to convert the contents of your ASPX to HTML and then converted that HTML content into a PDF file or a different way, which I use to create a simple HTML string and then convert it.

See below C# code:
using System;
using System.Web;
using System.Web.UI;
using System.IO;
using DuoDimension;


public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string html = "<table width='240'>" +
"<tr style='background-color:#00AAFF'><td width='50%'>Product</td><td width='25%'>Quantity</td><td>Cost</td></tr>" +
"<tr><td>Product Name 1</td><td>5</td><td>$100</td></tr>" +
"<tr><td>Product Name 2</td><td>15</td><td>$300</td></tr>" +
"<tr><td>Product Name 3</td><td>55</td><td>$500</td></tr>" +
"</table>";
string pdf = "pdf_file.pdf";
DuoDimension.HtmlToPdf conv = new DuoDimension.HtmlToPdf();
conv.PageInfo.PageFormat = ePageFormat.A4;
conv.PdfDocumentInfo.Title = "Generate PDF from HTML source";
conv.Header = "<br><i>HTML table Example</i>";
try
{
conv.OpenHTML(html);
conv.SavePDF(MapPath("~/Reports/") + pdf);
}
catch (Exception ex)
{
throw ex;
}
}
}
Adobe's PDF format is the most widely accepted file formats, in the current use. Most users and customers expect you to write software that will be able to generate and process PDF files. Unfortunately, Adobe does not provide a free SDK, you can download and use, you have to pay licensing API.

Static creating PDF files is very simple. Applications such as OpenOffice.org Writer, with which the user options export to a word processing document as a PDF file. Users can also enable utilities to find them,

But what about dynamic PDF generation? Some programs need to be able to write out PDF files. PDF Duo .NET alleviates this problem. It will give you the ability to add PDF functionality to your applications. Using PDF Duo .NET, you can create PDF by converting HTML string or file, so you can deliver the functionality your users expect.

That's how you have the PDF from the option to convert to another data source and generates an HTML or, HTML and your ASPX is to convert, PDF to first. Because, PDF duo. NET components as possible to clear it must work html format. It does not support ASP: Control and runat = server tags so far. Your table, H1, H2 in the paragraph styleshhet, with all the necessary tags for style sheets and other PDF can be fully applied.

PDF Duo .NET is absolutely independent, doesn't require any additional components and really appropriate for ASP.NET websites. The component is written entirely in C# for the .NET platform. PDF Duo .NET is a library that allows you to generate (convert) PDF documents from HTML web page.

For more information about the component please visit the product page:
http://www.duodimension.com/html_pdf_asp.net/component_html_pdf.aspx

If you have any questions or concerns about component, let us know:
{support@duodimension.com }

Posted in: asp.net| Tags: html pdf generate with

Hot Posts

Latest posts

Tags

Others

Sponsors

asp.net interview questions