Open Source HTML to PDF Renderer with Full CSS Support

117,933

Solution 1

I've always used it on the command line and not as a library, but HTMLDOC gives me excellent results, and it handles at least some CSS (I couldn't easily see how much).

Here's a sample command line

htmldoc --webpage -t pdf --size letter --fontsize 10pt index.html > index.pdf

Solution 2

This command line tool is the business! https://wkhtmltopdf.org/

It uses webkit rendering engine(used in safari and KDE), I tested it on some complex sites and it was by far better than any other tool.

Solution 3

Do you see :

They look as PrinceXML

Share:
117,933
Miguel Ventura
Author by

Miguel Ventura

Updated on May 14, 2020

Comments

  • Miguel Ventura
    Miguel Ventura almost 4 years

    I asked about getting iTextSharp to render a PDF from HTML and a CSS sheet before here but it seems like that may not be possible... So I guess I will have to try something else.

    Is there an open source .NET/C# library out there that can take HTML and CSS as input and render it correctly?

    I must reiterate... the library MUST be free and preferably something with a fairly liberal license. I'm working with basically no budget here.

  • Levitikon
    Levitikon over 12 years
    Yeah, and they put their logo on the output
  • Levitikon
    Levitikon over 12 years
    Doesn't look like the standard edition is free anymore, "Licenses for ABCpdf .NET from only $329."
  • AffineMesh
    AffineMesh over 12 years
    The free license is offered through a promotional scheme. If it disappears, try googling for 'websupergoo free licenses'. Note the offer is for single license only. If you need to purchase a license or additional licenses, the price is as Levitikon has said.
  • Bilal lilla
    Bilal lilla about 12 years
    will you please explain how to use that library. any code in either C# / VB.net
  • Norman Ramsey
    Norman Ramsey about 12 years
    @Bilal, as it says in my answer, I've always used it on the command line and not as a library.
  • Bilal lilla
    Bilal lilla about 12 years
    just write that line that you use for conversion from html to pdf.
  • Gman
    Gman almost 12 years
    In fact, it also has library version and I've implemented .NET wrapper for it github.com/gmanny/Pechkin (also on NuGet).
  • Volatil3
    Volatil3 about 11 years
    @NormanRamsey does it support RTL language based Custom TTF fonts by using @fontface?
  • PeterX
    PeterX almost 11 years
    Yes, @AffineMesh could you please revise your text above saying the "standard edition can be obtained free of charge". Or simply add an extra note. Incidentally, I find their license somewhat confusing: "The Owner offers you a non-exclusive, non-transferable license on the terms of this Agreement". What does this mean - do I still have to get one?
  • Dilhan Jayathilake
    Dilhan Jayathilake almost 10 years
    I tried the NuGet and it is great. Works perfectly.
  • Sean Chase
    Sean Chase over 9 years
    Outstanding! I tried this vs iTextSharp and AsposePDF. Aspose rendered horribly for me and iTextSharp just kept throwing exception after exception. wkhtmltopdf worked on the first try and rendered everything perfectly.
  • Norman Ramsey
    Norman Ramsey almost 9 years
    @mauvm fixed the link
  • Al Belmondo
    Al Belmondo almost 9 years
    Does this bring in styling and images?
  • Peter Wone
    Peter Wone almost 9 years
    @AlBelmondo - it definitely honours CSS defined in a header <style> block. There is a setting web.loadImages that takes a true/false value but I haven't managed to get images to load yet.
  • VFein
    VFein over 8 years
    The tuesPechkin library for wkhtmltopdf is great and thread safe, however, cannot process conversions concurrently -- which is my current problem.
  • Guru Stron
    Guru Stron over 8 years
    Also Rotativa is using wkhtmltopdf under the hood too, if i understand correctly.
  • Christian Neverdal
    Christian Neverdal almost 8 years
    This answer should be deleted. The asker is clearly asking for an open source renderer.
  • Charlie Martin
    Charlie Martin almost 8 years
    Yes dear, let's start fretting about seven-year-old answers to closed questions.
  • Charlie Martin
    Charlie Martin about 6 years
    Good, let's fret about TEN YEAR OLD questions now.
  • Stephanie
    Stephanie about 6 years
    Our IronPDF Library builds upon the great work done in wkhtmltopdf. CSS is fully supported. IronPDF.com makes the process of adding PDF functions to a project quick and easily.
  • Will Marcouiller
    Will Marcouiller about 5 years
    Broken Link, again. :\