Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Convert HTML to PDF

0.00/5 (No votes)
15 Mar 2013 1  
Application converts HTML link into PDF file format

Introduction

This tip is simple and is based on WkHtmlToXSharp library which converts HTML to PDF, here we have made few enhancements to fulfill our needs, hope this effort will help you in some way.

Using the Code

The code is really simple, you just need to create and object and pass the URL to GetUrlPDF() function described below, which returns byte array, from here, it can be converted to your desire stream. Here, we used file stream to put up the show.

WkHtmlToPdfConverter wol = new WkHtmlToPdfConverter();

           // Get PDF in bytes
           Byte[] bufferPDF = wol.GetUrlPDF(url);

           // Convert bytes to stream
           System.IO.FileStream writeStream = new System.IO.FileStream
            ("sample.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write);
           writeStream.Write(bufferPDF, 0, Convert.ToInt32(bufferPDF.Length));
           writeStream.Close();

           // Open PDF file
           System.Diagnostics.Process.Start(@"sample.pdf");

History

  • 14th March, 2013: Initial version
  • 15th March, 2013: Update

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here