EDIT (2024) : new method related to webview and Edge https://weblog.west-wind.com/posts/2024/Mar/26/Html-to-PDF-Generation-using-the-WebView2-Control

This will need Windows OS.

I have tested with ASP.net Core application and I used .net8.0-windows as target framework in order to use this nuget I also installed webview runtime

Also creator indicated windows desktop runtime as dependency too.

Install the nuget.

/// <summary>
/// Return raw data as PDF
/// </summary>
/// <returns></returns>
[HttpGet("rawpdfex")]
public async Task<IActionResult> RawPdf()
{
    var file = Path.GetFullPath("./HtmlSampleFile-SelfContained.html");

    var pdf = new HtmlToPdfHost();
    var pdfResult = await pdf.PrintToPdfStreamAsync(file, new 
        WebViewPrintSettings { PageRanges = "1-10" });

    if (pdfResult == null || !pdfResult.IsSuccess)
    {
        Response.StatusCode = 500;                
        return new JsonResult(new
        {
            isError = true,
            message = pdfResult.Message
        });
    }

    return new FileStreamResult(pdfResult.ResultStream, "application/pdf");             
}

EDIT: New Suggestion HTML Renderer for PDF using PdfSharp

(After trying wkhtmltopdf and suggesting to avoid it)

HtmlRenderer.PdfSharp is a 100% fully C# managed code, easy to use, thread safe and most importantly FREE (New BSD License) solution.

Usage

  1. Download HtmlRenderer.PdfSharp nuget package.

  2. Use Example Method.

    public static Byte[] PdfSharpConvert(String html)
    {
        Byte[] res = null;
        using (MemoryStream ms = new MemoryStream())
        {
            var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);
            pdf.Save(ms);
            res = ms.ToArray();
        }
        return res;
    }
    

A very Good Alternate Is a Free Version of iTextSharp

Until version 4.1.6 iTextSharp was licensed under the LGPL licence and versions until 4.16 (or there may be also forks) are available as packages and can be freely used. Of course someone can use the continued 5+ paid version.

I tried to integrate wkhtmltopdf solutions on my project and had a bunch of hurdles.

I personally would avoid using wkhtmltopdf - based solutions on Hosted Enterprise applications for the following reasons.

  1. First of all wkhtmltopdf is C++ implemented not C#, and you will experience various problems embedding it within your C# code, especially while switching between 32bit and 64bit builds of your project. Had to try several workarounds including conditional project building etc. etc. just to avoid "invalid format exceptions" on different machines.
  2. If you manage your own virtual machine its ok. But if your project is running within a constrained environment like (Azure (Actually is impossible withing azure as mentioned by the TuesPenchin author) , Elastic Beanstalk etc) it's a nightmare to configure that environment only for wkhtmltopdf to work.
  3. wkhtmltopdf is creating files within your server so you have to manage user permissions and grant "write" access to where wkhtmltopdf is running.
  4. Wkhtmltopdf is running as a standalone application, so its not managed by your IIS application pool. So you have to either host it as a service on another machine or you will experience processing spikes and memory consumption within your production server.
  5. It uses temp files to generate the pdf, and in cases Like AWS EC2 which has really slow disk i/o it is a big performance problem.
  6. The most hated "Unable to load DLL 'wkhtmltox.dll'" error reported by many users.

--- PRE Edit Section ---

For anyone who want to generate pdf from html in simpler applications / environments I leave my old post as suggestion.

TuesPechkin

https://www.nuget.org/packages/TuesPechkin/

or Especially For MVC Web Applications (But I think you may use it in any .net application)

Rotativa

https://www.nuget.org/packages/Rotativa/

They both utilize the wkhtmtopdf binary for converting html to pdf. Which uses the webkit engine for rendering the pages so it can also parse css style sheets.

They provide easy to use seamless integration with C#.

Rotativa can also generate directly PDFs from any Razor View.

Additionally for real world web applications they also manage thread safety etc...

Answer from Anestis Kivranoglou on Stack Overflow
๐ŸŒ
APITemplate.io
apitemplate.io โ€บ home โ€บ convert html to pdf in c# using 5 popular libraries (updated 2024)
Convert HTML to PDF in C# using 5 Popular Libraries (Updated 2024) - APITemplate.io
December 29, 2024 - HtmlRenderer.PdfSharp is a C# library used to generate PDFs. This library enables the creation of PDF documents from HTML snippets using static rendering code.
Top answer
1 of 16
290

EDIT (2024) : new method related to webview and Edge https://weblog.west-wind.com/posts/2024/Mar/26/Html-to-PDF-Generation-using-the-WebView2-Control

This will need Windows OS.

I have tested with ASP.net Core application and I used .net8.0-windows as target framework in order to use this nuget I also installed webview runtime

Also creator indicated windows desktop runtime as dependency too.

Install the nuget.

/// <summary>
/// Return raw data as PDF
/// </summary>
/// <returns></returns>
[HttpGet("rawpdfex")]
public async Task<IActionResult> RawPdf()
{
    var file = Path.GetFullPath("./HtmlSampleFile-SelfContained.html");

    var pdf = new HtmlToPdfHost();
    var pdfResult = await pdf.PrintToPdfStreamAsync(file, new 
        WebViewPrintSettings { PageRanges = "1-10" });

    if (pdfResult == null || !pdfResult.IsSuccess)
    {
        Response.StatusCode = 500;                
        return new JsonResult(new
        {
            isError = true,
            message = pdfResult.Message
        });
    }

    return new FileStreamResult(pdfResult.ResultStream, "application/pdf");             
}

EDIT: New Suggestion HTML Renderer for PDF using PdfSharp

(After trying wkhtmltopdf and suggesting to avoid it)

HtmlRenderer.PdfSharp is a 100% fully C# managed code, easy to use, thread safe and most importantly FREE (New BSD License) solution.

Usage

  1. Download HtmlRenderer.PdfSharp nuget package.

  2. Use Example Method.

    public static Byte[] PdfSharpConvert(String html)
    {
        Byte[] res = null;
        using (MemoryStream ms = new MemoryStream())
        {
            var pdf = TheArtOfDev.HtmlRenderer.PdfSharp.PdfGenerator.GeneratePdf(html, PdfSharp.PageSize.A4);
            pdf.Save(ms);
            res = ms.ToArray();
        }
        return res;
    }
    

A very Good Alternate Is a Free Version of iTextSharp

Until version 4.1.6 iTextSharp was licensed under the LGPL licence and versions until 4.16 (or there may be also forks) are available as packages and can be freely used. Of course someone can use the continued 5+ paid version.

I tried to integrate wkhtmltopdf solutions on my project and had a bunch of hurdles.

I personally would avoid using wkhtmltopdf - based solutions on Hosted Enterprise applications for the following reasons.

  1. First of all wkhtmltopdf is C++ implemented not C#, and you will experience various problems embedding it within your C# code, especially while switching between 32bit and 64bit builds of your project. Had to try several workarounds including conditional project building etc. etc. just to avoid "invalid format exceptions" on different machines.
  2. If you manage your own virtual machine its ok. But if your project is running within a constrained environment like (Azure (Actually is impossible withing azure as mentioned by the TuesPenchin author) , Elastic Beanstalk etc) it's a nightmare to configure that environment only for wkhtmltopdf to work.
  3. wkhtmltopdf is creating files within your server so you have to manage user permissions and grant "write" access to where wkhtmltopdf is running.
  4. Wkhtmltopdf is running as a standalone application, so its not managed by your IIS application pool. So you have to either host it as a service on another machine or you will experience processing spikes and memory consumption within your production server.
  5. It uses temp files to generate the pdf, and in cases Like AWS EC2 which has really slow disk i/o it is a big performance problem.
  6. The most hated "Unable to load DLL 'wkhtmltox.dll'" error reported by many users.

--- PRE Edit Section ---

For anyone who want to generate pdf from html in simpler applications / environments I leave my old post as suggestion.

TuesPechkin

https://www.nuget.org/packages/TuesPechkin/

or Especially For MVC Web Applications (But I think you may use it in any .net application)

Rotativa

https://www.nuget.org/packages/Rotativa/

They both utilize the wkhtmtopdf binary for converting html to pdf. Which uses the webkit engine for rendering the pages so it can also parse css style sheets.

They provide easy to use seamless integration with C#.

Rotativa can also generate directly PDFs from any Razor View.

Additionally for real world web applications they also manage thread safety etc...

2 of 16
131

Last Updated: October 2020

This is the list of options for HTML to PDF conversion in .NET that I have put together (some free some paid)

  • GemBox.Document

    • https://www.nuget.org/packages/GemBox.Document/
    • Free (up to 20 paragraphs)
    • $680 - https://www.gemboxsoftware.com/document/pricelist
    • https://www.gemboxsoftware.com/document/examples/c-sharp-convert-html-to-pdf/307
  • PDF Metamorphosis .Net

    • https://www.nuget.org/packages/sautinsoft.pdfmetamorphosis/
    • 1078 - https://www.sautinsoft.com/products/pdf-metamorphosis/order.php
    • https://www.sautinsoft.com/products/pdf-metamorphosis/convert-html-to-pdf-dotnet-csharp.php
  • HtmlRenderer.PdfSharp

    • https://www.nuget.org/packages/HtmlRenderer.PdfSharp/1.5.1-beta1
    • BSD-UNSPECIFIED License
  • PuppeteerSharp

    • https://www.puppeteersharp.com/examples/index.html
    • MIT License
    • https://github.com/kblok/puppeteer-sharp
  • EO.Pdf

    • https://www.nuget.org/packages/EO.Pdf/
    • $799 - https://www.essentialobjects.com/Purchase.aspx?f=3
  • WnvHtmlToPdf_x64

    • https://www.nuget.org/packages/WnvHtmlToPdf_x64/
    • 1600 - http://www.winnovative-software.com/Buy.aspx
    • demo - http://www.winnovative-software.com/demo/default.aspx
  • IronPdf

    • https://www.nuget.org/packages/IronPdf/
    • 1599 - https://ironpdf.com/licensing/
    • https://ironpdf.com/examples/using-html-to-create-a-pdf/
  • Spire.PDF

    • https://www.nuget.org/packages/Spire.PDF/
    • Free (up to 10 pages)
    • 1799 - https://www.e-iceblue.com/Buy/Spire.PDF.html
    • https://www.e-iceblue.com/Tutorials/Spire.PDF/Spire.PDF-Program-Guide/Convert-HTML-to-PDF-Customize-HTML-to-PDF-Conversion-by-Yourself.html
  • Aspose.Html

    • https://www.nuget.org/packages/Aspose.Html/
    • 1797 - https://purchase.aspose.com/pricing/html/net
    • https://docs.aspose.com/html/net/html-to-pdf-conversion/
  • EvoPDF

    • https://www.nuget.org/packages/EvoPDF/
    • 1200 - http://www.evopdf.com/buy.aspx
  • ExpertPdfHtmlToPdf

    • https://www.nuget.org/packages/ExpertPdfHtmlToPdf/
    • 1200 - https://www.html-to-pdf.net/Pricing.aspx
  • Zetpdf

    • https://zetpdf.com
    • 599 - https://zetpdf.com/pricing/
    • Is not a well know or supported library - ZetPDF - Does anyone know the background of this Product?
  • PDFtron

    • https://www.pdftron.com/documentation/samples/cs/HTML2PDFTes
    • $4000/year - https://www.pdftron.com/licensing/
  • WkHtmlToXSharp

    • https://github.com/pruiz/WkHtmlToXSharp
    • Free
    • Concurrent conversion is implemented as processing queue.
  • SelectPDF

    • https://www.nuget.org/packages/Select.HtmlToPdf/
    • Free (up to 5 pages)
    • 799 - https://selectpdf.com/pricing/
    • https://selectpdf.com/pdf-library-for-net/

If none of the options above help you you can always search the NuGet packages:
https://www.nuget.org/packages?q=html+pdf

๐ŸŒ
Adobe
adobe.com โ€บ acrobat โ€บ resources โ€บ how-to-convert-html-to-pdf.html
How to convert HTML to PDF | Adobe Acrobat
You can convert linked or unlinked web pages to new PDFs or append them to existing PDF documents. You have the option to include an entire website with the HTML code or just particular levels of the website. A level describes where a page is located in a websiteโ€™s hierarchy. Think of each click you make deeper into a site away from the main URL as a level.
๐ŸŒ
PDFreactor
pdfreactor.com โ€บ home โ€บ html to pdf via c#: convert html to pdf using c# & .net
HTML to PDF via C#: Convert HTML to PDF using C# & .NET
January 11, 2021 - Using C# to generate a PDF from HTML is not always an easy task. PDFreactor is the easy, fast and modern converter engine for C# users to create PDF from HTML efficiently. Benefit from our PDF library and powerful API to transform html to pdf using .Net core.
๐ŸŒ
GitHub
github.com โ€บ gnudles โ€บ wkgtkprinter
GitHub - gnudles/wkgtkprinter: HTML to PDF converter (C Library) using WebkitGtk (similar to wkhtmltopdf, but without the Qt part)
#include "wkgtkprinter.h" int main() { // start the main loop thread wkgtkprinter_gtk_mainloop_start_thread(); ... //from a thread, call to... wkgtkprinter_html2pdf(NULL, "<div style=\"background: #ff007e;overflow: hidden;\">HELLO WORLD!<br/>by wkgtkprinter</div>", NULL, "file://hello.pdf", print_settings, NULL); ...
Starred by 25 users
Forked by 5 users
Languages ย  C 97.1% | Makefile 2.9%
๐ŸŒ
Pdfnoodle
pdfnoodle.com โ€บ blog โ€บ how-to-generate-pdf-from-html-using-pdfsharp-in-c-sharp
How to Generate PDF from HTML Using PdfSharp in C# (Updated 2025)
February 3, 2025 - Elevate your SaaS app by generating PDFs from HTML with PdfSharp in .NET. Create professional documents easily using this lightweight C# PDF library.
๐ŸŒ
PDFCrowd
pdfcrowd.com โ€บ blog โ€บ convert-html-to-pdf-in-c
Convert HTML to PDF in C - PDFCrowd
In this article, we will show how to convert a webpage or an HTML document to PDF in C using the Pdfcrowd API. We will show the convert() function that provides the conversion functionality. We will demonstrate how to use it to create PDF from various input sources, such as a URL, a local HTML ...
๐ŸŒ
Sejda PDF
sejda.com โ€บ html-to-pdf
Convert HTML to PDF Online
HTML to PDF. Convert HTML pages to a PDF document. Online, no installation or registration required. It's free, quick and easy to use.
Find elsewhere
๐ŸŒ
Prince
princexml.com
Prince - Convert HTML to PDF with CSS
Convert HTML documents to PDF. Beautiful printing with CSS. Support for JavaScript and SVG.
๐ŸŒ
Pdfnoodle
pdfnoodle.com โ€บ blog โ€บ how-to-generate-pdf-from-html-with-playwright-in-c-sharp
How to Generate PDF from HTML with Playwright using C# (Updated 2025)
August 6, 2025 - Generate PDFs from HTML using Playwright in C#. Leverage its powerful features in .NET to automate PDF creation and streamline your product workflows.
๐ŸŒ
Reddit
reddit.com โ€บ r/webdev โ€บ what is the fastest way to convert html to pdf programatically (or pdf generation)?
r/webdev on Reddit: What is the fastest way to convert HTML to PDF programatically (or PDF generation)?
November 8, 2024 -

Some Pretext:

  • HTML to PDF conversion is as it sounds, converting HTML to PDF.

  • By PDF generation I mean to generate a PDF without that conversion thing.

Context:

In my company, we allow users to export there data in the form of PDFs where there is user data and images. Now this process is slow for users that have a lot of data (I have seen exports running for 2-3 hrs for some 100 page PDF).

There might be multiple reasons to this which I suspect are (DB is not the issue here):

  • Fetching user images from S3 takes time.

  • We first generate the HTML from user data and then use pupeteer to convert that html to PDF.

    • Sometimes, an admin can request data for multiple users, which means this whole conversion and generation thing will run for each user.

    • The pupeteer code is written with asyncio (Python) which uses async await paradigm. But we still wait for the task to complete.

We have to use pupeteer because currently we have some custom templates, css and fontfaces for the template of PDF.

While looking for solutions I came across a reddit post https://www.reddit.com/r/webdev/comments/18zm20r/html_to_pdf_with_performances/ where user had similar issue. I tested wkhtmltopdf and its styling was little bit off as compared to pupeteer.

Since we are already using headless chromium here (which according to the post is fastes), is there anything else that can speed this up? In the above post, one user mentioned some "layout engine on top of a 2D graphics API" which I guess is a layout engine on top of something like OpenGL (only one I've used so no idea). I am not sure I'll be able to develop a whole layout thing since my CPP is rusty. Anything else that I can do to improve performance?

๐ŸŒ
iLovePDF
ilovepdf.com โ€บ html-to-pdf
HTML to PDF converter. Transform HTML pages into PDF
Convert HTML pages to PDF documents for free with our HTML to PDF converter. Transform any web page to a PDF document. Easy, fast and without registration.
๐ŸŒ
HackerNoon
hackernoon.com โ€บ c-html-to-pdf-a-code-example
C# HTML to PDF - A Code Example | HackerNoon
April 15, 2022 - IronPDF is the ideal solution for converting HTML sites in .NET and .NET core projects. It not only transforms HTML but also has a lot of other useful capabili
๐ŸŒ
SelectPDF
selectpdf.com
Free HTML to PDF Converter ASP NET MVC | HTML to PDF API Online | PDF SDK
Create high quality PDFs with SelectPdf Html To Pdf Converter from the best PDF library. HTML to PDF API also available.
๐ŸŒ
GemBox
gemboxsoftware.com โ€บ document โ€บ examples โ€บ html-to-pdf-converter-csharp โ€บ 6001
How to convert Html to Pdf in C#: A complete guide
This is because default HtmlLoadOptions use print type media rule (@media print { โ€ฆ }) as the default style. Most pages have this style defined for printing purposes. You can check this by opening a print preview in the browser and comparing it to the original page. For the page used in the code above, the print preview looks like this: Screenshot of a print preview window in a Pdf file generated from an URL
๐ŸŒ
Syncfusion
syncfusion.com โ€บ blogs โ€บ post โ€บ generate-dynamic-pdf-reports-from-html-template-using-csharp
Generate Dynamic PDF Reports from an HTML Template Using C# | Syncfusion Blogs
September 27, 2022 - This blog explains the procedure to generate a PDF document from an HTML template using the Syncfusion C# HTML-to-PDF converter.
๐ŸŒ
IronPDF
ironpdf.com โ€บ examples โ€บ using-html-to-create-a-pdf
Code Example: Convert HTML to PDF in C# | IronPDF for .NET 10
September 1, 2025 - With IronPDF, you can create new PDF documents from simple HTML strings within your .NET project, and IronPDF is able to be used in C#, F#, and VB.NET. Thanks to the use of the ChromePdfRenderer class, you can be sure that any PDF documents ...
๐ŸŒ
HTML2PDF
html2pdf.com
HTML to PDF โ€“ Convert HTML files to PDF
The first thing you need to do is decide how youโ€™ll want your HTML rendered. There are four options on the page: Grayscale, Landscape, No Background, and No JavaScript. Ticking the Grayscale box will render your page without color; Landscape creates PDF pages in landscape mode rather than portrait; No Background will render the page with a simple white background; No JavaScript will remove all JavaScript from the page.