Skip to footer content
USING IRONPDF

Convert HTML Files to PDF in .NET with IronPDF

RenderHtmlFileAsPdf does one thing: it takes an HTML file on disk and renders it to a PDF through a Chrome engine. What displays correctly in Chrome lands correctly in the document, with full support for CSS3, JavaScript, images, and fonts. The single distinction that matters is the input. This method reads a file, so relative asset paths (logos, stylesheets, fonts) resolve from the file's own location, no base URL required. That decides where it fits best.

Template-driven document generation

Keep an HTML template in your project (invoice, quote, certificate, contract), populate it, write it to disk, and render:

using IronPdf;

var renderer = new ChromePdfRenderer();
renderer.RenderHtmlFileAsPdf("templates/invoice-1042.html")
        .SaveAs("invoice-1042.pdf");
using IronPdf;

var renderer = new ChromePdfRenderer();
renderer.RenderHtmlFileAsPdf("templates/invoice-1042.html")
        .SaveAs("invoice-1042.pdf");
Imports IronPdf

Dim renderer As New ChromePdfRenderer()
renderer.RenderHtmlFileAsPdf("templates/invoice-1042.html").SaveAs("invoice-1042.pdf")
$vbLabelText   $csharpLabel

Because the source is a real file, ./logo.png and styles.css resolve naturally alongside it.

Rendering static-site and build output

Static site generators, Markdown pipelines, and documentation builders all produce HTML files. Point IronPDF at the output to turn a published page into an archivable PDF, with no need to re-fetch it over HTTP.

Designer-authored layouts

A designer hands over a self-contained HTML and CSS file; you render it as-is. Chrome drives the conversion, so the designer's browser preview matches the PDF, which removes a whole class of "it looked fine in the mockup" disputes.

Batch conversion of a folder

The method is one call per file, so converting a directory of reports or handouts is a short loop:

var renderer = new ChromePdfRenderer();

foreach (string file in Directory.GetFiles("reports", "*.html"))
{
    string output = Path.ChangeExtension(file, ".pdf");
    renderer.RenderHtmlFileAsPdf(file).SaveAs(output);
}
var renderer = new ChromePdfRenderer();

foreach (string file in Directory.GetFiles("reports", "*.html"))
{
    string output = Path.ChangeExtension(file, ".pdf");
    renderer.RenderHtmlFileAsPdf(file).SaveAs(output);
}
Imports System.IO
Imports IronPdf

Dim renderer As New ChromePdfRenderer()

For Each file As String In Directory.GetFiles("reports", "*.html")
    Dim output As String = Path.ChangeExtension(file, ".pdf")
    renderer.RenderHtmlFileAsPdf(file).SaveAs(output)
Next
$vbLabelText   $csharpLabel

Offline and air-gapped rendering

Because it reads from the local filesystem rather than a URL, this works where there is no outbound network: secure backends, CI runners, on-premise deployments. The HTML and its assets only need to be present on the machine.

Email-template proofing

Teams storing notification or email templates as HTML files can render them to PDF for review, sign-off, or record-keeping, without standing up a web server to view them.

The rule of thumb

IronPDF offers three entry points, and picking the wrong one is the most common source of broken assets:

  • RenderHtmlFileAsPdf reads a file from disk; relative assets resolve from the file's location.
  • RenderHtmlAsPdf takes an HTML string in memory; you usually set a base URL so assets resolve.
  • RenderUrlAsPdf fetches over HTTP, and is where authentication, cookies, and logins apply.

Reach for the file method whenever your HTML already lives as a file. Configure output through RenderingOptions before rendering, and verify the page in Chrome first; if it renders there, it renders in the PDF.

Frequently Asked Questions

What is the difference between RenderHtmlFileAsPdf, RenderHtmlAsPdf, and RenderUrlAsPdf?

RenderHtmlFileAsPdf reads an HTML file from disk; relative asset paths resolve from the file's own location. RenderHtmlAsPdf takes an HTML string in memory and typically requires a base URL for assets. RenderUrlAsPdf fetches a live URL over HTTP and is where authentication and cookies apply.

Do I need to set a base URL when using RenderHtmlFileAsPdf?

No. Because the method reads an actual file on disk, relative paths like ./logo.png and styles.css resolve automatically from the HTML file's directory. No base URL configuration is needed.

Can I use RenderHtmlFileAsPdf in an offline or air-gapped environment?

Yes. The method reads from the local filesystem rather than fetching over HTTP, so it works in environments with no outbound network access, including secure backends, CI runners, and on-premise deployments.

How do I batch-convert a folder of HTML files to PDF with IronPDF?

Iterate over the files with Directory.GetFiles and call RenderHtmlFileAsPdf once per file. Reuse a single ChromePdfRenderer instance across the loop to share the browser context.

Will the PDF look exactly like what I see in Chrome?

IronPDF uses a full Chromium engine for rendering, so the output matches the Chrome browser preview for the same HTML file. Verify the page in Chrome first — if it renders correctly there, it will render correctly in the PDF.

Curtis Chau
Technical Writer

Curtis Chau holds a Bachelor’s degree in Computer Science (Carleton University) and specializes in front-end development with expertise in Node.js, TypeScript, JavaScript, and React. Passionate about crafting intuitive and aesthetically pleasing user interfaces, Curtis enjoys working with modern frameworks and creating well-structured, visually appealing manuals.

...

Read More

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me