Convert Web Page (Aspx,Html) to PDF File - Asp.net

For many developers while developing applications the question arises that How to Convert  Web Page (Aspx,Html,php) to PDF File. Solution is here..

You can convert any web URL in to PDF file by this utility.


Searching the web, I have found several command line tools that allow you to convert a HTML-document to a PDF-document, however they all seem to use their own, and rather incomplete rendering engine, resulting in poor quality. Recently QT 4.4 was released with a WebKit widget (WebKit is the engine of Apples Safari, which is a fork of the KDE KHtml), and making a good tool became very easy.

Simple shell utility to convert HTML to PDF using the webkit rendering engine, and qt.

That is it. You can go to any web page... even aspx. is supported better than any other utility as it uses the web-kit HTML rendering engine (Safari, Chrome). Enjoy
There is a single .exe (7 mb) that can be used from .Net simply by using Process.Start Make sure that you copy the exe into your project directory or you have to specify the full path..

Example: -

public void HtmlToPdf(string website, string destinationFile)
{
try
{
Process p = new Process();
p.StartInfo = new ProcessStartInfo();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = "C:\\Program Files\\wkhtmltopdf\\wkhtmltopdf.exe";
website = "\"" + website + "\"";
string arguments1 = website + " " + destinationFile;
p.StartInfo.Arguments = arguments1;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.CreateNoWindow = true;
p.Start();
p.WaitForExit();
p.Close();
p.Dispose();
}
catch (Exception ex)
{
throw ex;
}
}
  

Comments

  1. There is one more nice article here HTML TO PDF
    http://geeksprogrammings.blogspot.in/2014/03/convet-html-to-pdf-asp-itextsharp.html

    ReplyDelete
  2. great article....I have used Expert PDF. If you dont have coding knowledge then you can check details here
    http://www.html-to-pdf.net/free-online-pdf-converter.aspx

    ReplyDelete

Post a Comment