Generate PDF from HTML with C# in ASP.NET

PDF Duo .Net is a component for use in ASP.NET (VB, C# etc.) It converts HTML to PDF, provides several methods and properties for multi-purpose customization of the PDF. Main functions allow to convert HTML represented as a File,Url,Stream,String.
By: DuoDimension Software
 
Sept. 15, 2009 - PRLog -- 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 have used PDFDuo-NET.dll (version 2.3) in my project which is very useful. First, you need to convert content of your ASPX to HTML and then converted that HTML content into a PDF file or another way which I use is 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 = "" +
           "ProductQuantityCost" +
           "Product Name 15$100" +
           "Product Name 215$300" +
           "Product Name 355$500" +
           "";
       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 = "HTML table Example";
       try
       {
           conv.OpenHTML(html);
           conv.SavePDF(MapPath("~/Reports/") + pdf);
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }
}
Adobe's PDF format is one of the most widely accepted document formats in use today. Most users and clients expect that the software you write will be able to generate and work with PDFs. Unfortunately, however, Adobe does not offer a free SDK that you can download and use; you have to pay to license the API.

Statically creating PDF files is quite simple. Applications, such as OpenOffice.org Writer, give the user options to export a word processor document as a PDF file. Users can even find utilities that allow them to "print" directly to a PDF file. Features like these are well-known to end users and are useful for creating a PDF based off a document originally created in another format.

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.

It is up to you how you generate your HTML from your data source and then convert it to PDF or another option is to convert your ASPX to HTML first and then to PDF. This need to be done because PDF Duo .NET component can only works with clear html format. It did not support for asp:control and runat=server tag for now. You can apply styleshhet to tables, h1, h2, paragraph, and all others necessary stylesheet tag to complete your PDF.

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_ht...

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

# # #

Our goal is to provide high-quality components for converting between file formats. We develop components to convert formats such as PDF, HTML, DOC, XLS, RTF, XML. Users feedback is most important in helping us provide you with the best possible products. Contact us at: support@duodimension.com
End
Source:DuoDimension Software
Email:***@duodimension.com Email Verified
Tags:Html To Pdf, Asp Net, c, Convert, PDF, Html, Convert Html To Pdf, Using, Component
Industry:Computers, Technology, Internet
Location:United States
Account Email Address Verified     Disclaimer     Report Abuse



Like PRLog?
9K2K1K
Click to Share