Click here to Skip to main content
12,506,338 members (56,240 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
Hi,
I need to convert Html file into PDF file using c#

please, help ASAP.
Thank you.
Posted 20-Jul-12 2:22am
Updated yesterday
Comments
aarif moh shaikh 24-Sep-15 4:03am
   
use itextsharp
Member 12609251 29-Jun-16 9:29am
   
i want to hindi pdf generator please tell me best library in asp.net
Page 1 of 2

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

You can convert html page to pdf using wkhtmltopdf opensource library.

here is the implementation
Html to PDF in c#
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Use itextsharp library to convert simple html to pdf.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

There are many solutions can convert html to PDF. However they have different effects. For some converters, they are quick and free, but many can export only simple html webpage without dynamic images, while for other non converters, such as iTexsharp or other libraries, they can export complex webpage to PDF. As far as I know, the simplest solution that I ever seen is the code as below:

namespace htmltopdf
{
    class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            PdfDocument doc = new PdfDocument();
            String url = “Http://apple.com/”;
            doc.LoadFromHTML(url, false, true, true);
            doc.SaveToFile(“webpageaspdf.pdf”);
            doc.Close();
            System.Diagnostics.Process.Start(“webpageaspdf.pdf”);
        }
    }
}

You can see details about which tool is best suitable for you:
Save Webpage as PDF[^]

I belive this works only for Windows 8.1.
  Permalink  
v2
Comments
Pro Idiot 28-Nov-12 22:54pm
   
Vote of 5 .
Lacy00 28-Nov-12 22:57pm
   
Thanks!
nika2008 17-Mar-13 18:55pm
   
simple way, best way +5
swift.D 23-Oct-14 5:28am
   
Will this need a dll?
Sean-M-F 6-May-15 2:22am
   
This is great, and swift.D no it does not require anything, but note that PdfDocument class[^] is only available for Windows Store apps.
If you need this conversion for some other Windows application may I suggest you to read this article about HTML to PDF conversion done in C#.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 26

There are many C# html to pdf converters and some of them are free at least for relatively small html files. The most used is wkhtmltopdf which offers a command line utility to convert html to pdf on windows, linux, mac, etc and can be used from many languages but a best one I found for for .net is this example project with code samples for asp.net and mvc:

HtmlToPdf htmlToPdfConverter = new HtmlToPdf();
byte[] pdfBuffer = htmlToPdfConverter.ConvertUrlToMemory(url);

You can save the buffer to a file, send by email as attachment or download it in browser depending on what you want to do in the end with the pdf.
  Permalink  
Comments
   
This question was opened and answered FOUR years ago. Please do not trawl for dead questions, work on the current ones.
Page 1 of 2
1 2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 27 Sep 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100