HTML to PDF in C# .NET
As the developers of IronPDF, we know how important it is for HTML-to-PDF conversion to produce accurate, high-quality results that meet customer expectations. This C# tutorial will guide you through building an HTML-to-PDF converter for your applications, projects, and websites. We will develop a C# HTML-to-PDF converter, and the output PDF documents from IronPDF will be pixel perfect to the PDFs generated by the Google Chrome web browser.
Get started making PDFs now!
IronPdf.ChromePdfRenderer
.StaticRenderHtmlAsPdf("<p>Hello Word</p>")
.SaveAs("pixelperfect.pdf");
Overview
How to Convert HTML to PDF in C#

HTML to PDF Converter for C# & VB.NET
Creating PDF files programmatically in .NET can be a frustrating task. The PDF document file format was designed more for printers than for developers. And C# doesn't have many suitable libraries or features for PDF generation built-in, many of the libraries that are on the market do not work out-of-the-box, and cause further frustration when they require multiple lines of code to accomplish a simple task.
The C# HTML to PDF conversion tool we will be using in this tutorial is IronPDF by Iron Software, a highly popular C# PDF generation and editing library. This library has comprehensive PDF editing and generation functionality, works completely out-of-the-box, does exactly what you need it to do in the least amount of lines, and has outstanding documentation of its 50+ features. IronPDF stands out in that it supports .NET 9, .NET 8, .NET 7, .NET 6, and .NET 5, .NET Core, Standard, and Framework on Windows, macOS, Linux, Docker, Azure, and AWS.
With C# and IronPDF, the logic to "generate a PDF document" or "HTML to PDF conversion" is straightforward. Because of IronPDF's advanced Chrome Renderer, most or all of the PDF document design and layout will use existing HTML assets.
This method of dynamic PDF generation in .NET with HTML5 works equally well in console applications, windows forms applications, WPF, as well as websites and MVC.
IronPDF also supports debugging of your HTML with Chrome for Pixel Perfect PDFs. A tutorial for setting this up can be found here.
IronPDF works in multiples language from outside and within the .NET ecosystem.
IronPDF requires a trial or paid license to function. You can buy a license here or sign up for a free 30 day trial key here.
Step 1
Download and Install the HTML to PDF C# Library
Visual Studio - NuGet Package Manager
In Visual Studio, right click on your project solution explorer and select Manage NuGet Packages...
, From there simply search for IronPDF and install the latest version to your solution... click OK to any dialog boxes that come up. This will also work just as well in VB.NET projects.
Install-Package IronPdf
IronPDF on NuGet Website
For a comprehensive rundown of IronPDF's features, compatibility, and downloads, please check out IronPDF on NuGet's official website: https://www.nuget.org/packages/IronPdf
Install via DLL
Another option is to install the IronPDF DLL directly. IronPDF can be downloaded and manually installed to the project or GAC from https://ironpdf.com/packages/IronPdf.zip
How to Tutorials
Create a PDF with an HTML String in C# .NET
How to: Convert HTML String to PDF? It is a very efficient and rewarding skill to create a new PDF file in C#.
We can simply use the ChromePdfRenderer.RenderHtmlAsPdf method to turn any HTML (HTML5) string into a PDF. C# HTML to PDF rendering is undertaken by a fully functional version of the Google Chromium engine, embedded within IronPDF DLL.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-1.cs
// Import the necessary namespace from the IronPdf library
using IronPdf;
// Create a new instance of the ChromePdfRenderer class.
// This class is used to render HTML content to a PDF file.
var renderer = new ChromePdfRenderer();
// Use the renderer to convert a simple HTML string into a PDF document.
// The RenderHtmlAsPdf method takes an HTML string as an argument and renders it as a PDF.
var pdfDocument = renderer.RenderHtmlAsPdf("<h1> Hello IronPdf </h1>");
// Save the rendered PDF document to a file named "pixel-perfect.pdf".
// The SaveAs method takes a file path as an argument where the PDF will be saved.
pdfDocument.SaveAs("pixel-perfect.pdf");
' Import the necessary namespace from the IronPdf library
Imports IronPdf
' Create a new instance of the ChromePdfRenderer class.
' This class is used to render HTML content to a PDF file.
Private renderer = New ChromePdfRenderer()
' Use the renderer to convert a simple HTML string into a PDF document.
' The RenderHtmlAsPdf method takes an HTML string as an argument and renders it as a PDF.
Private pdfDocument = renderer.RenderHtmlAsPdf("<h1> Hello IronPdf </h1>")
' Save the rendered PDF document to a file named "pixel-perfect.pdf".
' The SaveAs method takes a file path as an argument where the PDF will be saved.
pdfDocument.SaveAs("pixel-perfect.pdf")
RenderHtmlAsPdf
fully supports HTML5, CSS3, JavaScript, and images. If these assets are on a hard disk, we may want to set the second parameter of RenderHtmlAsPdf
to the directory containing the assets. This method returns a PdfDocument object, which is a class used to hold PDF information.
IronPDF will render your HTML exactly as it appears in Chrome
We have a full tutorial dedicated to allowing you to set up Chrome for full HTML debugging to make sure the changes you see there when editing your HTML, CSS, and JavaScript are pixel-perfect the same as the output PDF from IronPDF when you choose to render. Please find the tutorial here: How to Debug HTML in Chrome to Create Pixel Perfect PDFs.
BaseUrlPath
:
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-2.cs
using IronPdf;
// Create an instance of HtmlToPdf renderer
var renderer = new HtmlToPdf();
// Render a PDF from an HTML string that includes an image tag
// - The `RenderHtmlAsPdf` method takes:
// 1. The HTML content to be rendered.
// 2. The base path for local resources like images.
// - In this example, the HTML contains an image tag with a relative path.
// The renderer uses the base path to locate the image file.
var pdf = renderer.RenderHtmlAsPdf("<img src='image1.png'/>", @"C:\MyProject\Assets\");
// Save the generated PDF to a file
// - The file will be saved in the specified directory with the given name.
// - Ensure the directory exists and the application has the necessary permissions
// to write files to the location.
pdf.SaveAs(@"C:\MyProject\Assets\output.pdf");
// Notes:
// 1. Ensure the IronPdf library is properly referenced in your project.
// You can typically do this via NuGet Package Manager by installing IronPdf.
// 2. The image path specified within the HTML must be relative to the base path provided.
// The base path is meant to direct the renderer to the correct location of images and other resources.
// 3. The resultant PDF is saved to "C:\MyProject\Assets\output.pdf".
// Verify that the given path is correct and accessible.
Imports IronPdf
' Create an instance of HtmlToPdf renderer
Private renderer = New HtmlToPdf()
' Render a PDF from an HTML string that includes an image tag
' - The `RenderHtmlAsPdf` method takes:
' 1. The HTML content to be rendered.
' 2. The base path for local resources like images.
' - In this example, the HTML contains an image tag with a relative path.
' The renderer uses the base path to locate the image file.
Private pdf = renderer.RenderHtmlAsPdf("<img src='image1.png'/>", "C:\MyProject\Assets\")
' Save the generated PDF to a file
' - The file will be saved in the specified directory with the given name.
' - Ensure the directory exists and the application has the necessary permissions
' to write files to the location.
pdf.SaveAs("C:\MyProject\Assets\output.pdf")
' Notes:
' 1. Ensure the IronPdf library is properly referenced in your project.
' You can typically do this via NuGet Package Manager by installing IronPdf.
' 2. The image path specified within the HTML must be relative to the base path provided.
' The base path is meant to direct the renderer to the correct location of images and other resources.
' 3. The resultant PDF is saved to "C:\MyProject\Assets\output.pdf".
' Verify that the given path is correct and accessible.
All referenced CSS stylesheets, images and JavaScript files will be relative to the BaseUrlPath
and can be kept in a neat and logical structure. You may also, of course, opt to reference images, stylesheets, and assets online, including web-fonts such as Google Fonts and even jQuery.
Export a PDF Using Existing URL
Rendering existing URLs as PDFs with C# is very efficient and intuitive. This also allows teams to split PDF design and back-end PDF rendering work across multiple teams.
Let's render a page from Wikipedia.com in the following example:
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-3.cs
using IronPdf; // Import the IronPdf library to work with PDF creation and manipulation
// Create an instance of ChromePdfRenderer to convert web pages into PDF format
var renderer = new ChromePdfRenderer();
// RenderUrlAsPdf method creates a PDF from the content of the specified URL.
// In this case, it converts the Wikipedia page about PDFs into a PDF document.
var pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/PDF");
// Save the created PDF to the local filesystem with a specific filename.
pdf.SaveAs("wikipedia.pdf");
// Note:
// - Ensure that the IronPdf NuGet package is installed in your project to use the IronPdf namespace.
// - The output PDF will be saved in the same directory where the executable runs.
Imports IronPdf ' Import the IronPdf library to work with PDF creation and manipulation
' Create an instance of ChromePdfRenderer to convert web pages into PDF format
Private renderer = New ChromePdfRenderer()
' RenderUrlAsPdf method creates a PDF from the content of the specified URL.
' In this case, it converts the Wikipedia page about PDFs into a PDF document.
Private pdf = renderer.RenderUrlAsPdf("https://en.wikipedia.org/wiki/PDF")
' Save the created PDF to the local filesystem with a specific filename.
pdf.SaveAs("wikipedia.pdf")
' Note:
' - Ensure that the IronPdf NuGet package is installed in your project to use the IronPdf namespace.
' - The output PDF will be saved in the same directory where the executable runs.
You will notice that hyperlinks and even HTML forms are preserved within the PDF generated by our C# code.
When rendering existing web pages we have some tricks we may wish to apply:
Print and Screen CSS
In modern CSS3 we have css directives for both print and screen. We can instruct IronPDF to render "Print" CSSs which are often simplified or overlooked. By default "Screen" CSS styles will be rendered, which IronPDF users have found most intuitive.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-4.cs
// Import necessary namespaces for using IronPdf functionalities
using IronPdf.Rendering;
// Initialize a new instance of the HtmlToPdf class to create a PDF document
var renderer = new HtmlToPdf();
// Set the CSS media type option for rendering
// CssMediaType.Screen is suitable for screen display formatting
// CssMediaType.Print is suitable for print formatting
// Only one of these options should be uncommented at a time
// Uncomment one of the following lines depending on your desired media type
// renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Screen;
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
// Note:
// The code sets a CSS media type to influence how the HTML content is formatted and displayed in the resulting PDF.
// PdfCssMediaType.Screen and PdfCssMediaType.Print are enum values provided by IronPdf to choose different rendering styles.
// Ensure that 'renderer' is a properly instantiated HtmlToPdf object, as shown above.
' Import necessary namespaces for using IronPdf functionalities
Imports IronPdf.Rendering
' Initialize a new instance of the HtmlToPdf class to create a PDF document
Private renderer = New HtmlToPdf()
' Set the CSS media type option for rendering
' CssMediaType.Screen is suitable for screen display formatting
' CssMediaType.Print is suitable for print formatting
' Only one of these options should be uncommented at a time
' Uncomment one of the following lines depending on your desired media type
' renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Screen;
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print
' Note:
' The code sets a CSS media type to influence how the HTML content is formatted and displayed in the resulting PDF.
' PdfCssMediaType.Screen and PdfCssMediaType.Print are enum values provided by IronPdf to choose different rendering styles.
' Ensure that 'renderer' is a properly instantiated HtmlToPdf object, as shown above.
Main Article: Pixel Perfect HTML to PDF Comparison.
JavaScript
IronPDF supports JavaScript, jQuery and even AJAX. We may need to instruct IronPDF to wait for JS or ajax to finish running before rendering a snapshot of our web-page.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-5.cs
// This code snippet appears to belong to a broader context dealing with rendering or web requests.
// Based on the clues, we can assume that 'renderer' is an object dealing with rendering operations,
// possibly in a web browser automation or document rendering service, like a headless browser tool.
using System;
namespace RenderingExample
{
// The 'renderer' object is presumed to represent some rendering system with configurable options.
// Here, we show a plausible configuration of rendering options using imagined classes and methods.
// Assuming necessary using directives based on typical rendering tools (like puppeteer-sharp for C#)
// Enable JavaScript execution for the rendering operation (if supported by the rendering library).
// This usually allows the rendering process to execute scripts, load dynamic content, etc.
renderer.RenderingOptions.EnableJavaScript = true;
// Set a delay for the rendering operation to ensure that JavaScript operations (like AJAX requests)
// or content rendering is fully completed before taking a snapshot of the page or processing it.
renderer.RenderingOptions.WaitFor = new WaitForOptions
{
// Assume RenderDelay is a property that defines a wait time in milliseconds before rendering.
RenderDelay = 500 // Setting a rendering delay of 500 milliseconds.
};
// Defining WaitForOptions class to illustrate the use of a render delay setting.
// This class should typically reside in its own file or the proper namespace.
public class WaitForOptions
{
// Property to specify the render delay in milliseconds.
public int RenderDelay { get; set; }
}
}
// Note: The exact implementation may vary depending on the library being used for rendering.
// This setup provides a high-level overview and hypothetical implementation for illustration purposes.
' This code snippet appears to belong to a broader context dealing with rendering or web requests.
' Based on the clues, we can assume that 'renderer' is an object dealing with rendering operations,
' possibly in a web browser automation or document rendering service, like a headless browser tool.
Imports System
Namespace RenderingExample
' The 'renderer' object is presumed to represent some rendering system with configurable options.
' Here, we show a plausible configuration of rendering options using imagined classes and methods.
' Assuming necessary using directives based on typical rendering tools (like puppeteer-sharp for C#)
' Enable JavaScript execution for the rendering operation (if supported by the rendering library).
' This usually allows the rendering process to execute scripts, load dynamic content, etc.
renderer.RenderingOptions.EnableJavaScript = True
' Set a delay for the rendering operation to ensure that JavaScript operations (like AJAX requests)
' or content rendering is fully completed before taking a snapshot of the page or processing it.
renderer.RenderingOptions.WaitFor = New WaitForOptions With {.RenderDelay = 500}
' Defining WaitForOptions class to illustrate the use of a render delay setting.
' This class should typically reside in its own file or the proper namespace.
'INSTANT VB TODO TASK: Local functions are not converted by Instant VB:
' public class WaitForOptions
' {
' ' Property to specify the render delay in milliseconds.
' public int RenderDelay
' {
' get;
' set;
' }
' }
End Namespace
' Note: The exact implementation may vary depending on the library being used for rendering.
' This setup provides a high-level overview and hypothetical implementation for illustration purposes.
We can demonstrate compliance with the JavaScript standard by rendering an advanced d3.js JavaScript chord chart from a CSV dataset like this:
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-6.cs
using IronPdf;
// This script uses the IronPdf library to render a webpage as a PDF document.
// Create an instance of ChromePdfRenderer, which uses a headless version of Chrome
// to accurately render HTML content into a PDF format.
var renderer = new ChromePdfRenderer();
// Call the RenderUrlAsPdf method on the renderer object with a specific URL.
// The URL leads to a D3.js data visualization, which will be fetched and rendered as a PDF.
var pdf = renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006");
// After the PDF is rendered, save it to the local filesystem.
// The PDF document will be saved with the name "chart.pdf" in the current working directory.
pdf.SaveAs("chart.pdf");
// Note:
// - Ensure that the IronPdf NuGet package is installed and referenced in your project to access these functionalities.
// - The URL must be accessible publicly. Ensure network connectivity for the URL to fetch the content successfully.
// - Handle any exceptions that may arise during the execution for a production-ready solution.
Imports IronPdf
' This script uses the IronPdf library to render a webpage as a PDF document.
' Create an instance of ChromePdfRenderer, which uses a headless version of Chrome
' to accurately render HTML content into a PDF format.
Private renderer = New ChromePdfRenderer()
' Call the RenderUrlAsPdf method on the renderer object with a specific URL.
' The URL leads to a D3.js data visualization, which will be fetched and rendered as a PDF.
Private pdf = renderer.RenderUrlAsPdf("https://bl.ocks.org/mbostock/4062006")
' After the PDF is rendered, save it to the local filesystem.
' The PDF document will be saved with the name "chart.pdf" in the current working directory.
pdf.SaveAs("chart.pdf")
' Note:
' - Ensure that the IronPdf NuGet package is installed and referenced in your project to access these functionalities.
' - The URL must be accessible publicly. Ensure network connectivity for the URL to fetch the content successfully.
' - Handle any exceptions that may arise during the execution for a production-ready solution.
Responsive CSS
HTML to PDF using response CSS in .NET! Responsive web pages are designed to be viewed in a browser. IronPDF does not open a real browser window within your server's OS. This can lead to responsive elements rendering at their smallest size.
We recommend using Print css media types to navigate this issue. Print CSS should not normally be responsive.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-7.cs
// This line of code sets the CSS media type for PDF rendering to 'Print'.
// It's used when rendering PDF documents with IronPdf to apply specific styles that are optimized for print media.
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print;
' This line of code sets the CSS media type for PDF rendering to 'Print'.
' It's used when rendering PDF documents with IronPdf to apply specific styles that are optimized for print media.
renderer.RenderingOptions.CssMediaType = IronPdf.Rendering.PdfCssMediaType.Print
Generate a PDF from a HTML Page
We can also render any HTML page to PDF on our hard disk. All relative assets such as CSS, images and js will be rendered as if the file had been opened using the file:// protocol.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-8.cs
// Import the IronPdf library to work with PDF files
using IronPdf;
// Instantiate a ChromePdfRenderer, which will be used to render HTML to PDF.
var renderer = new ChromePdfRenderer();
// Render the HTML content from the specified HTML file into a PDF document.
// 'RenderHtmlFileAsPdf' method takes a file path to an HTML document and converts it to PDF.
var pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html");
// Save the generated PDF to a file called "Invoice.pdf" in the current working directory.
// The 'SaveAs' method takes a string file path where the PDF will be saved.
pdf.SaveAs("Invoice.pdf");
' Import the IronPdf library to work with PDF files
Imports IronPdf
' Instantiate a ChromePdfRenderer, which will be used to render HTML to PDF.
Private renderer = New ChromePdfRenderer()
' Render the HTML content from the specified HTML file into a PDF document.
' 'RenderHtmlFileAsPdf' method takes a file path to an HTML document and converts it to PDF.
Private pdf = renderer.RenderHtmlFileAsPdf("Assets/TestInvoice1.html")
' Save the generated PDF to a file called "Invoice.pdf" in the current working directory.
' The 'SaveAs' method takes a string file path where the PDF will be saved.
pdf.SaveAs("Invoice.pdf")
This method has the advantage of allowing the developer the opportunity to test the HTML content in a browser during development. We recommend Chrome as it is the web browser on which IronPDF's rendering engine is based.
To convert XML to PDF you can use XSLT templating to print your XML content to PDF.
Add Custom Headers and Footers
Headers and footers can be added to PDFs when they are rendered, or to existing PDF files using IronPDF.
With IronPDF, Headers and footers can contain simple text based content using the TextHeaderFooter
class - or with images and rich HTML content using the HtmlHeaderFooter
class.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-9.cs
using IronPdf;
// Create a PDF from an existing HTML file with specified rendering options
var renderer = new ChromePdfRenderer
{
// Set rendering options such as margins, CSS media type, and header/footer details
RenderingOptions = new PdfDocumentOptions
{
// Margins in millimeters
MarginTop = 50,
MarginBottom = 50,
// Set CSS media type to 'Print'
CssMediaType = PdfCssMediaType.Print,
// Define header details
TextHeader = new HtmlHeaderFooter
{
CenterText = "{pdf-title}", // Title of the PDF
DrawDividerLine = true, // Draw a line below the header
FontSize = 16 // Font size for header content
},
// Define footer details
TextFooter = new HtmlHeaderFooter
{
LeftText = "{date} {time}", // Show the current date and time on the left
RightText = "Page {page} of {total-pages}", // Show pagination on the right
DrawDividerLine = true, // Draw a line above the footer
FontSize = 14 // Font size for footer content
}
}
};
// Render the HTML from the specified file as a PDF document
var pdf = renderer.RenderHtmlFileAsPdf("assets/TestInvoice1.html");
// Save the rendered PDF to the specified file path
pdf.SaveAs("Invoice.pdf");
// Open the generated PDF file using the default PDF viewer
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
{
FileName = "Invoice.pdf",
UseShellExecute = true
});
Imports IronPdf
' Create a PDF from an existing HTML file with specified rendering options
Private renderer = New ChromePdfRenderer With {
.RenderingOptions = New PdfDocumentOptions With {
.MarginTop = 50, .MarginBottom = 50, .CssMediaType = PdfCssMediaType.Print, .TextHeader = New HtmlHeaderFooter With {
.CenterText = "{pdf-title}",
.DrawDividerLine = True,
.FontSize = 16
},
.TextFooter = New HtmlHeaderFooter With {
.LeftText = "{date} {time}",
.RightText = "Page {page} of {total-pages}",
.DrawDividerLine = True,
.FontSize = 14
}
}
}
' Render the HTML from the specified file as a PDF document
Private pdf = renderer.RenderHtmlFileAsPdf("assets/TestInvoice1.html")
' Save the rendered PDF to the specified file path
pdf.SaveAs("Invoice.pdf")
' Open the generated PDF file using the default PDF viewer
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo With {
.FileName = "Invoice.pdf",
.UseShellExecute = True
})
Explore all rendering options in the following how-to article: How to Use the Rendering Options.
HTML Headers and Footers
The HtmlHeaderFooter
class allows for rich headers and footers to be generated using HTML5 content which may even include images, stylesheets and hyperlinks.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-10.cs
using IronPdf;
// The following code sets up a footer for a PDF using IronPdf, a library for rendering HTML to PDF.
// The footer is configured to show the current page number and total number of pages, formatted with HTML.
// It uses HtmlHeaderFooter to set the footer content with HTML and styling.
// Create an instance of the HtmlToPdf renderer
HtmlToPdf renderer = new HtmlToPdf();
// Configure the rendering options for the PDF
renderer.RenderingOptions.Footer = new HtmlHeaderFooter()
{
// Define the HTML content for the footer
HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>"
// The {page} and {total-pages} are special tokens that will be replaced by
// the current page number and the total number of pages in the PDF, respectively.
};
Imports IronPdf
' The following code sets up a footer for a PDF using IronPdf, a library for rendering HTML to PDF.
' The footer is configured to show the current page number and total number of pages, formatted with HTML.
' It uses HtmlHeaderFooter to set the footer content with HTML and styling.
' Create an instance of the HtmlToPdf renderer
Private renderer As New HtmlToPdf()
' Configure the rendering options for the PDF
renderer.RenderingOptions.Footer = New HtmlHeaderFooter() With {.HtmlFragment = "<div style='text-align:right'><em style='color:pink'>page {page} of {total-pages}</em></div>"}
Dynamic Data in PDF Headers and Footers
We may "mail-merge" content into the text and even HTML of headers and footers using placeholders such as:
{page}
for the current page number{total-pages}
for the total number of pages in the PDF{url}
for the URL of the rendered PDF if rendered from a web page{date}
for today's date{time}
for the current time{html-title}
for the title attribute of the rendered HTML document{pdf-title}
for the document title, which may be set via ChromePdfRenderOptions
C# HTML to PDF Conversion Settings
There are many nuances to how our users and clients may expect PDF content to be rendered.
The ChromePdfRenderer
class contains a RenderingOptions property which can be used to set these options.
For example we may wish to choose to only accept "print
" style CSS3 directives:
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-11.cs
// Import the IronPdf namespace to access the required classes and methods
using IronPdf;
// Instantiate a new HtmlToPdf renderer from the IronPdf library
var renderer = new HtmlToPdf();
// Set the CSS media type rendering option to 'Print' for the PDF renderer
// This ensures that print-specific CSS styles are applied during rendering
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print;
// Generate a PDF from HTML content and save it to a file
// The RenderHtmlAsPdf method converts an HTML string to a PDF document
// The SaveAs method saves the PDF document to the specified file path
renderer.RenderHtmlAsPdf("<html><body><h1>Hello, World!</h1></body></html>").SaveAs("Output.pdf");
' Import the IronPdf namespace to access the required classes and methods
Imports IronPdf
' Instantiate a new HtmlToPdf renderer from the IronPdf library
Private renderer = New HtmlToPdf()
' Set the CSS media type rendering option to 'Print' for the PDF renderer
' This ensures that print-specific CSS styles are applied during rendering
renderer.RenderingOptions.CssMediaType = PdfCssMediaType.Print
' Generate a PDF from HTML content and save it to a file
' The RenderHtmlAsPdf method converts an HTML string to a PDF document
' The SaveAs method saves the PDF document to the specified file path
renderer.RenderHtmlAsPdf("<html><body><h1>Hello, World!</h1></body></html>").SaveAs("Output.pdf")
We may also wish to change the size of our print margins to create more whitespace on the page, to make room for large headers or footers, or even set zero margins for commercial printing of brochures or posters:
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-12.cs
// Import necessary namespaces
using IronPdf;
// Create an HtmlToPdf renderer instance
var renderer = new HtmlToPdf();
// Set the top margin for the rendered PDF in millimeters
renderer.PrintOptions.MarginTop = 50;
// Set the bottom margin for the rendered PDF in millimeters
renderer.PrintOptions.MarginBottom = 50;
// Render an HTML document as PDF example:
// var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
// The result 'pdf' can be saved or manipulated further
// Example: pdf.SaveAs("output.pdf");
' Import necessary namespaces
Imports IronPdf
' Create an HtmlToPdf renderer instance
Private renderer = New HtmlToPdf()
' Set the top margin for the rendered PDF in millimeters
renderer.PrintOptions.MarginTop = 50
' Set the bottom margin for the rendered PDF in millimeters
renderer.PrintOptions.MarginBottom = 50
' Render an HTML document as PDF example:
' var pdf = renderer.RenderHtmlAsPdf("<html><body><h1>Hello World</h1></body></html>");
' The result 'pdf' can be saved or manipulated further
' Example: pdf.SaveAs("output.pdf");
We may wish to turn on or off background images from HTML elements:
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-13.cs
// Import the IronPdf library to work with PDF operations.
using IronPdf;
// Create a PdfRenderer object to manage PDF rendering options.
PdfRenderer renderer = new PdfRenderer();
// Set rendering options for the PdfRenderer.
// Specifically, enable the printing of HTML backgrounds in the generated PDF documents.
renderer.RenderingOptions.PrintHtmlBackgrounds = true;
// This is where you would continue with your PDF rendering logic based on your needs,
// such as creating a PDF from HTML, rendering to a specific file, etc.
// For instance, to render an HTML string into a PDF:
string htmlContent = "<h1>Hello, PDF!</h1><p>This is a PDF document rendered from HTML content.</p>";
// Specify the output path for the generated PDF document.
string outputPath = "output.pdf";
// Render the HTML content to the specified PDF file.
PdfDocument pdfDocument = renderer.RenderHtmlAsPdf(htmlContent);
pdfDocument.SaveAs(outputPath);
// Inform the user about the successful creation of the PDF file.
Console.WriteLine($"PDF document successfully created at: {outputPath}");
' Import the IronPdf library to work with PDF operations.
Imports IronPdf
' Create a PdfRenderer object to manage PDF rendering options.
Private renderer As New PdfRenderer()
' Set rendering options for the PdfRenderer.
' Specifically, enable the printing of HTML backgrounds in the generated PDF documents.
renderer.RenderingOptions.PrintHtmlBackgrounds = True
' This is where you would continue with your PDF rendering logic based on your needs,
' such as creating a PDF from HTML, rendering to a specific file, etc.
' For instance, to render an HTML string into a PDF:
Dim htmlContent As String = "<h1>Hello, PDF!</h1><p>This is a PDF document rendered from HTML content.</p>"
' Specify the output path for the generated PDF document.
Dim outputPath As String = "output.pdf"
' Render the HTML content to the specified PDF file.
Dim pdfDocument As PdfDocument = renderer.RenderHtmlAsPdf(htmlContent)
pdfDocument.SaveAs(outputPath)
' Inform the user about the successful creation of the PDF file.
Console.WriteLine($"PDF document successfully created at: {outputPath}")
It is also possible to set our output PDFs to be rendered on any virtual paper size - including portrait and landscape sizes and even custom sizes which may be set in millimeters or inches.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-14.cs
using IronPdf;
using IronPdf.Rendering;
// Create an instance of the HtmlToPdf renderer
var renderer = new HtmlToPdf();
/*
Set the rendering options for the PDF:
- PaperSize: Sets the paper size to A4.
- PaperOrientation: Sets the paper orientation to Landscape.
*/
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4;
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape;
// Additional code for generating a PDF should be added here. For example:
// var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
// pdf.SaveAs("output.pdf");
// The above example shows how you might render an HTML string to a PDF and save it to a file.
Imports IronPdf
Imports IronPdf.Rendering
' Create an instance of the HtmlToPdf renderer
Private renderer = New HtmlToPdf()
'
' Set the rendering options for the PDF:
' - PaperSize: Sets the paper size to A4.
' - PaperOrientation: Sets the paper orientation to Landscape.
'
renderer.RenderingOptions.PaperSize = PdfPaperSize.A4
renderer.RenderingOptions.PaperOrientation = PdfPaperOrientation.Landscape
' Additional code for generating a PDF should be added here. For example:
' var pdf = renderer.RenderHtmlAsPdf("<h1>Hello World</h1>");
' pdf.SaveAs("output.pdf");
' The above example shows how you might render an HTML string to a PDF and save it to a file.
Explore all rendering options in the following how-to article: "How to Use the Rendering Options."
Apply HTML Templating
To template or "batch create" PDFs is a common requirement for Internet and website developers.
Rather than templating a PDF document itself, with IronPDF we can template our HTML using existing, well tried technologies. When the HTML template is combined with data from a query-string or database we end up with a dynamically generated PDF document.
In the simplest instance, using the C# String.Format method is effective for basic sample.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-15.cs
using System;
// Define a class named 'Program' containing the main entry point of the application
class Program
{
// The main entry point for the application
static void Main()
{
// The following line formats a string to include the word "World"
// in place of the placeholder {0} and enclose it within <h1> HTML tags
string formattedString = String.Format("<h1>Hello {0}!</h1>", "World");
// Output the formatted string to the console
Console.WriteLine(formattedString);
}
}
Imports System
' Define a class named 'Program' containing the main entry point of the application
Friend Class Program
' The main entry point for the application
Shared Sub Main()
' The following line formats a string to include the word "World"
' in place of the placeholder {0} and enclose it within <h1> HTML tags
Dim formattedString As String = String.Format("<h1>Hello {0}!</h1>", "World")
' Output the formatted string to the console
Console.WriteLine(formattedString)
End Sub
End Class
If the HTML file is longer, often we can use arbitrary placeholders such as [[NAME]]
and replace them with real data later.
The following example will create 3 PDFs, each personalized to a user.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-16.cs
// Define a basic HTML template with a placeholder for names
var htmlTemplate = "<p>[[NAME]]</p>";
// Create an array containing names to be inserted into the HTML template
var names = new[] { "John", "James", "Jenny" };
// Iterate over each name in the names array
foreach (var name in names)
{
// Replace the placeholder in the HTML template with the current name
var htmlInstance = htmlTemplate.Replace("[[NAME]]", name);
// Render the HTML string to a PDF object
// Assume 'renderer' is a pre-configured instance of a PDF rendering library
var pdf = renderer.RenderHtmlAsPdf(htmlInstance);
// Save the rendered PDF file with the name of the person
pdf.SaveAs(name + ".pdf");
}
' Define a basic HTML template with a placeholder for names
Dim htmlTemplate = "<p>[[NAME]]</p>"
' Create an array containing names to be inserted into the HTML template
Dim names = { "John", "James", "Jenny" }
' Iterate over each name in the names array
For Each name In names
' Replace the placeholder in the HTML template with the current name
Dim htmlInstance = htmlTemplate.Replace("[[NAME]]", name)
' Render the HTML string to a PDF object
' Assume 'renderer' is a pre-configured instance of a PDF rendering library
Dim pdf = renderer.RenderHtmlAsPdf(htmlInstance)
' Save the rendered PDF file with the name of the person
pdf.SaveAs(name & ".pdf")
Next name
Advanced Templating With Handlebars.NET
A sophisticated method to merge C# data with HTML for PDF generation is using the Handlebars Templating standard.
Handlebars makes it possible to create dynamic HTML from C# objects and class instances including database records. Handlebars is particularly effective where a query may return an unknown number of rows such as in the generation of an invoice.
We must first add an additional NuGet Package to our project: https://www.nuget.org/packages/Handlebars.NET/
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-17.cs
using HandlebarsDotNet;
// Define the source template as a string with placeholders for title and body
var source =
@"<div class=""entry"">
<h1>{{title}}</h1>
<div class=""body"">
{{body}}
</div>
</div>";
// Compile the Handlebars template from the source string
var template = Handlebars.Compile(source);
// Create an anonymous type representing the data with properties `title` and `body`
var data = new { title = "My new post", body = "This is my first post!" };
// Execute the compiled template with the given data to produce the result string
var result = template(data);
// The resulting HTML will look like this:
//
// <div class="entry">
// <h1>My new post</h1>
// <div class="body">
// This is my first post!
// </div>
// </div>
// Output the result to the console
Console.WriteLine(result);
Imports HandlebarsDotNet
' Define the source template as a string with placeholders for title and body
Private source = "<div class=""entry"">
<h1>{{title}}</h1>
<div class=""body"">
{{body}}
</div>
</div>"
' Compile the Handlebars template from the source string
Private template = Handlebars.Compile(source)
' Create an anonymous type representing the data with properties `title` and `body`
Private data = New With {
Key .title = "My new post",
Key .body = "This is my first post!"
}
' Execute the compiled template with the given data to produce the result string
Private result = template(data)
' The resulting HTML will look like this:
'
' <div class="entry">
' <h1>My new post</h1>
' <div class="body">
' This is my first post!
' </div>
' </div>
' Output the result to the console
Console.WriteLine(result)
To render this HTML we can simply use the RenderHtmlAsPdf
method.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-18.cs
using IronPdf;
// Create an instance of the ChromePdfRenderer, which allows rendering HTML to PDF.
var renderer = new ChromePdfRenderer();
// Define the HTML content you wish to convert to PDF.
string htmlInstance = "<html><body><h1>Hello, World!</h1></body></html>"; // Example HTML content
// Render the HTML content as a PDF document.
var pdf = renderer.RenderHtmlAsPdf(htmlInstance);
// Save the rendered PDF document to a file named "Handlebars.pdf".
pdf.SaveAs("Handlebars.pdf");
Imports IronPdf
' Create an instance of the ChromePdfRenderer, which allows rendering HTML to PDF.
Private renderer = New ChromePdfRenderer()
' Define the HTML content you wish to convert to PDF.
Private htmlInstance As String = "<html><body><h1>Hello, World!</h1></body></html>" ' Example HTML content
' Render the HTML content as a PDF document.
Private pdf = renderer.RenderHtmlAsPdf(htmlInstance)
' Save the rendered PDF document to a file named "Handlebars.pdf".
pdf.SaveAs("Handlebars.pdf")
You can learn more about the handlebars HTML templating standard and its C# implementation from GitHub.
Add Page Breaks using HTML5
A common requirement in a PDF document is for pagination. Developers need to control where PDF pages start and end for a clean, readable layout.
The easiest way to do this is with a lesser-known CSS trick which will render a page break into any printed HTML document.
<div style='page-break-after: always;'> </div>
<div style='page-break-after: always;'> </div>
The provided HTML works, but is hardly best practice. We advise to adjust the media attribute like the following example. Such a neat and tidy way to lay out multi-page HTML content.
<!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>This is Page 1</h1>
</div>
<div class="page">
<h1>This is Page 2</h1>
</div>
<div class="page">
<h1>This is Page 3</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>This is Page 1</h1>
</div>
<div class="page">
<h1>This is Page 2</h1>
</div>
<div class="page">
<h1>This is Page 3</h1>
</div>
</body>
</html>
The How-To outlines more tips and tricks with Page Breaks.
Attach a Cover Page to a PDF
IronPDF makes it easy to Merge PDF documents. The most common usage of this technique is to add a cover page or back page to an existing rendered PDF document.
To do so, we first render a cover page, and then use the PdfDocument.Merge()
static method to combine the two documents.
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-19.cs
// Import the IronPdf library, which provides tools for generating and manipulating PDF documents
using IronPdf;
// Create an instance of the HtmlToPdf class, which is used for converting HTML content into PDF format
var renderer = new HtmlToPdf();
// Render a PDF document from a specific URL
// This line creates a PDF document from the contents of the given URL
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/");
// Merge the newly created PDF with another PDF document named "CoverPage.pdf"
// The PdfDocument.Merge method combines multiple PDF documents into a single document
var pdfMerged = PdfDocument.Merge(new PdfDocument("CoverPage.pdf"), pdf);
// Save the merged PDF document as "Combined.Pdf"
pdfMerged.SaveAs("Combined.Pdf");
// Note:
// 1. The code assumes that "CoverPage.pdf" is already available in the working directory.
// 2. The method PdfDocument.Merge returns a new PdfDocument object that represents the merged PDFs.
// 3. Make sure you have the IronPdf library installed and referenced in your project for this code to work.
' Import the IronPdf library, which provides tools for generating and manipulating PDF documents
Imports IronPdf
' Create an instance of the HtmlToPdf class, which is used for converting HTML content into PDF format
Private renderer = New HtmlToPdf()
' Render a PDF document from a specific URL
' This line creates a PDF document from the contents of the given URL
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf/")
' Merge the newly created PDF with another PDF document named "CoverPage.pdf"
' The PdfDocument.Merge method combines multiple PDF documents into a single document
Private pdfMerged = PdfDocument.Merge(New PdfDocument("CoverPage.pdf"), pdf)
' Save the merged PDF document as "Combined.Pdf"
pdfMerged.SaveAs("Combined.Pdf")
' Note:
' 1. The code assumes that "CoverPage.pdf" is already available in the working directory.
' 2. The method PdfDocument.Merge returns a new PdfDocument object that represents the merged PDFs.
' 3. Make sure you have the IronPdf library installed and referenced in your project for this code to work.
A full code example can be found here: PDF Cover Page Code Example.
Add a Watermark
A final C# PDF feature that IronPDF supports is to add a watermark to documents. This can be used to add a notice to each page that a document is "confidential" or a "sample".
:path=/static-assets/pdf/content-code-examples/tutorials/html-to-pdf-20.cs
// Import necessary namespaces for IronPdf
using IronPdf;
using IronPdf.Editing;
// Instantiate the ChromePdfRenderer, which allows rendering HTML/CSS/JavaScript content to a PDF
var renderer = new ChromePdfRenderer();
// Render a PDF from a URL. The specified URL is that of a NuGet package page for IronPdf.
var pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf");
// Create a text watermark to apply to all pages of the PDF.
// The watermark text is "SAMPLE", styled in red, and positioned at the center of each page.
var watermark = new TextWatermark()
{
FontSize = 50, // Set font size for the watermark text
Text = "SAMPLE", // The watermark text
HorizontalAlignment = HorizontalAlignment.Center, // Horizontally align the watermark to the center
VerticalAlignment = VerticalAlignment.Middle, // Vertically align the watermark to the middle
FontColor = IronPdf.Drawing.Colors.Red // Font color set to red
};
// Apply the watermark to all pages of the PDF
pdf.Watermark = watermark;
// Save the watermarked PDF to the specified path
pdf.SaveAs(@"C:\Path\To\Watermarked.pdf");
' Import necessary namespaces for IronPdf
Imports IronPdf
Imports IronPdf.Editing
' Instantiate the ChromePdfRenderer, which allows rendering HTML/CSS/JavaScript content to a PDF
Private renderer = New ChromePdfRenderer()
' Render a PDF from a URL. The specified URL is that of a NuGet package page for IronPdf.
Private pdf = renderer.RenderUrlAsPdf("https://www.nuget.org/packages/IronPdf")
' Create a text watermark to apply to all pages of the PDF.
' The watermark text is "SAMPLE", styled in red, and positioned at the center of each page.
Private watermark = New TextWatermark() With {
.FontSize = 50,
.Text = "SAMPLE",
.HorizontalAlignment = HorizontalAlignment.Center,
.VerticalAlignment = VerticalAlignment.Middle,
.FontColor = IronPdf.Drawing.Colors.Red
}
' Apply the watermark to all pages of the PDF
pdf.Watermark = watermark
' Save the watermarked PDF to the specified path
pdf.SaveAs("C:\Path\To\Watermarked.pdf")
A full code example can be found here: PDF Watermarking Code Example.
Download C# Source Code
The full free HTML to PDF converter C# Source Code for this tutorial is available to download as a zipped Visual Studio 2022 project file. It will use its rendering engine to generate PDF document objects in C#.
Download this tutorial as a Visual Studio project
The free download contains everything you need to create a PDF from HTML - including working C# PDF code examples code for:
- Convert an HTML String to PDF using C#
- HTML File to PDF in C# (supporting CSS, JavaScript and images)
- C# HTML to PDF using a URL ("URL to PDF")
- C# PDF editing and settings examples
- Rendering JavaScript canvas charts such as d3.js to a PDF
- The PDF Library for C#
Class Reference
Developers may also be interested in the IronPdf.PdfDocument
Class reference:
https://ironpdf.com/object-reference/api/
This object model shows how PDF documents may be:
- Encrypted and password protected
- Edited or 'stamped' with new HTML content
- Enhanced with foreground and background images
- Merged, joined, truncated and spliced at a page or document level
- OCR processed to extract plain text and images
Blazor HTML to PDF
Adding HTML to PDF functionality to your Blazor server is easy, simply:
- Create a new Blazor server project or use an existing one
- Add the IronPDF library to your project using NuGet
- Add a new Razor Component or use an existing one
- Add a
InputTextArea
and link it to IronPDF - Let IronPDF take care of the rest and deploy
For further reading, continue to the full step-by-step guide for converting HTML to PDF in Blazor applications.

Compare with Other PDF Libraries
IronPDF is a powerful and full-featured PDF library tailored for modern .NET developers. With native HTML-to-PDF conversion powered by an advanced Chromium engine, an intuitive API, and regular updates, it simplifies development while ensuring high-quality results. Let’s take a closer look at how it compares to other tools:
PDFSharp
- Core Features: PdfSharp is an open-source library that supports basic PDF creation and editing. However, it lacks built-in HTML-to-PDF conversion, which is crucial for accurately rendering web content.
- Modern Standards: IronPDF leverages modern web technologies, including HTML, CSS, and JavaScript, through its Chromium-based engine, ensuring that PDFs maintain a contemporary look and feel.
- Support & Updates: PdfSharp receives infrequent updates and lacks official support, while IronPDF offers monthly updates, security patches, and professional assistance—making it ideal for enterprise applications.
wkhtmltopdf
- Ease of Integration: wkhtmltopdf requires command-line operations and manual dependency configuration, making its integration with .NET applications more cumbersome.
- Rendering Technology: wkhtmltopdf relies on an outdated WebKit engine, which struggles with modern JavaScript and CSS often taking too long to generate output — especially for dynamic, content-rich websites. IronPDF’s Chromium engine provides accurate and reliable rendering.
- Ongoing Development: wkhtmltopdf has seen little active development since 2022 and offers limited support, while IronPDF continues to evolve with frequent updates and dedicated customer service.
iTextSharp
- HTML-to-PDF Rendering: The free version of iTextSharp does not offer native HTML-to-PDF conversion, often forcing developers to use complex workarounds. IronPDF, on the other hand, provides seamless conversion with full support for modern web technologies.
- Developer Experience: iTextSharp’s low-level API can be cumbersome and time-consuming, slowing down development. IronPDF offers a clean and intuitive C# API, simplifying coding and accelerating project delivery.
- Maintenance & Support: IronPDF provides professional support and regular updates, ensuring security and efficiency, whereas iTextSharp’s free version is outdated and lacks official assistance.
Aspose.PDF
- Conversion Quality: Aspose.PDF is a capable tool, but its HTML-to-PDF conversion has limitations and may struggle with modern CSS and JavaScript. Aspose does not allow direct URL to PDF conversion, so developers must manually download the HTML or stream the content, adding extra steps. Even after doing so, the resulting PDF is often missing styles, layout elements, and dynamic content. IronPDF’s Chromium-based engine guarantees high-fidelity conversion of complex web layouts.
- API Usability: Aspose.PDF’s API can be verbose and challenging to navigate, whereas IronPDF focuses on a developer-friendly experience that minimizes setup time and enhances productivity.
- Performance: IronPDF’s optimized processing ensures faster conversion speeds and better performance, making it a strong choice for enterprise applications with high-volume PDF generation needs.
Syncfusion PDF
- API Complexity: Syncfusion PDF is a robust tool but has a more complex API that can slow down development. IronPDF, by contrast, provides a straightforward API for rapid integration.
- Rendering Engine: Syncfusion supports both WebKit and Blink engines. While Blink is faster than WebKit, real-world testing shows that Syncfusion’s Blink engine still performs slower than IronPDF’s Chromium rendering engine. Additionally, Syncfusion struggles to fully capture complex pages, missing some dynamically loaded sections and certain CSS styles. IronPDF’s Chromium engine ensures precise and consistent rendering, even for modern sites with heavy JavaScript and CSS.
- Advanced Features: In addition to standard conversion, IronPDF includes powerful capabilities such as digital signatures, annotations, form filling, OCR, and barcode generation—adding extra value to your projects.
Rendering Comparison
To compare the HTML-to-PDF conversion quality of these libraries, we used the Reddit page, which contains dynamic content, live updates, modern CSS, and JavaScript-based elements:
https://www.reddit.com/
Here are the results (click each image to view it enlarged):
IronPDF

SyncFusion

Aspose.PDF

Wkhtmltopdf

Please note
Conclusion
For .NET developers seeking a modern and reliable PDF solution, IronPDF stands ahead of the competition. Its seamless HTML-to-PDF conversion, ease of use, regular updates, and comprehensive feature set make it a top choice. Whether you're working on a small project or a large-scale enterprise application, IronPDF enhances productivity while avoiding the risks associated with outdated or unsupported libraries. Designed for commercial applications, IronPDF ensures your projects remain robust, efficient, and future-proof.
In direct tests using real-world dynamic websites, IronPDF delivered the fastest and most accurate results. Syncfusion was slower and missed most of the sections. Aspose required downloading HTML first and still failed to render correctly. wkhtmltopdf gave static html content without capturing the style – a poor fit for modern sites.
This confirms IronPDF offers the best balance of speed, accuracy, and ease of use for modern HTML-to-PDF workflows.
Experience IronPDF's full-feature suite that converts dynamic, heavy CSS HTML to PDF with ease—test it out now with our free trial.
Watch HTML to PDF in C# Tutorial Video
With the PDF document, you can visit the following link to learn how to open a PDF in Chrome without downloading it.
Frequently Asked Questions
How do I convert HTML to PDF using IronPDF in C#?
To convert HTML to PDF using IronPDF, you need to initialize the ChromePdfRenderer, render the HTML content as a PDF using RenderHtmlAsPdf method, and then save the PDF to a file.
What are the system requirements for IronPDF?
IronPDF supports .NET 9, .NET 8, .NET 7, .NET 6, .NET 5, .NET Core, Standard, and Framework on Windows, macOS, Linux, Docker, Azure, and AWS.
Can I use IronPDF with other programming languages?
Yes, IronPDF can be used with multiple languages both inside and outside the .NET ecosystem, including F#, VB.NET, Python, Java, and Node.js.
How can I add custom headers and footers to a PDF using IronPDF?
With IronPDF, you can add headers and footers using the SimpleHeaderFooter class for text-based content or the HtmlHeaderFooter class for rich HTML content.
Is it possible to render a PDF from an existing URL with IronPDF?
Yes, you can render a PDF from an existing URL by using the RenderUrlAsPdf method in IronPDF.
Does IronPDF support advanced CSS and JavaScript rendering?
Yes, IronPDF supports advanced CSS3 and JavaScript, including jQuery and AJAX, providing accurate rendering of modern web designs.
Can I apply HTML templating for batch PDF creation in IronPDF?
Yes, you can use C# templating techniques, including String.Format and Handlebars.NET, to dynamically generate PDFs with IronPDF.
How does IronPDF compare with other PDF libraries?
IronPDF offers superior HTML-to-PDF conversion with modern Chromium engine support, frequent updates, and a user-friendly API compared to libraries like PdfSharp, wkhtmltopdf, iTextSharp, Aspose.PDF, and Syncfusion PDF.
Can I add watermarks to PDFs with IronPDF?
Yes, IronPDF allows you to add text or image watermarks to your PDF documents.
Is there a trial version available for IronPDF?
Yes, you can sign up for a free 30-day trial key to test IronPDF’s features before purchasing a license.