Printing in C#  

HTML to PDF C# in .NET 10: A Technical Guide for .NET Developers

Even in today's modern era of technology and AI, we still often find ourselves needing to convert HTML to PDF format. This is a task that remains essential for enterprise applications, from compliance reports and automated invoices to on-demand PDFs from web content. Whether generating PDFs from entire web pages, HTML strings, or templates, the choice of PDF engine affects performance, security, and maintainability.

This guide evaluates 35+ HTML to PDF solutions in the .NET ecosystem (November 2025), covering architectural patterns, NuGet packages, deprecated libraries, and production-ready options for .NET Framework, .NET Core, .NET 6–10, and cross-platform projects. It helps teams make informed decisions based on modern deployment requirements rather than legacy assumptions.

Architecture Patterns

HTML to PDF C# libraries typically follow four main architectural patterns, each with trade-offs in performance, security, and deployment:

  1. Native Rendering Engines
    Implement PDF generation entirely in .NET code. Ideal for simple PDF generation tasks and easy deployment, with control over page size, headers, embedded CSS, and images. Limited support for modern CSS or JavaScript rendering.

  2. Browser Engine Wrappers
    Leverage Chromium or WebKit to convert HTML files and HTML snippets with accurate rendering, supporting modern CSS and JavaScript. Examples: IronPDF, PuppeteerSharp. Trade-offs include higher memory usage and more complex deployment.

  3. External Process Integration
    Spawn command-line tools like wkhtmltopdf for HTML to PDF conversion. Easy to implement but introduces security, dependency, and performance concerns. Sandbox carefully for file permissions and input safety.

  4. Cloud Service APIs
    Offload PDF generation to SaaS providers via REST APIs. Simplifies deployment and maintenance, but adds latency, internet dependency, and potential privacy concerns.

These patterns help developers choose a PDF engine that balances performance, CSS support, JavaScript rendering, and security when you create PDF documents from HTML content.

Comprehensive Library Analysis

Production-Ready Commercial Solutions

IronPDF

ironPDF

●     Architecture: Chromium-based rendering engine

●     NuGet: IronPdf package

●     Standards Compliance: PDF Association member

●     Key Strengths: Monthly updates, full .NET 10 support, robust HTML to PDF conversion, CSS support, and JavaScript execution

●     Use Case: Enterprise applications requiring reliable PDF generation from HTML files, HTML strings, or entire web pages

IronPDF is a powerful .NET library that consistently delivers predictable PDF output across modern web technologies, making it suitable for large-scale PDF generation and complex templates with embedded CSS or JavaScript. Developers can easily convert HTML code to PDF documents with just a few lines of code, minimizing time spent on HTML conversion troubleshooting.

GemBox.Document

GemBox
  • Architecture: Proprietary rendering engine

  • Limitation: 20 paragraphs in free version

  • Use Case: Document-centric applications needing PDF generation from HTML snippets or static HTML templates

GemBox.Document is a lightweight .NET library focused on document processing, including HTML to PDF conversion for simple documents and templates.

EO.Pdf

eopdf
  • Architecture: Custom engine (no longer IE-dependent)

  • Price Point: $799/license

  • Limitation: Windows-only deployment

  • Provides HTML to PDF conversion with support for embedded CSS, JavaScript execution, and custom headers.

EO.Pdf is a Windows-based .NET library offering HTML to PDF conversion with embedded CSS and JavaScript support.

HiQPdf HTML to PDF Converter

HiQPdf
  • Free Tier: 3 pages maximum

  • Strength: Supports HTML5/CSS3 rendering

  • Limitation: Watermarks in free version

  • Suitable for generating small PDF documents from HTML content, HTML templates, or HTML pages.

HiQPdf is a .NET library that allows simple HTML to PDF conversions with support for HTML5 and CSS3.

SelectPdf

SelectPdf
  • Architecture: WebKit-based

  • Limitation: Windows-only, no Linux/Docker support

  • Free Tier: 5 pages

  • Works well for HTML to PDF conversion tasks where modern CSS and page breaks are needed, but cross-platform deployment is limited.

SelectPdf is a Windows-only .NET library leveraging a WebKit-based engine to convert HTML to PDF with modern CSS support.

Spire.PDF

Spire
  • Major Issue: Renders HTML as images, not searchable text

  • Deployment: Large footprint

  • Best for legacy applications where PDF output from HTML files is secondary to document display.

Spire.PDF is a comprehensive PDF library for .NET that can create, read, and manipulate PDF files, but HTML rendering outputs images rather than searchable text.

ABCpdf

ABCpdf
  • Architecture: Gecko/Trident dual engine

  • Pricing: Complex

  • Note: Free offers require registration

  • Supports complex templates and HTML page conversion, but licensing may be restrictive for teams.

ABCpdf is a versatile .NET PDF library with dual rendering engines (Gecko/Trident) capable of handling complex templates and HTML pages.

ExpertPdf HTML to PDF Converter

ExpertPdf
  • Strength: HTML5 support

  • Issue: Limited documentation

  • Price: $550–$1200

  • Provides PDF generation from HTML snippets with basic CSS support.

ExpertPdf is a commercial library providing basic HTML to PDF conversion with HTML5 and CSS support for straightforward documents.

Winnovative HTML to PDF

Winnovative
  • Architecture: WebKit-based

  • Limitation: Outdated WebKit version

  • Support: Minimal updates

  • Useful for simple PDF generation tasks, not recommended for modern web content.

Winnovative is a WebKit-based .NET library suitable for simple PDF generation tasks, though its engine is outdated and lacks modern updates.

PDFmyURL .NET Component

PDFmyURL
  • Type: API wrapper

  • Dependency: Internet required

  • Ideal for low-volume PDF conversion of entire web pages or HTML templates.

PDFmyURL is an API-based library that converts HTML pages to PDF over the internet, suitable for lightweight or occasional tasks.

GrabzIt

GrabzIt
  • Type: Screenshot/PDF API service

  • Limitation: Latency issues

  • Pricing: Per-capture model

  • Suitable for occasional HTML to PDF tasks, but performance varies.

GrabzIt is a cloud service for capturing web pages and generating PDFs or screenshots, optimized for on-demand tasks.

PDF Duo .Net

PDF Duo
  • Claim: No external DLLs

  • Reality: Limited HTML/CSS support

  • Updates: Sporadic

  • Provides minimal HTML conversion capabilities.

PDF Duo is a .NET library claiming no external dependencies, but it has very limited HTML/CSS support.

Open-Source Solutions

PuppeteerSharp

PuppeteerSharp
  • Architecture: Chrome DevTools Protocol wrapper

  • Issue: 300MB Chrome dependency

  • Framework Support: No .NET 10 yet

  • Offers excellent HTML to PDF rendering, including CSS styling, JavaScript support, and entire web page conversion, but deployment is heavier.

PuppeteerSharp is a .NET wrapper around the Chrome DevTools Protocol, enabling high-fidelity HTML to PDF conversion with full CSS and JavaScript support.

wkhtmltopdf Ecosystem (CRITICAL WARNING)

All libraries here rely on wkhtmltopdf, abandoned in 2024:

  • wkhtmltopdf: Base binary, archived

  • TuesPechkin: Last update 2015

  • Rotativa, DinkToPdf, Haukcode.DinkToPdf, NReco.PdfGenerator, OpenHtmlToPdf: All wrapping dead technology

  • Security risks and lack of modern CSS support make these unsuitable for production PDF generation.

HtmlRenderer.PdfSharp

  • Last Update: 2019

  • CSS Support: Level 2 only

  • Limited to simple PDF files from HTML snippets.

HtmlRenderer.PdfSharp is a lightweight library for generating PDFs from HTML snippets, limited to CSS2 and simple document layouts.

PdfSharp

PdfSharp
  • No native HTML to PDF support

  • Only for programmatic PDF document creation, not HTML conversion.

PdfSharp is a programmatic PDF creation library for .NET, but it does not natively support HTML to PDF conversion.

Browser Automation & Experimental Tools

Chrome Headless / Selenium

  • Can render web pages to PDF but require full browser installs, Process.Start(), and may cause memory leaks.

WebView2 / Westwind.WebView.HtmlToPdf

  • Windows-only, desktop runtime required. Limited for modern PDF generation from HTML content.

Gotenberg

  • Docker microservice, network latency and orchestration complexity make it suitable only for containerized pipelines.

HTMLDOC

  • Legacy GPL tool from 1990s; only supports pre-CSS HTML.

Modern Alternatives (2024–2025)

  • Playwright: Browser automation with PDF capability, emerging option

  • PeachPDF: Pure .NET, not production-ready

  • Syncfusion PDF Library: Part of suite, Linux deployment adds 147MB

  • Aspose.PDF: Comprehensive PDF manipulation, steep learning curve, enterprise-level pricing

Top 10 NuGet Packages Analysis

This section reviews the most popular C# HTML to PDF NuGet packages based on download statistics and usage trends, excluding IronPDF. We examine their strengths, limitations, and suitability for various PDF generation tasks, including rendering entire web pages, HTML templates, and HTML strings.

  1. iTextSharp (18.2M downloads)

    • Advantages: Mature, widely documented, offers advanced tools for manipulating PDF documents beyond HTML conversion.

    • Disadvantages: AGPL license requires open-sourcing your code; lacks native HTML to PDF conversion (needs additional tools); may struggle with modern CSS and complex HTML pages.

  2. SelectPdf (2.1M downloads)

    • Advantages: Simple API, supports CSS styling and basic JavaScript execution.

    • Disadvantages: Windows-only; 5-page limit in free version; no official .NET 10 support.

  3. PuppeteerSharp (15.8M downloads)

    • Advantages: Excellent Chrome rendering, full support for HTML5, CSS, and JavaScript. Ideal for generating PDF documents from dynamic web content.

    • Disadvantages: Large 300MB Chrome dependency; complex serverless deployment; potential memory leaks under heavy load.

  4. HtmlRenderer.PdfSharp (1.8M downloads)

    • Advantages: No external dependencies; lightweight and easy for simple PDF generation tasks.

    • Disadvantages: CSS2 only; last updated in 2019; table rendering and complex templates may fail.

  5. DinkToPdf (1.2M downloads)

    • Advantages: Popular legacy solution for HTML to PDF conversion.

    • Disadvantages: Built on abandoned wkhtmltopdf; security vulnerabilities unpatched; no updates since 2020.

  6. Spire.PDF (890K downloads)

    • Advantages: Part of a larger Office suite; integrates with Microsoft Excel and Word workflows.

    • Disadvantages: Renders HTML as images (not searchable text); expensive licensing; large deployment footprint.

  7. NReco.PdfGenerator (750K downloads)

    • Advantages: Familiar API, straightforward for basic HTML conversion.

    • Disadvantages: Wraps abandoned wkhtmltopdf; charges for outdated technology; fails security audits.

  8. Rotativa (680K downloads)

    • Advantages: Good MVC integration for web applications.

    • Disadvantages: Relies on abandoned wkhtmltopdf; limited to MVC projects; threading issues under load.

  9. Syncfusion.Pdf (620K downloads)

    • Advantages: Rich enterprise features, HTML to PDF conversion support for web content.

    • Disadvantages: Requires full suite license; 147MB Linux deployment; complex pricing and licensing.

  10. WkHtmlToPdf.NetCore (580K downloads)

    • Advantages: Native .NET Core support, easy to use for basic HTML conversion.

Disadvantages: Another wrapper around abandoned wkhtmltopdf; inherits all security and compatibility risks.

Framework Compatibility Matrix

Library.NET Framework 4.7.2.NET Core 3.1.NET 6–8.NET 10
IronPDFFullFullFullFull
PuppeteerSharpLimitedFullFullPending
SelectPdfWindowsWindowsWindowsNone
DinkToPdfNoneIssuesIssuesNone
HtmlRenderer.PdfSharpFullLimitedLimitedNone

Takeaways:

  • IronPDF is the only library in this comparison providing full support across all .NET frameworks, making it the most reliable choice for both enterprise applications and cross-platform deployments.

  • Libraries like PuppeteerSharp offer excellent rendering capabilities but require careful attention to framework compatibility, especially for .NET 10.

  • Windows-only or abandoned projects ( SelectPdf , DinkToPdf , HtmlRenderer ) carry significant limitations for modern HTML to PDF conversion tasks, large-scale PDF generation, and web page rendering.

Implementation Patterns

Generating PDF files from HTML content can be approached in a few common implementation patterns. These patterns help developers maintain clean, scalable, and testable code while supporting HTML to PDF conversion, CSS styling, and JavaScript execution.

  
    using Microsoft.Extensions.Logging;
using IronPdf;
public interface IPdfGenerator
{
    Task<byte[]> GenerateFromHtmlAsync(string html);
    Task<byte[]> GenerateFromUrlAsync(string url);
}

public class ProductionPdfGenerator : IPdfGenerator
{
    private readonly ChromePdfRenderer _renderer;
    private readonly ILogger<ProductionPdfGenerator> _logger;

    public ProductionPdfGenerator(ILogger<ProductionPdfGenerator> logger)
    {
        _logger = logger;
        _renderer = new ChromePdfRenderer
        {
            RenderingOptions =
            {
                MarginTop = 25,
                MarginBottom = 25,
                EnableJavaScript = true,      // Supports dynamic HTML content
            }
        };
    }

    public async Task<byte[]> GenerateFromHtmlAsync(string html)
    {
        try
        {
            // Render PDF from an HTML string or template
            _renderer.RenderingOptions.WaitFor.RenderDelay(2000); // Wait for 2 seconds to allow JS to execute
            var pdf = await _renderer.RenderHtmlAsPdfAsync(html);
            _logger.LogInformation("PDF generated successfully");
            return pdf.BinaryData; // Return byte array for storage or download
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "PDF generation failed");
            throw;
        }
    }

    public async Task<byte[]> GenerateFromUrlAsync(string url)
    {
        // Convert entire web pages or specific URLs to PDF documents
        var pdf = await _renderer.RenderUrlAsPdfAsync(url);
        return pdf.BinaryData;
    }
}
  

Notes:

  • Use this pattern for enterprise applications, large-scale PDF generation, or when rendering complex HTML templates.

  • Supports embedded CSS, JavaScript rendering, and custom headers.

  • Logging ensures failures during HTML conversion or PDF generation are captured for diagnostics.

Using this code, for example, we were able to convert this URL ( https://en.wikipedia.org/wiki/Main_Page ) to PDF format while maintaining the original structure and styling:

wikipedia

Pattern 2: Dependency Injection Configuration

  
    // Program.cs (.NET 6+)
builder.Services.AddSingleton<IPdfGenerator, ProductionPdfGenerator>();

// Usage in controller
[ApiController]
[Route("api/[controller]")]
public class PdfController : ControllerBase
{
    private readonly IPdfGenerator _pdfGenerator;
    
    public PdfController(IPdfGenerator pdfGenerator)
    {
        _pdfGenerator = pdfGenerator;
    }
    
    [HttpPost("generate")]
    public async Task<IActionResult> GeneratePdf([FromBody] string html)
    {
        // Generate PDF from HTML string or template
        var pdfData = await _pdfGenerator.GenerateFromHtmlAsync(html);
        
        // Return PDF file as response
        return File(pdfData, "application/pdf", "document.pdf");
    }
}
  

Notes:

  • Integrates PDF generation into ASP.NET Core applications via dependency injection.

  • Promotes clean, testable code and centralized rendering logic.

  • Ideal for rendering entire web pages, HTML snippets, or complex templates from existing HTML content.

Performance Benchmarks

Performance is critical for HTML to PDF conversion, especially in high-volume or large-scale PDF generation scenarios. This section evaluates memory usage, generation time, thread safety, and deployment complexity for several popular libraries.

Memory Consumption and Generation Speed

LibraryMemory Usage (100 PDFs)Generation TimeThread Safe
IronPDF50MB20sYes
PuppeteerSharp500MB+45sLimited
HtmlRenderer.PdfSharp30MB15sYes
DinkToPdf150MB35sNo

Insights:

  • IronPDF is optimized for enterprise-level PDF generation, handling multiple concurrent requests efficiently.

  • PuppeteerSharp provides high-fidelity HTML to PDF conversion, but memory-heavy and slower for large batches.

  • HtmlRenderer.PdfSharp is the fastest and lightest but limited to basic HTML conversion.

  • DinkToPdf is risky for production due to threading issues and memory instability.

Deployment Complexity

LibraryComplexity Score (1–10)Notes
IronPDF2NuGet install only; works out of the box with minimal setup for HTML or URL conversion.
HtmlRenderer.PdfSharp3Easy to use but missing modern CSS and JavaScript support.
SelectPdf5Windows-only dependency, which limits cross-platform use.
PuppeteerSharp7You need to manage the Chrome binary and handle serverless deployment quirks.
DinkToPdf8Native binaries and platform differences make large-scale deployment tricky.
Gotenberg9Runs as a Docker service, adding orchestration overhead and network latency.

Takeaways:

  • For production HTML to PDF conversion, libraries with low memory usage, fast generation times, and thread safety are preferred.

  • Deployment simplicity is equally important: IronPDF scores best for quick integration in .NET Core, .NET 6+, and .NET 10 projects.

  • Memory-heavy solutions like PuppeteerSharp are better suited for batch or high-fidelity PDF generation, not lightweight APIs or serverless environments.

Security Considerations

Generating PDF documents from HTML carries potential security risks, especially when using abandoned libraries like wkhtmltopdf.

Key Vulnerabilities

  • Remote code execution (CVE-2020-21365) via crafted HTML.

  • SSRF attacks (CVE-2022-35583) from external resources.

  • XSS vectors from unsafe HTML or JavaScript.

  • Unpatched flaws in discontinued libraries.

Best Practices

  • Sanitize HTML input to remove unsafe scripts.

  • Disable JavaScript unless necessary.

  • Use sandboxed renderers with timeouts to prevent infinite loops.

  • Avoid Process.Start() methods and abandoned libraries.

  • Validate external resources for security compliance.

  
    public class SecurePdfGenerator
{
    public async Task<byte[]> GenerateSecurePdf(string untrustedHtml)
    {
        var sanitizedHtml = new HtmlSanitizer().Sanitize(untrustedHtml);
        
        var renderer = new ChromePdfRenderer
        {
            RenderingOptions =
            {
                EnableJavaScript = false,
                Timeout = 30000,
                PageSize = PdfPageSize.A4
            }
        };
        
        return await renderer.RenderHtmlAsPdfAsync(sanitizedHtml);
    }
}
  

Recommendations

Selecting the right HTML to PDF library in C# depends on your project’s scope, scale, and security requirements. Below are tailored recommendations for different scenarios.

1. For Enterprise Applications

Primary Recommendation: IronPDF

  • Fully cross-platform and supports .NET Framework, .NET Core, and .NET 10.

  • Consistent monthly updates with security patches.

  • Supports PDF/A compliance, essential for archival and compliance reports.

  • Handles complex templates, CSS styling, and JavaScript execution.

  • Provides professional support and extensive documentation, reducing developer overhead.

Use Case: Generating large-scale PDF files, entire web pages, or creating PDF files from HTML templates.

2. For Proof of Concepts or Testing

Recommended Library: PuppeteerSharp

  • Excellent Chrome-based rendering, supporting modern HTML, CSS, and JavaScript.

  • Good for dynamic web content or interactive HTML pages.

  • Be mindful of memory usage and deployment complexity in serverless environments.

Use Case: Quick prototypes or experimental PDF generation, where cross-platform support is less critical.

3. For Simple Documents or Lightweight Tasks

Recommended Library: HtmlRenderer.PdfSharp

  • Lightweight and easy to integrate.

  • Supports basic HTML snippets and CSS2 styling.

  • Not suitable for complex templates or large-scale PDF generation.

Use Case: Single-page HTML documents, simple reports, or internal tools with minimal CSS and JavaScript requirements.

4. Libraries to Avoid in Production

  • All wkhtmltopdf-based libraries (DinkToPdf, Rotativa, NReco.PdfGenerator): Unpatched security vulnerabilities.

  • Process.Start() approaches : Injection risks.

  • Abandoned projects : No security updates, no modern web support.

5. Migration Strategy for Deprecated Libraries

  
    // Legacy code using wkhtmltopdf-based library
public byte[] OldMethod(string html)
{
    var converter = new SomeWkHtmlToPdfWrapper();
    return converter.Convert(html);
}

// Migration to supported library
public async Task<byte[]> NewMethod(string html)
{
    var renderer = new ChromePdfRenderer();
    var pdf = await renderer.RenderHtmlAsPdfAsync(html);
    return pdf.BinaryData;
}
  

Conclusion

C# HTML to PDF conversion in 2025 requires careful library selection to balance performance, security, and maintainability. While many libraries exist, only a few meet modern .NET requirements for reliable PDF generation.

Key Takeaways

  1. Choose actively maintained libraries

    • Monthly updates, security patches, and .NET 10 support are essential.

    • IronPDF is the most reliable for production environments.

  2. Avoid deprecated or abandoned solutions

    • wkhtmltopdf-based libraries have security flaws and lack modern CSS/JS support.

    • Process.Start() methods carry injection risks.

  3. Match the library to your use case

    • Enterprise PDF generation : IronPDF

    • Prototypes / PoCs : PuppeteerSharp

    • Simple documents : HtmlRenderer.PdfSharp

  4. Support complex HTML content

    • Ensure libraries handle CSS3, JavaScript, page breaks, custom headers, and HTML templates.

  5. Invest in maintainable workflows

    • Dependency injection and robust renderers simplify scalable PDF generation.

    • Migrating from deprecated libraries reduces long-term security and maintenance risks.

Final Thought:

Choosing the right library is more than PDF quality, it ensures security, cross-platform support, and maintainability. For generating PDF documents from HTML pages or templates, a commercial, actively maintained solution like IronPDF is the most reliable approach. Try IronPDF's free trial to explore its powerful features for yourself, and check out its extensive documentation to learn more.