Convert HTML to PDF in .NET Desktop and Web Application

HTML to PDF Conversion has its own significance among conversions of different file formats into one another. You can convert HTML to PDF using different applications, tools and online services available. But, we are talking here about converting HTML to PDF programmatically. Yes, we are talking about automation of the entire process. How about the idea of including this feature into your own desktop/web application by using a few lines of code, isn’t it exciting? Aspose.PDF for .NET offers not only basic conversion of HTML to PDF like most of the free services offer but it also allows you to specify various options to achieve what you need. We are now going to take a drive to the road of HTML to PDF Conversion using Aspose.PDF for .NET in following section. Here we go..

Convert HTML to PDF in C#

You can convert HTML to PDF in a very basic manner using just a few lines of code with resource loading callback. Following is the code snippet that will allow you to achieve the purpose:

Convert a Web Page to PDF in C#

While discussing HTML to PDF Conversion, we cannot put conversion of a Web Page to PDF aside. You often need to convert a web page into PDF and this operation requires various steps if you perform it manually. The functionality is offered by the API which can be performed using the code shown below. Things to be noticed are, following code snippet covers two main and essential aspects of a Web Page to PDF conversion operation:

  • Download resources which a Web Page is using e.g. CSS, Images
  • You can provide credentials in case they are required to access the page

Render all content on a single PDF Page in C#

Things get more excited when we talk about what Aspose.PDF for .NET 19.7. It has very much improved to offer in this regard. Speaking of which, you can now render your all HTML content over a single page in PDF document. If you have some HTML content which output size is greater than one page, you can use option for rendering output data into single PDF page as following:

Render HTML with SVG Data

Since you can use SVG Data elements inside HTML, Aspose.PDF for .NET 19.7 allows you to perform conversion of such data into a PDF document. The following code snippet shows how to convert HTML file with SVG graphic tags to Tagged PDF Document:

Useful Enhancements and Fixes in v19.7

Following list shows further enhancements and fixes which API offers in this version:

  • Saving resultant PDF/A to stream with Transparency Mask is available now
  • Support to add Latex Script 
  • PDF to Image Conversion is further improvised
  • PDF to XPS conversion is improved
  • PCL to PDF Conversion is further improved
  • Several improvements are included while printing PDF
  • Memory consumption while using the API is further improved
  • Rendering of non English Characters is taken care of
  • PDF form functionality is improvised
  • PDF signing and security algorithms have been further improved for better results

Well, above was the most of all what Aspose.PDF for .NET 19.7 offers. Do not limit yourself to this blog post and have a look over release notes page of this version of the API to know more about this release. Do not hesitate to ask if you have any query. We will be back with another API update soon. Until then, stay tuned.