The easy method to convert HTML to PDF in ASP.NET

Elerium HTML to PDF .NET component, new release 2.5 has been introduced by Elerium Software.
 
May 8, 2013 - PRLog -- HTML format is simple and easy to use and allows to create complex reports from the raw data with a minimum of effort. But the appearance of HTML documents can be quite different depending on the browser. Also HTML documents do not have any protection. Therefore, the best choice for the provision of important reports to end users is a PDF document. Appearance of the PDF document is always the same and does not depend on the viewing software and security measures can be easily added to a PDF document.

When a developer creates an application or site, he can create a PDF document manually to understand the format specification, but it is a very long and laborious process. On the other side, the developer can use ready-made libraries for working with the PDF. One of these solutions is Elerium HTML to PDF .NET component.

Elerium HTML to PDF .NET component, new release 2.5 has been introduced by Elerium Software. It has several important changes:

- Improved the CSS parser of Html to PDF converter.
- Added a parsing of tabs in HTML files.
- Improved rendering of images in the PDF document.
- Fixed issues of image alignment at PDF rendering.
- Fixed issues of carrying the image over to the next line.

How to convert an HTML file to a PDF document? This is very easy. First of all, a developer must install HTML to PDF .NET component to the project:

1. Add HTML to PDF .Net component to the solution. Simply put Docs.PDF.dll into /bin folder of the project.
2. Initialize the HtmlToPdf instance.

When the component is connected to the project a developer can convert HTML to PDF:

ASP.NET example

// Initialize the string variables of input and output files
string file_html = @"C:\hdoc.html";
string file_pdf = @"C:\new.pdf";
try
{
// Create a new instance of the HtmlToPdf class
Docs.Pdf.HtmlToPdf conv = new Docs.Pdf.HtmlToPdf();
// Open the Html source
conv.OpenHTML(file_html);
// Convert html to pdf and save pdf to certain path and file name
conv.SavePDF(file_pdf);
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
Most often a developer need to convert dynamically generated HTML string to the PDF. It is also very easy:

C# + ASP.NET example

Docs.Pdf.HtmlToPdf conv = new Docs.Pdf.HtmlToPdf();
conv.BasePath = MapPath("~/");
conv.PageInfo.PageFormat = Docs.Pdf.ePageFormat.A4;
conv.PageInfo.PageOrientation = Docs.Pdf.ePageOrientation.Portrait;
conv.OpenHTML(@"<table width='100%'>
<tr>
<td width='19%'><strong>Last update:</strong></td>
<td width='81%'> 23 Jun 2009 - 01:22</td>
</tr>
</table>");
conv.SavePDF(MapPath("~/pdf/") + "report.pdf");

About Elerium Software

Elerium Software develops professional solutions for use in .NET projects (C#, VB.NET, ASP.NET) that aimed to read/write/convert different office/web documents and formats. Elerium Software components are based on the unique design and fast algorithms that allow being independent from the third-party applications and libraries.

For more information about the component please visit the product page:
http://www.eleriumsoft.com/PDF_NET/HTML2PDF/Default.aspx
End
Source: » Follow
Email:***@eleriumsoft.com Email Verified
Tags:Html To Pdf, Net, PDF, Html, Asp Net
Industry:Computers, Software
Location:luzern - Switzerland
Account Email Address Verified     Account Phone Number Verified     Disclaimer     Report Abuse
Elerium Software PRs
Trending News
Most Viewed
Top Daily News



Like PRLog?
9K2K1K
Click to Share