Click here to Skip to main content
Click here to Skip to main content
Go to top

Convert html to PDF

, 15 Mar 2013
Rate this:
Please Sign up or sign in to vote.
Application convert's html link into PDF file format.

Introduction

Article is simple and based on WkHtmlToXSharp library which convert's html to PDF, here we had done little enhancement to fulfill our needs, hope this effort would serve you in some way.

   Download Application

Using the code  

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 had 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"); 

 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Hasan Hyder
Software Developer
Pakistan Pakistan
No Biography provided
Group type: Organisation

29 members

Follow on   Google+

Comments and Discussions

 
QuestionWhat did you change? PinmemberIhtsham ul haq9-Sep-14 1:34 
AnswerRe: What did you change? PingroupHasan Hyder9-Sep-14 6:20 
QuestionHow to support Chinese characters or UTF-8 characters ? Pinmembergotolnc6-Jul-13 14:42 
AnswerRe: How to support Chinese characters or UTF-8 characters ? Pinmembergotolnc6-Jul-13 14:47 
GeneralMy vote of 5 PinmemberPrasad Khandekar15-Mar-13 4:52 
GeneralRe: My vote of 5 PingroupHasan Hyder17-Mar-13 22:50 
GeneralMy vote of 4 PinmemberNerijus_Vax14-Mar-13 3:47 
GeneralRe: My vote of 4 [modified] PingroupHasan Hyder14-Mar-13 19:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 15 Mar 2013
Article Copyright 2013 by Hasan Hyder
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid