locked
Native .NET library to generate PDF from HTML RRS feed

  • Question

  •  

    Hi,

     

    I want to convert a html output into a PDF file using C#.

     

    Is there any native .NET library/components available?

     

    As I searched, noticed every one is going for 3rd party components.

     

    Thanks in advance.

    Thursday, June 7, 2007 6:11 AM

Answers

All replies

  • The Adobe Acrobat SDK doesn't provide a method to Create PDF from HTML .

    There are numerous third party tools available .

    One such example is  "iTextSharp" , its a free .NET API for PDF Related operations. It has a

    iTextSharp.text.html.HtmlParser class for Parsing and converting the html to PDF .

     

     

    Regards.
    Thursday, June 7, 2007 12:31 PM
  • Here are several solutions.

     

    1.Generate PDF documents from a HTML page using ASP.NET

     

    2.Pdfizer, a dumb HTML to PDF converter, in C#

     

    3.Recommend ExpertPDF. This is a commercial library that converts any web page to PDF.

      It's pure .NET and produces straight PDF from Html.

      You can see live demo using the online free html to pdf converter.

      For detail see this thread and this thread.

     

      Hope that helps!

    Monday, June 11, 2007 6:22 PM
  • Folks, Thank you for your responses... Your inputs were all really useful...

    Friday, June 15, 2007 6:08 AM
  • Hi Karthik

     

    I'm using PDFSharp in my project which I found very useful for working with PDFs. It's fully .NET managed code, plus it's free! There is also a project called MigraDocLite which might be what you need:

    www.pdfsharp.com

    Friday, June 15, 2007 9:47 AM
  • Hi Neal,

     

    Thank you...

    Can you provide me links where I can get more sample codes using pdfsharp component.

    I need to convert my html strings into pdf report.

     

    Thanks,

    Karthik J

     

     

     

     

    Monday, June 18, 2007 10:55 AM
  • Hi,

    The HTML to PDF library for .NET  from http://www.dotnet-reporting.com or the HTML to PDF converter from http://www.winnovative-software.com is what you need. It's pure .NET library, it doesn't use a printer driver. There is also a free html to pdf converter application built on top of this library. The conversion can be done with only a few lines of code:

     

    PdfConverter pdfConverter = new PdfConverter();
    pdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4;
    pdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Portrait;
    pdfConverter.PdfDocumentOptions.PdfCompressionLevel = PdfCompressionLevel.Normal;
    pdfConverter.PdfDocumentOptions.GenerateSelectablePdf = true;
    pdfConverter.PdfDocumentOptions.ShowFooter = false;
    pdfConverter.PdfDocumentOptions.ShowHeader = false;
    pdfConverter.LicenseFilePath = Server.MapPath(@"~/Bin");
    byte[] downloadBytes = pdfConverter.GetPdfFromUrlBytes(MyURL);  

     

    Regards,

    Florin

    Sunday, July 8, 2007 4:52 PM
  • Hi Karthik,

    I am also looking for some solution for converting html to pdf.
    Did you get something working for you?

    Your reply will be of great help to me.

    Thanks and Regards,
    Harish
    Wednesday, June 3, 2009 6:51 AM
  • Hi , 

    Is Winnovative library supports filling form field after conversion , i try to do it but it i can't


    Regards

    Serdar

    Thursday, August 13, 2009 2:37 PM
  • You may want to take a look at PDFTron PDFNet SDK (http://www.pdftron.com/pdfnet). Among many other options there is HTML2PDF option which is using WebKit rendering engine to convert HTML to PDF  (in .NET, Java, C++, etc).

    The library has many options, however the basic conversion is as simple as:

    using (PDFDoc doc = new PDFDoc()) {
      if ( HTML2PDF.Convert(doc, host + page0))
           doc.Save(output_path + "_01.pdf", SDFDoc.SaveOptions.e_linearized);
     }

    As a starting point check out HTML2PDF sample: http://www.pdftron.com/pdfnet/samplecode.html#HTML2PDF

     

     

    Monday, February 7, 2011 11:23 PM
  • EVO html to pdf converter can convert HTML 5 and CSS 3 to PDF
    Wednesday, February 9, 2011 3:05 PM
  • How is this possible to convert HTML to PDF (the subject of this thread, if you can't read) ? The official FAQ say it's NOT possible !
    Monday, December 10, 2012 1:37 PM
  • itextsharp only do ugly result and is very difficult to use. No complete documentation, especially on how to convert a rich html doc (with scripts and pictures) to pdf.
    Monday, December 10, 2012 1:38 PM
  • If you're creating a commercial project you may want to look at Elerium HTML to PDF .NET component. I hope this example will help you:

    http://eleriumsoft.com/PDF_NET/HTML2PDF/Examples/ex1.aspx

    http://eleriumsoft.com/PDF_NET/HTML2PDF/Examples/Create_PDF_using_HTML_string.aspx

    http://eleriumsoft.com/PDF_NET/HTML2PDF/Examples/Right_converting_HTML_with_Images_to_PDF.aspx

    Disclaimer: I'm a developer at Elerium Software.

    Wednesday, April 10, 2013 4:47 AM
  • Hi, yes unfortunately there is no native .NET library for this task there are solutions for it and I disagree with McFerson, iTextSharp is not difficult to use and they offer in my opinion a nice documentation. Here is is how to convert HTML to PDF with it:

    // Creation a new document.
    Document document = new Document(PageSize.A4, 80, 50, 30, 65);
                
    // Create a writer that listens to the document and directs a XML-stream to a file.
    PdfWriter.getInstance(document, new FileStream("Sample.pdf", FileMode.Create));
            
    // Parse the HTML file.
    HtmlParser.parse(document, "Sample.html");

    For a really simple and straightforward approach you can also try this C# Word component. Here is how to convert HTML to PDF in C# with it:

    // Convert HTML to PDF.
    DocumentModel.Load("Sample.html").Save("Sample.pdf");

    • Edited by Szervc Thursday, August 22, 2013 6:48 AM Added a simplier alternative
    Thursday, August 22, 2013 6:47 AM
  • Try:   https://www.articlage.com/adrianillo/article/htmltopdf

    It´s MIT License. 

    Transform basic html and css, but  html5 and css3  remains to be completed.

    You can add code for completing librery, the code is: https://github.com/adrianillo/HtmlToPdf

    Thursday, February 6, 2014 8:04 PM
  • Try Expert PDF's pdf library for C#. Check it here: http://www.html-to-pdf.net/html-to-pdf-csharp.aspx. They have also given a sample code there.
    Monday, April 14, 2014 10:38 AM
  • Hi Guys,
              we can refer this link so we can easily convert our html page contents into pdf in byte[] form.

    go through this link:
    http://www.nrecosite.com/pdf_generator_net.aspx


    Wednesday, February 18, 2015 7:29 PM
  • Select.Pdf offers a Community Edition (FREE) of the powerful Html To Pdf Converter for .NET that can be found in the full featured pdf library Select.Pdf for .NET. The free html to pdf converter offers most of the features the professional sdk offers, the only notable limitation is that it can only generate pdf documents up to 5 pages long.

    More details about the free html to pdf converter for .net:

    http://selectpdf.com/community-edition/

    SelectPdf Html To Pdf Converter for .NET is very easy to use. Here is a sample piece of code:

    // instantiate the html to pdf converter
    HtmlToPdf converter = new HtmlToPdf();
    
    // convert the url to pdf
    PdfDocument doc = converter.ConvertUrl(url);
    
    // save pdf document
    doc.Save(file);
    
    // close pdf document
    doc.Close();

    Wednesday, February 25, 2015 2:00 PM
  • I guess there aren't any native components, since everyone seems to be recommending their favorite third-party stuff. So I'll just join the fun and recommend mine, you can use GemBox.Document to convert HTML to PDF

    It's as simple as: 

    DocumentModel.Load("Document.html").Save("Document.pdf");
    Thursday, December 10, 2015 11:56 AM
  • As per my knowledge, there is not such Library is provided by .net to convert HTML to PDF but there are several 3 party dot net libraries to do this job. Some of them are free as under GNU General Public licensebut not for commercial use for that you need to get a license which is not for free. Some of the best libraries for C# are...

    1. itextsharp.
    2. pdfsharp.
    3. pdfclown.
    4. wkhtmltopdf.

    If pricing is not a concern and you are willing to spend enough then I would like to recommend you, Prince, as it is best among all of them surely the price is high but it's worth.



    Friday, September 22, 2017 10:57 AM
  • For html to pdf conversion on C# I used easyPDF SDK solution and insert just a few lines of code. Cannot tell you it is the best tool in the market but works good to me. But you may check it out, it has a free trial.
    Wednesday, October 25, 2017 5:14 PM
  • As the majority says, you'd have to use third party library for it. As for what I am using and you can try as well, it is https://zetpdf.com/. It is a great tool.
    Thursday, April 12, 2018 4:12 AM
  • You can try using this ZetPDF.com platform  that  has a fastest pdf sdk for .net applications.

    Tuesday, July 3, 2018 12:26 PM
  • To get a really good HTML to PDF conversion you need to use a browser to properly parse the CSS, JavaScript and images into the PDF. That is why I would unfortunately recommend a third party provider such as GrabzIt's HTML to PDF .NET library https://grabz.it/html-to-pdf-image-api.aspx, to get a decent conversion.
    Wednesday, April 10, 2019 4:30 PM