IronPDF Tutorials HTML to PDF C# Conversion HTML to PDF in C# .NET - Complete Developer Guide Jacob Mellor Updated:July 13, 2025 41 Looking to convert HTML to PDF in your .NET applications? This comprehensive tutorial shows you exactly how to implement a HTML to PDF converter using IronPDF, creating pixel-perfect PDF documents that match your web designs precisely. Whether you're building invoices, reports, or document archives, you'll learn the most efficient approach to convert HTML to PDF in C#. Get started making PDFs now! IronPdf.ChromePdfRenderer .StaticRenderHtmlAsPdf("<p>Hello World</p>") .SaveAs("pixelperfect.pdf"); Install with NuGet PM > Install-Package IronPdf Overview How to Convert HTML to PDF in C#? Download and install the HTML to PDF C# library Create a PDF with an HTML String Use the RenderHtmlAsPdf method to convert an HTML String to a PDF Export a PDF using existing URL Generate a PDF from a HTML page Add Custom Headers and Footers Call SaveAs to save the PDF file to the computer More Why Do You Need an HTML to PDF Converter for C#? Creating PDF files programmatically in .NET can be a frustrating task. The PDF document file format was designed primarily for printers rather than developers. C# doesn't have built-in HTML to PDF functionality, requiring third-party libraries to accomplish this common task. While several options exist - including IronPDF, iTextSharp, PdfSharp, Syncfusion, Aspose.PDF, and wkhtmltopdf - choosing the right HTML to PDF converter significantly impacts your project's success. The HTML to PDF conversion library we'll use in this tutorial is IronPDF, a comprehensive C# PDF generation and editing library. This library delivers production-ready PDF functionality, works out-of-the-box without complex configuration, accomplishes tasks with minimal code, and provides extensive documentation for over 50 features. IronPDF stands out with support for .NET 9, .NET 8, .NET 7, .NET 6, and .NET 5, .NET Core, Standard, and Framework on Windows, macOS, Linux, Docker, Azure, and AWS. The library is already compliant with the upcoming .NET 10 release scheduled for November 2025, as Iron Software works closely with the .NET Foundation and Microsoft to ensure day-one compatibility. With IronPDF's advanced Chrome rendering engine, creating PDFs becomes straightforward - you design your documents using familiar HTML, CSS, and JavaScript, then let IronPDF handle the HTML to PDF conversion with pixel-perfect accuracy. This approach to dynamic PDF generation works seamlessly across console applications, Windows Forms, WPF, websites, and MVC applications. IronPDF also supports debugging of your HTML with Chrome for pixel-perfect PDFs. A tutorial for this setup is available here. What Makes IronPDF's Chrome Rendering Engine Special? IronPDF distinguishes itself as the only .NET PDF library producing pixel-perfect PDFs that match exactly what you see in Google Chrome. While other libraries generate PDFs resembling faded printer output, IronPDF creates vibrant, accurate generated PDF documents preserving your design intent when you convert HTML to PDF. Key Advantages of IronPDF: True Chrome Rendering - Uses the same Blink engine as Google Chrome for accurate HTML to PDF conversion Pixel-Perfect Accuracy - Your generated PDF documents match the web page exactly, not a printer-friendly version Full Modern Web Support - Complete CSS3, HTML5, and JavaScript support for all HTML elements Zero External Dependencies - No executables to install on servers (unlike wkhtmltopdf) 5-20x Performance Boost - Significantly faster than browser automation or web drivers for high-load applications PDF/UA Compliant - Creates accessible PDFs meeting Section 508 standards Learn more about achieving pixel-perfect HTML to PDF rendering Cross-Language Support IronPDF extends beyond .NET, offering consistent PDF generation across multiple programming languages: F# PDF generation guide VB.NET PDF creation tutorial Python HTML to PDF Java PDF generation Node.js PDF creation IronPDF requires a license for production use. You can purchase a license or sign up for a free 30-day trial key. Step 1 How to Install the HTML to PDF C# Library? Visual Studio - NuGet Package Manager In Visual Studio, right-click on your project in Solution Explorer and select Manage NuGet Packages.... Search for IronPDF and install the latest version. Click OK to any dialog boxes that appear. This installation method works equally well for VB.NET projects. Install-Package IronPdf IronPDF on NuGet Website For comprehensive details about IronPDF's features, compatibility, and downloads, visit IronPDF on NuGet's official website: https://www.nuget.org/packages/IronPdf Install via DLL Alternatively, you can install the IronPDF DLL directly. Download and manually install IronPDF to your project or GAC from https://ironpdf.com/packages/IronPdf.zip Which Package Should You Choose? IronPdf - Standard package with everything included (recommended for most users) IronPdf.Slim - Lightweight package for advanced cloud deployments using remote rendering For containerized or distributed computing scenarios, IronPDF offers Remote Mode that separates the rendering engine. Explore IronPdfEngine for advanced deployments. How to Tutorials How to Create a PDF with an HTML String in C#? Converting HTML strings to PDF is a fundamental skill for .NET developers. The process is remarkably efficient using IronPDF's rendering engine. We use the ChromePdfRenderer.RenderHtmlAsPdf method to transform any HTML code (including HTML5) into a PDF. The C# HTML to PDF rendering leverages a fully functional Google Chromium engine embedded within the IronPDF DLL. // Import IronPdf namespace for PDF generation functionality using IronPdf; // Create ChromePdfRenderer instance for HTML to PDF conversion var renderer = new ChromePdfRenderer(); // Convert HTML string to PDF document using Chrome rendering engine // RenderHtmlAsPdf method processes HTML/CSS/JavaScript content var pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>"); // Save the generated PDF document to disk // The PDF will be pixel-perfect matching Chrome's rendering pdfDocument.SaveAs("pixel-perfect.pdf"); // Import IronPdf namespace for PDF generation functionality using IronPdf; // Create ChromePdfRenderer instance for HTML to PDF conversion var renderer = new ChromePdfRenderer(); // Convert HTML string to PDF document using Chrome rendering engine // RenderHtmlAsPdf method processes HTML/CSS/JavaScript content var pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>"); // Save the generated PDF document to disk // The PDF will be pixel-perfect matching Chrome's rendering pdfDocument.SaveAs("pixel-perfect.pdf"); ' Import IronPdf namespace for PDF generation functionality Imports IronPdf ' Create ChromePdfRenderer instance for HTML to PDF conversion Private renderer = New ChromePdfRenderer() ' Convert HTML string to PDF document using Chrome rendering engine ' RenderHtmlAsPdf method processes HTML/CSS/JavaScript content Private pdfDocument = renderer.RenderHtmlAsPdf("<h1>Hello IronPdf</h1>") ' Save the generated PDF document to disk ' The PDF will be pixel-perfect matching Chrome's rendering pdfDocument.SaveAs("pixel-perfect.pdf") $vbLabelText $csharpLabel The RenderHtmlAsPdf method fully supports HTML5, CSS3, JavaScript, and images. For assets stored locally, set the second parameter to the directory path containing these resources. This method returns a PdfDocument object - a comprehensive class for PDF manipulation and information. Working with Local Assets When your HTML references local files like images or stylesheets, use the BaseUrlPath parameter: using IronPdf; // Initialize ChromePdfRenderer for HTML to PDF conversion var renderer = new ChromePdfRenderer(); // Convert HTML with local image reference // BaseUrlPath parameter tells IronPDF where to find referenced files var pdf = renderer.RenderHtmlAsPdf("<img src='image1.png'/>", @"C:\MyProject\Assets\"); // Save the PDF containing the embedded image // Ensure write permissions for the output directory pdf.SaveAs(@"C:\MyProject\Assets\output.pdf"); // The HTML to PDF converter resolves relative paths using BaseUrlPath // All CSS, JavaScript, and image references work seamlessly using IronPdf; // Initialize ChromePdfRenderer for HTML to PDF conversion var renderer = new ChromePdfRenderer(); // Convert HTML with local image reference // BaseUrlPath parameter tells IronPDF where to find referenced files var pdf = renderer.RenderHtmlAsPdf("<img src='image1.png'/>", @"C:\MyProject\Assets\"); // Save the PDF containing the embedded image // Ensure write permissions for the output directory pdf.SaveAs(@"C:\MyProject\Assets\output.pdf"); // The HTML to PDF converter resolves relative paths using BaseUrlPath // All CSS, JavaScript, and image references work seamlessly Imports IronPdf ' Initialize ChromePdfRenderer for HTML to PDF conversion Private renderer = New ChromePdfRenderer() ' Convert HTML with local image reference ' BaseUrlPath parameter tells IronPDF where to find referenced files Private pdf = renderer.RenderHtmlAsPdf("<img src='image1.png'/>", "C:\MyProject\Assets\") ' Save the PDF containing the embedded image ' Ensure write permissions for the output directory pdf.SaveAs("C:\MyProject\Assets\output.pdf") ' The HTML to PDF converter resolves relative paths using BaseUrlPath ' All CSS, JavaScript, and image references work seamlessly $vbLabelText $csharpLabel All referenced CSS stylesheets, images, and JavaScript files resolve relative to the BaseUrlPath, maintaining a clean and logical structure. You can also reference online resources, including web fonts like Google Fonts and libraries like jQuery. How to Export a PDF Using an Existing URL? Rendering existing URLs as PDFs with C# proves both efficient and intuitive. This approach enables teams to separate PDF design and back-end rendering work across different skill sets. Let's render a Wikipedia page as an example: using IronPdf; // Create ChromePdfRenderer for URL to PDF conversion var renderer = new ChromePdfRenderer(); // Convert webpage URL directly to PDF document // Preserves all styling, images, and interactive elements var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/PDF"); // Save the rendered webpage as a PDF file pdf.SaveAs("wikipedia.pdf"); // The PDF converter maintains hyperlinks and form elements // Perfect for archiving web content or creating offline versions using IronPdf; // Create ChromePdfRenderer for URL to PDF conversion var renderer = new ChromePdfRenderer(); // Convert webpage URL directly to PDF document // Preserves all styling, images, and interactive elements var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/PDF"); // Save the rendered webpage as a PDF file pdf.SaveAs("wikipedia.pdf"); // The PDF converter maintains hyperlinks and form elements // Perfect for archiving web content or creating offline versions Imports IronPdf ' Create ChromePdfRenderer for URL to PDF conversion Private renderer = New ChromePdfRenderer() ' Convert webpage URL directly to PDF document ' Preserves all styling, images, and interactive elements Private pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/PDF") ' Save the rendered webpage as a PDF file pdf.SaveAs("wikipedia.pdf") ' The PDF converter maintains hyperlinks and form elements ' Perfect for archiving web content or creating offline versions $vbLabelText $csharpLabel Notice how hyperlinks and HTML forms remain functional within the generated PDF document created by our C# code. Print vs Screen CSS Media Types Modern CSS3 supports different styling for print and screen media. You can configure IronPDF to render using either CSS media type. By default, "Screen" CSS renders, which users find most intuitive. using IronPdf; using IronPdf.Rendering; // Initialize HTML to PDF converter var renderer = new ChromePdfRenderer(); // Configure CSS media type for rendering // Choose between Screen (default) or Print styling renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // Screen media type shows the webpage as displayed on screen // Print media type applies print-specific CSS rules using IronPdf; using IronPdf.Rendering; // Initialize HTML to PDF converter var renderer = new ChromePdfRenderer(); // Configure CSS media type for rendering // Choose between Screen (default) or Print styling renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // Screen media type shows the webpage as displayed on screen // Print media type applies print-specific CSS rules Imports IronPdf Imports IronPdf.Rendering ' Initialize HTML to PDF converter Private renderer = New ChromePdfRenderer() ' Configure CSS media type for rendering ' Choose between Screen (default) or Print styling renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print ' Screen media type shows the webpage as displayed on screen ' Print media type applies print-specific CSS rules $vbLabelText $csharpLabel Learn more: Choosing Between Print and Screen CSS Media Types JavaScript Support IronPDF fully supports JavaScript, jQuery, and even AJAX. For dynamic content, you can configure IronPDF to wait for JavaScript completion before rendering. using IronPdf; // Configure JavaScript rendering for dynamic content var renderer = new ChromePdfRenderer(); // Enable JavaScript execution during PDF generation renderer.RenderingOptions.EnableJavaScript = true; // Add delay for AJAX/dynamic content to fully load // WaitFor.RenderDelay pauses before capturing the page renderer.RenderingOptions.WaitFor.RenderDelay = 500; // milliseconds // Perfect for single-page applications and dynamic websites using IronPdf; // Configure JavaScript rendering for dynamic content var renderer = new ChromePdfRenderer(); // Enable JavaScript execution during PDF generation renderer.RenderingOptions.EnableJavaScript = true; // Add delay for AJAX/dynamic content to fully load // WaitFor.RenderDelay pauses before capturing the page renderer.RenderingOptions.WaitFor.RenderDelay = 500; // milliseconds // Perfect for single-page applications and dynamic websites Imports IronPdf ' Configure JavaScript rendering for dynamic content Private renderer = New ChromePdfRenderer() ' Enable JavaScript execution during PDF generation renderer.RenderingOptions.EnableJavaScript = True ' Add delay for AJAX/dynamic content to fully load ' WaitFor.RenderDelay pauses before capturing the page renderer.RenderingOptions.WaitFor.RenderDelay = 500 ' milliseconds ' Perfect for single-page applications and dynamic websites $vbLabelText $csharpLabel We can demonstrate JavaScript compatibility by rendering an advanced d3.js chord chart: using IronPdf; // Create renderer for JavaScript-heavy content var renderer = new ChromePdfRenderer(); // Convert d3.js visualization to PDF // IronPDF executes all JavaScript before rendering var pdf = renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006"); // Save the interactive chart as a static PDF pdf.SaveAs("chart.pdf"); // Complex JavaScript visualizations render perfectly // No special configuration needed for most JavaScript frameworks using IronPdf; // Create renderer for JavaScript-heavy content var renderer = new ChromePdfRenderer(); // Convert d3.js visualization to PDF // IronPDF executes all JavaScript before rendering var pdf = renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006"); // Save the interactive chart as a static PDF pdf.SaveAs("chart.pdf"); // Complex JavaScript visualizations render perfectly // No special configuration needed for most JavaScript frameworks Imports IronPdf ' Create renderer for JavaScript-heavy content Private renderer = New ChromePdfRenderer() ' Convert d3.js visualization to PDF ' IronPDF executes all JavaScript before rendering Private pdf = renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006") ' Save the interactive chart as a static PDF pdf.SaveAs("chart.pdf") ' Complex JavaScript visualizations render perfectly ' No special configuration needed for most JavaScript frameworks $vbLabelText $csharpLabel Responsive CSS Considerations Responsive web pages designed for browsers may render at minimum widths in PDFs. IronPDF doesn't open a browser window on your server, which can affect responsive layouts. We recommend using Print CSS media types to address this issue, as print CSS typically isn't responsive. // Configure for optimal responsive design handling renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print; // Configure for optimal responsive design handling renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print; ' Configure for optimal responsive design handling renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print $vbLabelText $csharpLabel How to Generate a PDF from an HTML File? Converting local HTML files to PDF preserves all relative assets including CSS, images, and JavaScript, as if opened using the file:// protocol. using IronPdf; // Initialize ChromePdfRenderer for file conversion var renderer = new ChromePdfRenderer(); // Convert HTML file to PDF document // Preserves all relative paths and linked resources var pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html"); // Save the generated PDF invoice pdf.SaveAs("Invoice.pdf"); // All CSS, JavaScript, and images load correctly // Perfect for template-based PDF generation using IronPdf; // Initialize ChromePdfRenderer for file conversion var renderer = new ChromePdfRenderer(); // Convert HTML file to PDF document // Preserves all relative paths and linked resources var pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html"); // Save the generated PDF invoice pdf.SaveAs("Invoice.pdf"); // All CSS, JavaScript, and images load correctly // Perfect for template-based PDF generation Imports IronPdf ' Initialize ChromePdfRenderer for file conversion Private renderer = New ChromePdfRenderer() ' Convert HTML file to PDF document ' Preserves all relative paths and linked resources Private pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html") ' Save the generated PDF invoice pdf.SaveAs("Invoice.pdf") ' All CSS, JavaScript, and images load correctly ' Perfect for template-based PDF generation $vbLabelText $csharpLabel This method allows developers to test HTML code in a browser during development. We recommend Chrome since IronPDF uses the same rendering engine. For XML to PDF conversion, use XSLT templating to transform XML content. How to Add Custom Headers and Footers? Headers and footers enhance generated PDF documents with consistent branding and navigation. IronPDF supports both simple text-based headers using TextHeaderFooter and rich HTML content using HtmlHeaderFooter. using IronPdf; // Configure PDF with professional headers and footers var renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { // Set margins for header/footer space MarginTop = 50, // millimeters MarginBottom = 50, // Use Print CSS for consistent formatting CssMediaType = PdfCssMediaType.Print, // Add text-based header with title TextHeader = new TextHeaderFooter { CenterText = "{pdf-title}", DrawDividerLine = true, FontSize = 16 }, // Add footer with date and pagination TextFooter = new TextHeaderFooter { LeftText = "{date} {time}", RightText = "Page {page} of {total-pages}", DrawDividerLine = true, FontSize = 14 } } }; // Generate PDF with headers and footers var pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html"); pdf.SaveAs("Invoice.pdf"); using IronPdf; // Configure PDF with professional headers and footers var renderer = new ChromePdfRenderer { RenderingOptions = new ChromePdfRenderOptions { // Set margins for header/footer space MarginTop = 50, // millimeters MarginBottom = 50, // Use Print CSS for consistent formatting CssMediaType = PdfCssMediaType.Print, // Add text-based header with title TextHeader = new TextHeaderFooter { CenterText = "{pdf-title}", DrawDividerLine = true, FontSize = 16 }, // Add footer with date and pagination TextFooter = new TextHeaderFooter { LeftText = "{date} {time}", RightText = "Page {page} of {total-pages}", DrawDividerLine = true, FontSize = 14 } } }; // Generate PDF with headers and footers var pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html"); pdf.SaveAs("Invoice.pdf"); Imports IronPdf ' Configure PDF with professional headers and footers Private renderer = New ChromePdfRenderer With { .RenderingOptions = New ChromePdfRenderOptions With { .MarginTop = 50, .MarginBottom = 50, .CssMediaType = PdfCssMediaType.Print, .TextHeader = New TextHeaderFooter With { .CenterText = "{pdf-title}", .DrawDividerLine = True, .FontSize = 16 }, .TextFooter = New TextHeaderFooter With { .LeftText = "{date} {time}", .RightText = "Page {page} of {total-pages}", .DrawDividerLine = True, .FontSize = 14 } } } ' Generate PDF with headers and footers Private pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html") pdf.SaveAs("Invoice.pdf") $vbLabelText $csharpLabel Explore comprehensive rendering options: How to Use the Rendering Options HTML Headers and Footers The HtmlHeaderFooter class enables rich headers and footers using HTML5 content, including images, stylesheets, and hyperlinks. using IronPdf; // Create renderer with HTML-based footer var renderer = new ChromePdfRenderer(); // Configure HTML footer with styled content renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter() { HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>", // HTML footers support full CSS styling // Perfect for branded document footers }; using IronPdf; // Create renderer with HTML-based footer var renderer = new ChromePdfRenderer(); // Configure HTML footer with styled content renderer.RenderingOptions.HtmlFooter = new HtmlHeaderFooter() { HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>", // HTML footers support full CSS styling // Perfect for branded document footers }; Imports IronPdf ' Create renderer with HTML-based footer Private renderer = New ChromePdfRenderer() ' Configure HTML footer with styled content renderer.RenderingOptions.HtmlFooter = New HtmlHeaderFooter() With {.HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>"} $vbLabelText $csharpLabel Dynamic Header and Footer Placeholders Merge dynamic content into headers and footers using these placeholders: {page} - Current page number {total-pages} - Total page count {url} - Source URL (for web-based PDFs) {date} - Today's date {time} - Current time {html-title} - Title from rendered HTML document {pdf-title} - PDF document title What Are the Key HTML to PDF Conversion Settings? The HTML to PDF converter provides extensive customization through the ChromePdfRenderer.RenderingOptions property. Choose CSS media type for optimal rendering: using IronPdf; // Create renderer with specific media type var renderer = new ChromePdfRenderer(); // Apply print-specific CSS rules // Useful for simplified, print-optimized layouts renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // Generate PDF with print styling renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>").SaveAs("Output.pdf"); using IronPdf; // Create renderer with specific media type var renderer = new ChromePdfRenderer(); // Apply print-specific CSS rules // Useful for simplified, print-optimized layouts renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print; // Generate PDF with print styling renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>").SaveAs("Output.pdf"); Imports IronPdf ' Create renderer with specific media type Private renderer = New ChromePdfRenderer() ' Apply print-specific CSS rules ' Useful for simplified, print-optimized layouts renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print ' Generate PDF with print styling renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>").SaveAs("Output.pdf") $vbLabelText $csharpLabel Customize page margins for professional layouts: using IronPdf; var renderer = new ChromePdfRenderer(); // Set custom margins in millimeters // Ideal for headers, footers, or full-bleed designs renderer.RenderingOptions.MarginTop = 50; renderer.RenderingOptions.MarginBottom = 50; // Create PDF with custom margins // Zero margins work great for posters and brochures using IronPdf; var renderer = new ChromePdfRenderer(); // Set custom margins in millimeters // Ideal for headers, footers, or full-bleed designs renderer.RenderingOptions.MarginTop = 50; renderer.RenderingOptions.MarginBottom = 50; // Create PDF with custom margins // Zero margins work great for posters and brochures Imports IronPdf Private renderer = New ChromePdfRenderer() ' Set custom margins in millimeters ' Ideal for headers, footers, or full-bleed designs renderer.RenderingOptions.MarginTop = 50 renderer.RenderingOptions.MarginBottom = 50 ' Create PDF with custom margins ' Zero margins work great for posters and brochures $vbLabelText $csharpLabel Control background rendering from HTML elements: using IronPdf; var renderer = new ChromePdfRenderer(); // Enable background colors and images // Essential for preserving design elements renderer.RenderingOptions.PrintHtmlBackgrounds = true; // Generate visually rich PDFs var htmlContent = "<div style='background-color: #f0f0f0; padding: 20px;'><h1>Styled Content</h1></div>"; var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent); pdfDocument.SaveAs("styled-output.pdf"); using IronPdf; var renderer = new ChromePdfRenderer(); // Enable background colors and images // Essential for preserving design elements renderer.RenderingOptions.PrintHtmlBackgrounds = true; // Generate visually rich PDFs var htmlContent = "<div style='background-color: #f0f0f0; padding: 20px;'><h1>Styled Content</h1></div>"; var pdfDocument = renderer.RenderHtmlAsPdf(htmlContent); pdfDocument.SaveAs("styled-output.pdf"); Imports IronPdf Private renderer = New ChromePdfRenderer() ' Enable background colors and images ' Essential for preserving design elements renderer.RenderingOptions.PrintHtmlBackgrounds = True ' Generate visually rich PDFs Dim htmlContent = "<div style='background-color: #f0f0f0; padding: 20px;'><h1>Styled Content</h1></div>" Dim pdfDocument = renderer.RenderHtmlAsPdf(htmlContent) pdfDocument.SaveAs("styled-output.pdf") $vbLabelText $csharpLabel Configure paper size and orientation: using IronPdf; using IronPdf.Rendering; var renderer = new ChromePdfRenderer(); // Set paper size and orientation // Supports standard and custom sizes renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape; // Custom sizes available in millimeters or inches // Perfect for invoices, reports, or presentations using IronPdf; using IronPdf.Rendering; var renderer = new ChromePdfRenderer(); // Set paper size and orientation // Supports standard and custom sizes renderer.RenderingOptions.PaperSize = PdfPaperSize.A4; renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape; // Custom sizes available in millimeters or inches // Perfect for invoices, reports, or presentations Imports IronPdf Imports IronPdf.Rendering Private renderer = New ChromePdfRenderer() ' Set paper size and orientation ' Supports standard and custom sizes renderer.RenderingOptions.PaperSize = PdfPaperSize.A4 renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape ' Custom sizes available in millimeters or inches ' Perfect for invoices, reports, or presentations $vbLabelText $csharpLabel Discover all options: Complete Guide to Rendering Options How to Apply HTML Templating for Batch PDF Creation? Batch PDF creation is a common requirement for web applications. Using our HTML to PDF converter, you can efficiently generate multiple personalized documents. Rather than templating PDFs directly, IronPDF leverages existing HTML templating technologies. Combining HTML templates with data produces dynamically generated PDF documents. For basic scenarios, C#'s String.Format method works effectively: // Simple HTML templating with String.Format string htmlTemplate = String.Format("<h1>Hello {0}!</h1>", "World"); // Results in: <h1>Hello World!</h1> // Simple HTML templating with String.Format string htmlTemplate = String.Format("<h1>Hello {0}!</h1>", "World"); // Results in: <h1>Hello World!</h1> ' Simple HTML templating with String.Format Dim htmlTemplate As String = String.Format("<h1>Hello {0}!</h1>", "World") ' Results in: <h1>Hello World!</h1> $vbLabelText $csharpLabel For longer templates, use placeholder replacement: using IronPdf; // Define reusable HTML template var htmlTemplate = "<p>Dear [[NAME]],</p><p>Thank you for your order.</p>"; // Customer names for batch processing var names = new[] { "John", "James", "Jenny" }; // Create personalized PDFs for each customer var renderer = new ChromePdfRenderer(); foreach (var name in names) { // Replace placeholder with actual data var htmlInstance = htmlTemplate.Replace("[[NAME]]", name); // Generate personalized PDF document var pdf = renderer.RenderHtmlAsPdf(htmlInstance); // Save with customer-specific filename pdf.SaveAs($"{name}-invoice.pdf"); } // Batch HTML to PDF conversion completed // Each PDF is personalized with customer data using IronPdf; // Define reusable HTML template var htmlTemplate = "<p>Dear [[NAME]],</p><p>Thank you for your order.</p>"; // Customer names for batch processing var names = new[] { "John", "James", "Jenny" }; // Create personalized PDFs for each customer var renderer = new ChromePdfRenderer(); foreach (var name in names) { // Replace placeholder with actual data var htmlInstance = htmlTemplate.Replace("[[NAME]]", name); // Generate personalized PDF document var pdf = renderer.RenderHtmlAsPdf(htmlInstance); // Save with customer-specific filename pdf.SaveAs($"{name}-invoice.pdf"); } // Batch HTML to PDF conversion completed // Each PDF is personalized with customer data Imports IronPdf ' Define reusable HTML template Private htmlTemplate = "<p>Dear [[NAME]],</p><p>Thank you for your order.</p>" ' Customer names for batch processing Private names = { "John", "James", "Jenny" } ' Create personalized PDFs for each customer Private renderer = New ChromePdfRenderer() For Each name In names ' Replace placeholder with actual data Dim htmlInstance = htmlTemplate.Replace("[[NAME]]", name) ' Generate personalized PDF document Dim pdf = renderer.RenderHtmlAsPdf(htmlInstance) ' Save with customer-specific filename pdf.SaveAs($"{name}-invoice.pdf") Next name ' Batch HTML to PDF conversion completed ' Each PDF is personalized with customer data $vbLabelText $csharpLabel Advanced Templating with Handlebars.NET For sophisticated HTML templating, use the Handlebars standard to merge C# objects with HTML templates. Handlebars excels at creating dynamic HTML from database records, particularly for scenarios with variable data like invoice line items. First, install the Handlebars.NET package: https://www.nuget.org/packages/Handlebars.NET/ using HandlebarsDotNet; using IronPdf; // Define Handlebars template with placeholders var source = @"<div class=""entry""> <h1>{{title}}</h1> <div class=""body""> {{body}} </div> </div>"; // Compile template for reuse var template = Handlebars.Compile(source); // Create data object (can be database records) var data = new { title = "Monthly Report", body = "Sales increased by 15% this month." }; // Merge template with data var htmlResult = template(data); // Convert templated HTML to PDF var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(htmlResult); pdf.SaveAs("monthly-report.pdf"); // Complex templates with loops and conditionals supported // Perfect for invoices, reports, and dynamic documents using HandlebarsDotNet; using IronPdf; // Define Handlebars template with placeholders var source = @"<div class=""entry""> <h1>{{title}}</h1> <div class=""body""> {{body}} </div> </div>"; // Compile template for reuse var template = Handlebars.Compile(source); // Create data object (can be database records) var data = new { title = "Monthly Report", body = "Sales increased by 15% this month." }; // Merge template with data var htmlResult = template(data); // Convert templated HTML to PDF var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(htmlResult); pdf.SaveAs("monthly-report.pdf"); // Complex templates with loops and conditionals supported // Perfect for invoices, reports, and dynamic documents Imports HandlebarsDotNet Imports IronPdf ' Define Handlebars template with placeholders Private source = "<div class=""entry""> <h1>{{title}}</h1> <div class=""body""> {{body}} </div> </div>" ' Compile template for reuse Private template = Handlebars.Compile(source) ' Create data object (can be database records) Private data = New With { Key .title = "Monthly Report", Key .body = "Sales increased by 15% this month." } ' Merge template with data Private htmlResult = template(data) ' Convert templated HTML to PDF Private renderer = New ChromePdfRenderer() Private pdf = renderer.RenderHtmlAsPdf(htmlResult) pdf.SaveAs("monthly-report.pdf") ' Complex templates with loops and conditionals supported ' Perfect for invoices, reports, and dynamic documents $vbLabelText $csharpLabel Learn more about Handlebars.NET on GitHub. Control PDF Page Breaks Managing pagination in generated PDF documents ensures professional, readable layouts. Use this CSS trick for page breaks: <div style='page-break-after: always;'> </div> <div style='page-break-after: always;'> </div> HTML For better practice, use CSS media attributes: <!DOCTYPE html> <html> <head> <style type="text/css" media="print"> .page { page-break-after: always; page-break-inside: avoid; } </style> </head> <body> <div class="page"> <h1>Page 1 Content</h1> </div> <div class="page"> <h1>Page 2 Content</h1> </div> <div class="page"> <h1>Page 3 Content</h1> </div> </body> </html> <!DOCTYPE html> <html> <head> <style type="text/css" media="print"> .page { page-break-after: always; page-break-inside: avoid; } </style> </head> <body> <div class="page"> <h1>Page 1 Content</h1> </div> <div class="page"> <h1>Page 2 Content</h1> </div> <div class="page"> <h1>Page 3 Content</h1> </div> </body> </html> HTML More strategies: HTML to PDF Page Breaks Guide How to Attach a Cover Page to a PDF? IronPDF simplifies merging generated PDF documents. Common use cases include adding cover pages or appendices to existing PDFs. First, render a cover page using our HTML to PDF converter, then combine documents using PdfDocument.Merge(): using IronPdf; var renderer = new ChromePdfRenderer(); // Generate main document from URL var mainPdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/"); // Merge cover page with main document // PdfDocument.Merge combines multiple PDFs seamlessly var pdfWithCover = PdfDocument.Merge(new PdfDocument("CoverPage.pdf"), mainPdf); // Save the complete document pdfWithCover.SaveAs("Complete-Document.pdf"); // Order matters - first PDF appears first // Supports merging unlimited PDF documents using IronPdf; var renderer = new ChromePdfRenderer(); // Generate main document from URL var mainPdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/"); // Merge cover page with main document // PdfDocument.Merge combines multiple PDFs seamlessly var pdfWithCover = PdfDocument.Merge(new PdfDocument("CoverPage.pdf"), mainPdf); // Save the complete document pdfWithCover.SaveAs("Complete-Document.pdf"); // Order matters - first PDF appears first // Supports merging unlimited PDF documents Imports IronPdf Private renderer = New ChromePdfRenderer() ' Generate main document from URL Private mainPdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/") ' Merge cover page with main document ' PdfDocument.Merge combines multiple PDFs seamlessly Private pdfWithCover = PdfDocument.Merge(New PdfDocument("CoverPage.pdf"), mainPdf) ' Save the complete document pdfWithCover.SaveAs("Complete-Document.pdf") ' Order matters - first PDF appears first ' Supports merging unlimited PDF documents $vbLabelText $csharpLabel Complete example: PDF Cover Page Implementation How to Add Watermarks to PDFs? Apply watermarks to generated PDF documents for security or branding purposes: using IronPdf; using IronPdf.Editing; var renderer = new ChromePdfRenderer(); // Generate PDF from URL var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf"); // Create text watermark with custom styling pdf.Watermark = new TextWatermark { Text = "CONFIDENTIAL", FontSize = 50, FontColor = IronSoftware.Drawing.Color.Red, Opacity = 50, // Semi-transparent HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Middle }; // Save watermarked PDF pdf.SaveAs("Watermarked-Document.pdf"); // Also supports image watermarks // Perfect for draft stamps or branding using IronPdf; using IronPdf.Editing; var renderer = new ChromePdfRenderer(); // Generate PDF from URL var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf"); // Create text watermark with custom styling pdf.Watermark = new TextWatermark { Text = "CONFIDENTIAL", FontSize = 50, FontColor = IronSoftware.Drawing.Color.Red, Opacity = 50, // Semi-transparent HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Middle }; // Save watermarked PDF pdf.SaveAs("Watermarked-Document.pdf"); // Also supports image watermarks // Perfect for draft stamps or branding Imports IronPdf Imports IronPdf.Editing Private renderer = New ChromePdfRenderer() ' Generate PDF from URL Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf") ' Create text watermark with custom styling pdf.Watermark = New TextWatermark With { .Text = "CONFIDENTIAL", .FontSize = 50, .FontColor = IronSoftware.Drawing.Color.Red, .Opacity = 50, .HorizontalAlignment = HorizontalAlignment.Center, .VerticalAlignment = VerticalAlignment.Middle } ' Save watermarked PDF pdf.SaveAs("Watermarked-Document.pdf") ' Also supports image watermarks ' Perfect for draft stamps or branding $vbLabelText $csharpLabel Complete guide: PDF Watermarking Tutorial Advanced PDF Security Features How to Password Protect PDFs in .NET? Secure sensitive generated PDF documents with passwords and permissions: using IronPdf; var renderer = new ChromePdfRenderer(); // Convert HTML to PDF first var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Report</h1>"); // Configure security settings pdf.SecuritySettings.UserPassword = "user123"; // Password to open pdf.SecuritySettings.OwnerPassword = "owner456"; // Password to modify // Set granular permissions pdf.SecuritySettings.AllowUserCopyPasteContent = false; pdf.SecuritySettings.AllowUserAnnotations = false; pdf.SecuritySettings.AllowUserPrinting = PrintPermissions.LowQualityPrint; // Apply strong encryption pdf.SecuritySettings.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES256; pdf.SaveAs("secure-document.pdf"); // Your HTML to PDF converter now creates encrypted PDFs // Perfect for sensitive business documents using IronPdf; var renderer = new ChromePdfRenderer(); // Convert HTML to PDF first var pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Report</h1>"); // Configure security settings pdf.SecuritySettings.UserPassword = "user123"; // Password to open pdf.SecuritySettings.OwnerPassword = "owner456"; // Password to modify // Set granular permissions pdf.SecuritySettings.AllowUserCopyPasteContent = false; pdf.SecuritySettings.AllowUserAnnotations = false; pdf.SecuritySettings.AllowUserPrinting = PrintPermissions.LowQualityPrint; // Apply strong encryption pdf.SecuritySettings.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES256; pdf.SaveAs("secure-document.pdf"); // Your HTML to PDF converter now creates encrypted PDFs // Perfect for sensitive business documents Imports IronPdf Private renderer = New ChromePdfRenderer() ' Convert HTML to PDF first Private pdf = renderer.RenderHtmlAsPdf("<h1>Confidential Report</h1>") ' Configure security settings pdf.SecuritySettings.UserPassword = "user123" ' Password to open pdf.SecuritySettings.OwnerPassword = "owner456" ' Password to modify ' Set granular permissions pdf.SecuritySettings.AllowUserCopyPasteContent = False pdf.SecuritySettings.AllowUserAnnotations = False pdf.SecuritySettings.AllowUserPrinting = PrintPermissions.LowQualityPrint ' Apply strong encryption pdf.SecuritySettings.EncryptionAlgorithm = PdfEncryptionAlgorithm.AES256 pdf.SaveAs("secure-document.pdf") ' Your HTML to PDF converter now creates encrypted PDFs ' Perfect for sensitive business documents $vbLabelText $csharpLabel How to Add Digital Signatures to PDFs? Add cryptographic signatures to ensure document authenticity: using IronPdf; using IronPdf.Signing; var renderer = new ChromePdfRenderer(); // Generate PDF from HTML var pdf = renderer.RenderHtmlAsPdf("<h1>Contract Agreement</h1>"); // Create digital signature with certificate var signature = new PdfSignature("certificate.pfx", "password") { SigningContact = "legal@company.com", SigningLocation = "New York, NY", SigningReason = "Contract Approval" }; // Apply signature to PDF pdf.Sign(signature); pdf.SaveAs("signed-contract.pdf"); // Digitally signed PDFs ensure authenticity // Required for legal and compliance documents using IronPdf; using IronPdf.Signing; var renderer = new ChromePdfRenderer(); // Generate PDF from HTML var pdf = renderer.RenderHtmlAsPdf("<h1>Contract Agreement</h1>"); // Create digital signature with certificate var signature = new PdfSignature("certificate.pfx", "password") { SigningContact = "legal@company.com", SigningLocation = "New York, NY", SigningReason = "Contract Approval" }; // Apply signature to PDF pdf.Sign(signature); pdf.SaveAs("signed-contract.pdf"); // Digitally signed PDFs ensure authenticity // Required for legal and compliance documents Imports IronPdf Imports IronPdf.Signing Private renderer = New ChromePdfRenderer() ' Generate PDF from HTML Private pdf = renderer.RenderHtmlAsPdf("<h1>Contract Agreement</h1>") ' Create digital signature with certificate Private signature = New PdfSignature("certificate.pfx", "password") With { .SigningContact = "legal@company.com", .SigningLocation = "New York, NY", .SigningReason = "Contract Approval" } ' Apply signature to PDF pdf.Sign(signature) pdf.SaveAs("signed-contract.pdf") ' Digitally signed PDFs ensure authenticity ' Required for legal and compliance documents $vbLabelText $csharpLabel Complete Digital Signatures Guide High-Performance PDF Generation IronPDF delivers enterprise-grade performance with full async and multithreading support for your HTML to PDF converter requirements. Async PDF Generation for Web Applications using IronPdf; using System.Threading.Tasks; // Async method for non-blocking PDF generation public async Task<byte[]> GeneratePdfAsync(string html) { var renderer = new ChromePdfRenderer(); // Async HTML to PDF conversion preserves thread pool var pdf = await renderer.RenderHtmlAsPdfAsync(html); // Return PDF as byte array for web responses return pdf.BinaryData; } // Concurrent batch PDF generation public async Task GenerateMultiplePdfsAsync(List<string> htmlTemplates) { var renderer = new ChromePdfRenderer(); // Create parallel conversion tasks var tasks = htmlTemplates.Select(html => renderer.RenderHtmlAsPdfAsync(html) ); // Await all conversions simultaneously var pdfs = await Task.WhenAll(tasks); // Save generated PDFs for (int i = 0; i < pdfs.Length; i++) { pdfs[i].SaveAs($"document-{i}.pdf"); } } // Async operations improve scalability // Essential for high-traffic web applications using IronPdf; using System.Threading.Tasks; // Async method for non-blocking PDF generation public async Task<byte[]> GeneratePdfAsync(string html) { var renderer = new ChromePdfRenderer(); // Async HTML to PDF conversion preserves thread pool var pdf = await renderer.RenderHtmlAsPdfAsync(html); // Return PDF as byte array for web responses return pdf.BinaryData; } // Concurrent batch PDF generation public async Task GenerateMultiplePdfsAsync(List<string> htmlTemplates) { var renderer = new ChromePdfRenderer(); // Create parallel conversion tasks var tasks = htmlTemplates.Select(html => renderer.RenderHtmlAsPdfAsync(html) ); // Await all conversions simultaneously var pdfs = await Task.WhenAll(tasks); // Save generated PDFs for (int i = 0; i < pdfs.Length; i++) { pdfs[i].SaveAs($"document-{i}.pdf"); } } // Async operations improve scalability // Essential for high-traffic web applications Imports IronPdf Imports System.Threading.Tasks ' Async method for non-blocking PDF generation Public Async Function GeneratePdfAsync(ByVal html As String) As Task(Of Byte()) Dim renderer = New ChromePdfRenderer() ' Async HTML to PDF conversion preserves thread pool Dim pdf = Await renderer.RenderHtmlAsPdfAsync(html) ' Return PDF as byte array for web responses Return pdf.BinaryData End Function ' Concurrent batch PDF generation Public Async Function GenerateMultiplePdfsAsync(ByVal htmlTemplates As List(Of String)) As Task Dim renderer = New ChromePdfRenderer() ' Create parallel conversion tasks Dim tasks = htmlTemplates.Select(Function(html) renderer.RenderHtmlAsPdfAsync(html)) ' Await all conversions simultaneously Dim pdfs = Await Task.WhenAll(tasks) ' Save generated PDFs For i As Integer = 0 To pdfs.Length - 1 pdfs(i).SaveAs($"document-{i}.pdf") Next i End Function ' Async operations improve scalability ' Essential for high-traffic web applications $vbLabelText $csharpLabel Performance Optimization Tips: Use 64-bit systems for optimal performance Ensure adequate server resources (avoid underpowered free tiers) Allow sufficient RenderDelay for complex JavaScript Reuse ChromePdfRenderer instances when possible View detailed system requirements Platform Compatibility IronPDF runs everywhere .NET runs: Frameworks: .NET 9, 8, 7, 6, 5, Core 3.1+, Framework 4.6.2+ Operating Systems: Windows 10+ (Desktop & Server) Linux (Ubuntu, Debian, CentOS, Amazon Linux) macOS 10.14+ Cloud Platforms: Azure (App Service, Functions, VMs) AWS (EC2, Lambda, ECS) Google Cloud Platform Docker & Kubernetes Application Types: ASP.NET Core & MVC Blazor, MAUI (Windows/macOS) WPF & Windows Forms Console Applications Microservices IronPDF for Other Programming Languages While this tutorial focuses on C# and .NET, IronPDF provides native support for additional platforms: Java Developers IronPDF for Java delivers identical pixel-perfect Chrome rendering for Java 8+, Kotlin, and Scala applications. Explore Java documentation Complete feature parity with .NET version Maven and Gradle support Python Developers IronPDF for Python brings HTML to PDF capabilities to Python 3+ applications using the same Chrome-based engine. Browse Python documentation pip installation available Compatible with Django, Flask, and other frameworks Distributed Architecture (gRPC) For microservices and distributed systems, IronPDF supports remote rendering via gRPC. Discover IronPdfEngine and gRPC Ideal for containerized environments Language-agnostic PDF generation All versions share the same powerful Chrome rendering engine, ensuring consistent, pixel-perfect generated PDF document output across all platforms. Download C# Source Code The complete free HTML to PDF converter C# source code for this tutorial is available as a Visual Studio 2022 project. It demonstrates using IronPDF's rendering engine to generate PDF documents in C#. Download this tutorial as a Visual Studio project The free download includes working C# code examples for: Converting HTML strings to PDF using C# HTML file to PDF conversion (supporting CSS, JavaScript, and images) URL to PDF conversion in C# PDF editing and configuration examples Rendering JavaScript charts (like d3.js) to PDF Complete PDF library implementation API Reference Explore the complete IronPDF API documentation: https://ironpdf.com/object-reference/api/ The API reference details how PDF documents can be: Encrypted and password protected Edited with new HTML content Enhanced with images and backgrounds Merged, split, and manipulated at page level Processed with OCR for text extraction Blazor HTML to PDF Adding HTML to PDF functionality to your Blazor server is straightforward: Create or use an existing Blazor server project Install IronPDF via NuGet Add a new Razor Component Connect an InputTextArea to IronPDF Deploy your PDF generation solution For detailed implementation, see the complete Blazor HTML to PDF tutorial. A Blazor server application using IronPDF to convert HTML content into PDF documents with real-time preview Compare IronPDF with Other .NET PDF Libraries IronPDF stands as the premier PDF converter library for modern .NET developers. With native HTML to PDF conversion powered by an advanced Chromium engine, intuitive APIs, and continuous updates, it streamlines development while ensuring professional results. Feature Comparison: IronPDF vs Other .NET PDF Generators Feature IronPDF wkhtmltopdf QuestPDF iText 7 PDFSharp Syncfusion Aspose.PDF Rendering Accuracy Pixel-Perfect Print-Style N/A Limited N/A Good Good HTML5 Support Full Outdated No Partial No Full Full CSS3 Support Full Limited Basic Partial No Full Full JavaScript Full No No Limited No Limited Limited Ease of Use High-Level API CLI Only Code-First Complex Low-Level Good Complex Server Install None Executable None None None None None Performance Fast + Async Slow Fast Fast Fast Fast Fast Support 24/7 Engineers Unmaintained Community Commercial Community Commercial Commercial License Commercial Open Source Commercial AGPL/Commercial MIT Commercial Commercial Price Range $749+ Free $599+ $1,999+ Free $2,995+ $2,499+ Key Differences: IronPDF produces PDFs that look exactly like Chrome when you convert HTML to PDF wkhtmltopdf uses outdated technology and creates print-style PDFs QuestPDF requires code-first approach with no HTML support (Now requires commercial license) iText 7 offers limited HTML/CSS support with AGPL licensing restrictions PDFSharp lacks HTML support entirely Syncfusion and Aspose.PDF provide good features but miss pixel-perfect Chrome rendering Important: Only IronPDF generates PDF documents matching your web design exactly. Others produce printer-friendly versions that often differ significantly from your intended layout. IronPDF vs PDFSharp Core Features: PDFSharp provides basic PDF creation and editing but lacks built-in HTML to PDF conversion, crucial for rendering web content accurately. Modern Standards: IronPDF leverages current web technologies through its Chromium engine, ensuring PDFs maintain contemporary design standards. Support & Updates: PDFSharp receives infrequent updates without official support, while IronPDF delivers monthly updates, security patches, and professional assistance. IronPDF vs wkhtmltopdf Integration Simplicity: wkhtmltopdf requires command-line configuration and manual dependencies, complicating .NET integration. Rendering Technology: wkhtmltopdf uses an outdated WebKit engine struggling with modern JavaScript and CSS. IronPDF's Chromium engine ensures accurate rendering. Development Status: wkhtmltopdf shows minimal activity since 2022 with limited support, while IronPDF continues active development with dedicated support. IronPDF vs iTextSharp HTML Rendering: The free iTextSharp version lacks native HTML to PDF conversion, forcing complex workarounds. IronPDF provides seamless conversion with full web technology support. Developer Experience: iTextSharp's low-level API increases development time. IronPDF offers an intuitive C# API accelerating project delivery. Maintenance: IronPDF provides professional support and regular updates, while iTextSharp's free version lacks official assistance. IronPDF vs Aspose.PDF Conversion Quality: Aspose.PDF's HTML to PDF conversion has limitations with modern CSS and JavaScript. Direct URL conversion isn't supported, requiring manual HTML downloads. Results often miss styling and dynamic content. IronPDF's Chromium engine guarantees accurate conversion of complex layouts. API Design: Aspose.PDF's verbose API increases complexity, while IronPDF emphasizes developer-friendly experiences minimizing setup time. Performance: IronPDF's optimized processing delivers faster conversions and superior performance for enterprise-scale PDF generation. IronPDF vs Syncfusion PDF API Simplicity: Syncfusion PDF's complex API can slow development. IronPDF provides straightforward integration for rapid deployment. Rendering Performance: While Syncfusion supports WebKit and Blink engines, testing shows slower performance than IronPDF's optimized Chromium engine. Syncfusion struggles with dynamic content and modern CSS. IronPDF ensures precise rendering for JavaScript-heavy sites. Advanced Capabilities: Beyond conversion, IronPDF includes digital signatures, annotations, forms, OCR, and barcode generation. Real-World Rendering Comparison To evaluate HTML to PDF conversion quality, we tested these libraries with Reddit's homepage containing dynamic content, modern CSS, and JavaScript HTML elements: https://www.reddit.com/ Reddit's homepage serves as an ideal test case with its dynamic content, complex CSS layouts, and JavaScript-driven features Results comparison (click images to enlarge): IronPDF IronPDF delivers pixel-perfect results, preserving all dynamic content, modern styling, and interactive elements exactly as displayed in Chrome. Syncfusion Syncfusion converted successfully but missed most sections and styling, especially dynamic content. Initially blocked by Reddit's security. Achieving better results requires extensive command-line tuning, yet output remains incomplete. Aspose.PDF Aspose.PDF required manual HTML download first (no direct URL support). After conversion, output lacked proper formatting and missed nearly all content sections, making it unsuitable for modern web pages. wkhtmltopdf wkhtmltopdf completed quickly but produced a plain, static page missing critical content like live updates, dynamic elements, and interactive sections. This demonstrates wkhtmltopdf's incompatibility with modern, JavaScript-driven websites. Note: PDFSharp and iTextSharp lack native HTML to PDF conversion capabilities and were excluded from this comparison. Developers using these libraries must rely on third-party tools for HTML rendering. Performance and Quality Verdict For .NET developers requiring a modern, reliable PDF converter, IronPDF leads the market. Its seamless HTML to PDF conversion, developer-friendly API, continuous updates, and comprehensive features make it the optimal choice. In real-world testing with dynamic websites, IronPDF delivered the fastest, most accurate results. Syncfusion was slower and missed critical sections. Aspose required manual HTML code downloads and still failed proper rendering. wkhtmltopdf produced static content without capturing modern styling. This confirms IronPDF offers the superior balance of speed, accuracy, and ease of use for modern HTML to PDF workflows. Experience IronPDF's complete feature suite that converts dynamic, CSS-heavy HTML to PDF effortlessly—start your free trial today. Troubleshooting & Support Encountering issues with your HTML to PDF converter? IronPDF provides 24/7 support from real software engineers via the chat widget on any ironpdf.com page. Common solutions: Initial render slowness? Normal behavior (2-3 seconds) as Chrome initializes. Subsequent conversions are much faster. Insufficient cloud resources? IronPDF requires adequate computing power. Use at least B1 tier on Azure or equivalent. Assets not loading? Configure base paths or embed resources as base64 in your HTML code. HTML elements missing? Ensure sufficient JavaScript execution time using RenderDelay. Quick Links Comprehensive troubleshooting guide Performance optimization strategies Engineering support requests Quick troubleshooting checklist Summary IronPDF provides the leading C# PDF converter library for generating PDFs from HTML, delivering: Pixel-perfect Chrome rendering - Generated PDF documents match web pages exactly Full modern web support - CSS3, HTML5, JavaScript, all HTML elements supported Simple yet powerful API - Intuitive HTML to PDF converter with advanced features Zero server dependencies - Install and immediately convert HTML to PDF 24/7 engineer support - Professional assistance when needed Getting Started Install IronPDF via NuGet - No license required for development Try the quick start examples to convert HTML to PDF Get a free 30-day trial for production deployment Browse additional examples of HTML to PDF conversion Read complete documentation for advanced features Whether building invoices, reports, archives, or any document generation system, IronPDF provides the accurate, reliable HTML to PDF converter foundation your project needs. Consider the Iron Suite for additional .NET productivity tools including Excel, Word, OCR, QR codes, and more at significant bundle savings. Get stated with IronPDF now. Start for Free Please noteAspose, SyncFusion, and wkhtmltopdf are registered trademarks of their respective owner. This site is not affiliated with, endorsed by, or sponsored by Aspose, SyncFusion, or wkhtmltopdf. All product names, logos, and brands are property of their respective owners. Comparisons are for informational purposes only and reflect publicly available information at the time of writing. Frequently Asked Questions How do I convert HTML to PDF in C#? You can convert HTML to PDF using the ChromePdfRenderer class and its RenderHtmlAsPdf method. Simply create a renderer instance, pass your HTML string to the method, and save the resulting PDF using SaveAs. Can I convert a URL directly to PDF? Yes, use the RenderUrlAsPdf method to convert any web page URL directly to a PDF document. This preserves all styling, images, and even interactive elements like forms and hyperlinks. How do I handle JavaScript content when converting to PDF? Enable JavaScript rendering by setting RenderingOptions.EnableJavaScript = true and add a render delay using RenderingOptions.WaitFor.RenderDelay to ensure dynamic content loads completely before conversion. What's the best way to add headers and footers to PDFs? Use the TextHeaderFooter class for simple text headers or HtmlHeaderFooter for rich HTML content. You can include dynamic placeholders like {page}, {total-pages}, and {date} for automatic content. How can I generate multiple PDFs from templates? Create HTML templates with placeholders, then use string replacement or templating libraries like Handlebars.NET. Loop through your data, replace placeholders with actual values, and use RenderHtmlAsPdf to generate personalized PDFs. Is it possible to password protect generated PDFs? Yes, use the SecuritySettings property to set user and owner passwords, configure permissions like printing and copying, and apply AES256 encryption using SecuritySettings.EncryptionAlgorithm. How do I optimize performance for high-volume PDF generation? Use async methods like RenderHtmlAsPdfAsync for non-blocking operations, reuse ChromePdfRenderer instances, process multiple PDFs concurrently with Task.WhenAll, and ensure adequate server resources on 64-bit systems. Can I control page breaks in my PDF output? Yes, use CSS properties page-break-after: always and page-break-inside: avoid within a print media type CSS block to control exactly where pages break in your generated PDFs. What paper sizes and orientations are supported? Set paper size using RenderingOptions.PaperSize (supports A4, Letter, Legal, etc.) and orientation with RenderingOptions.PaperOrientation for Portrait or Landscape. Custom sizes in millimeters or inches are also supported. How do I merge multiple PDFs or add cover pages? Use the static PdfDocument.Merge method to combine multiple PDF documents. Generate your cover page separately, then merge it with your main document to create a complete PDF with cover. How does this library compare to free alternatives like wkhtmltopdf? Unlike wkhtmltopdf's outdated WebKit engine, this library uses modern Chrome rendering for pixel-perfect PDFs. It requires no server executables, supports full JavaScript/CSS3, receives regular updates, and includes professional support - while wkhtmltopdf is unmaintained since 2022. What advantages does this offer over PDFSharp? PDFSharp lacks built-in HTML to PDF conversion entirely, requiring complex workarounds. This library provides direct HTML/URL/file conversion with a high-level API, modern web technology support, and regular updates with professional assistance. Is this a better choice than iTextSharp for HTML conversion? Yes, the free iTextSharp version doesn't support native HTML to PDF conversion and has a complex low-level API. This library offers seamless HTML conversion with an intuitive API, full CSS3/JavaScript support, and doesn't have AGPL licensing restrictions. How does rendering quality compare to Aspose.PDF? This library produces pixel-perfect Chrome-quality PDFs while Aspose.PDF often misses styling and dynamic content. Additionally, Aspose requires manual HTML downloads for URL conversion, whereas this library converts URLs directly with superior accuracy. Why choose this over Syncfusion PDF? While Syncfusion is capable, testing shows its Blink engine performs slower and struggles with dynamic content compared to this library's optimized Chrome engine. This library also provides a simpler API and includes advanced features like OCR and barcode generation. Jacob Mellor Chat with engineering team now Chief Technology Officer Jacob Mellor is Chief Technology Officer at Iron Software and a visionary engineer pioneering C# PDF technology. As the original developer behind Iron Software's core codebase, he has shaped the company's product architecture since its inception, transforming it alongside CEO Cameron Rimington into a 50+ person company serving NASA, Tesla, and global government agencies.Jacob holds a First-Class Honours Bachelor of Engineering (BEng) in Civil Engineering from the University of Manchester (1998–2001). After opening his first software business in London in 1999 and creating his first .NET components in 2005, he specialized in solving complex problems across the Microsoft ecosystem.His flagship IronPDF & IronSuite .NET libraries have achieved over 30 million NuGet installations globally, with his foundational code continuing to power developer tools used worldwide. With 25 years of commercial experience and 41 years of coding expertise, Jacob remains focused on driving innovation in enterprise-grade C#, Java, and Python PDF technologies while mentoring the next generation of technical leaders. Reviewed by Jeffrey T. Fritz Principal Program Manager - .NET Community Team Jeff is also a Principal Program Manager for the .NET and Visual Studio teams. He is the executive producer of the .NET Conf virtual conference series and hosts 'Fritz and Friends' a live stream for developers that airs twice weekly where he talks tech and writes code together with viewers. Jeff writes workshops, presentations, and plans content for the largest Microsoft developer events including Microsoft Build, Microsoft Ignite, .NET Conf, and the Microsoft MVP Summit Comments 12 May, 2025 csharpBuilderX says: Prompt replies and accurate help. Support experience was top notch! 11 May, 2025 Daniel N. says: Handled everything super quickly. Didn’t expect it to be this smooth. 9 May, 2025 Leila G. says: Was guided through the issue patiently and clearly. Top-tier support. 7 May, 2025 johnny_dev87 says: Support was kind, helpful, and stayed with me until it was resolved. Great job! 4 May, 2025 Theo B. says: Fast response, understood the issue in seconds. Appreciate the no-fuss resolution. 29 April, 2025 megan.codes says: Excellent customer experience. Felt like someone really listened and helped. 27 April, 2025 Matt Mariano says: Very easy process. Thanks much 21 April, 2025 Ajay V. says: Thanks for the speedy help and smooth conversation. Got what I needed without stress. 19 April, 2025 Matt Mariano says: Very easy process. Thanks much 12 April, 2025 Santosh Ramareddy says: Understood and was able to guide me easily 4 April, 2025 Rob Davis says: Instantly helped me with my issue and waiting for me to test. Very happy with the service I received 3 April, 2025 harry_devtools says: Support team knew exactly what to do. Quick, efficient, and polite throughout. 30 March, 2025 Chris Derham says: Resolved the issue with no pain. Great job. You should give your support team a pay rise! 22 March, 2025 Varonique Philander says: I was able to get the information I required. Thank you. 11 March, 2025 Jan Dolezalek says: Quick response from Support. Issue is getting resolved immediately. 4 March, 2025 Henrik Melchander says: Quick and clear 25 February, 2025 Aayush Raj says: Masterpiece 15 February, 2025 Doug Charbonneau says: Support took quite a bit of time to work with me through the issues. Was about to give up, so may have saved a sale!!! 1 February, 2025 Rod Rencoret says: goat supporting, great service. thank you. 19 January, 2025 Beugin says: Simple and Efficient. 3 January, 2025 William Mayerchak says: Good article, good response time. 18 September, 2024 Abby Fields says: Honestly, not bad. The explanations were clear, and I like that the examples can be copied and pasted directly. Not every doc does that well. One suggestion: add a section on integrating with Razor views. 8 June, 2024 Leo Fernandez says: I was looking for a way to convert dynamic HTML templates to PDF without compromising CSS styling, and this tutorial nailed it. Everything I needed was right there. Even the licensing section helped clear up some confusion I had. 17 January, 2024 iAmNick_C says: Straightforward, which I appreciate. PDFs come out looking sharp too. 30 November, 2023 user12345 says: PDFs now printing in the right margins, finally. Thanks! 3 October, 2023 Oscar Vega says: If you're using .NET and looking to turn HTML into PDFs without losing your mind, this guide is a solid bet. Easy integration, no weird dependencies. Just add the package and go. 11 June, 2023 skywalker.dev says: I was up and running before my coffee cooled down. That’s saying something! 21 April, 2023 Vanessa Li says: The tutorial was surprisingly thorough. I appreciated the attention to detail, especially when it came to rendering styles and fonts. We use IronPDF in a fairly large enterprise app and it hasn't disappointed us yet. 2 January, 2023 theRealCSharpNerd says: Solid walkthrough. IronPDF has a weird learning curve, but this made it way easier to wrap my head around. 27 August, 2022 Nadia Hassan says: Decent resource. Could use more coverage of edge cases, but it’s a strong starting point for most devs. 14 March, 2022 Tina Q. says: It’s okay. I expected more advanced use cases, like adding bookmarks or TOCs dynamically. But overall, it got me started. 9 February, 2022 Priya Chatterjee says: I like how this doesn’t assume too much. It’s beginner-friendly but still useful for devs like me who just want to confirm best practices. Nicely done. 13 November, 2021 dev_mike89 says: Works like a charm. Got it running in 10 minutes! 11 May, 2021 Harvey Becker says: Used this for an internal reporting dashboard project. It worked well out of the box. Would love to see some async handling examples for long render jobs. 4 November, 2020 lucy_d_coder says: Clean and simple. I like that. 5 July, 2020 Jacob.Stone says: Wish I found this sooner. Saved me a ton of trial and error. 29 April, 2020 Benito Reyes says: Could use more Razor Pages examples. Still, the tutorial gives you all the right pieces to make it work. 10 February, 2020 xXJoelXx says: Just two words: life saver. 8 October, 2019 Laura Meyers says: I’ve been using IronPDF for a couple of years now. Every time I revisit the docs, they’ve improved. This HTML to PDF tutorial is no exception—well-organized and very developer-friendly. 20 September, 2019 CodeWithMarla says: Old school dev here. IronPDF isn’t too shabby. This tutorial had enough meat to get me going without googling every five minutes. 25 June, 2018 Matt R. says: This guide was helpful for me when migrating from another PDF engine. The part on styling support with embedded CSS was gold. View All Comments Leave a comment Ready to Get Started? Free NuGet Download Total downloads: 14,631,247 View Licenses