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();
Byte[] bufferPDF = wol.GetUrlPDF(url);
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();
System.Diagnostics.Process.Start(@"sample.pdf");
History
- 14th March, 2013: Initial version
- 15th March, 2013: Update