This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/dotnet/csharp/conversion/html-to-pdf.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. Converting HTML to PDF | Nutrient .NET SDK

HTML content can render differently across browsers, devices, and viewport sizes. Converting HTML to PDF gives you a fixed output format for sharing, archiving, and printing.

Use this workflow to:

  • Preserve layout and styling in a stable document format
  • Distribute web content for offline access
  • Archive rendered pages for audit or compliance workflows

How Nutrient supports this workflow

Nutrient .NET SDK converts HTML to PDF through a single API call. Nutrient renders the HTML through Chrome, so the PDF preserves the page layout, fonts, images, and styling.

HTML-to-PDF conversion on Linux relies on Chrome for rendering. If you run this workflow in Docker on Linux, make sure the container includes Chrome and runs as a non-root user. For the packaged Docker setup, refer to the running Chrome-based conversions in Docker guide.

You don’t need to handle:

  • HTML parsing and layout
  • Rendering fonts, images, and CSS styling
  • Page sizing and pagination

Use the SDK API to handle the conversion in your application.

Complete implementation

The following example converts a local input.html file to PDF. This line sets up the C# application. The using directive brings in the Nutrient SDK namespace:

using Nutrient;

This line opens the HTML file. The using declaration(opens in a new tab) ensures the document is automatically closed when it goes out of scope, preventing resource leaks:

try
{
using Document document = Document.Open("input.html");

This block exports the file to PDF and saves it as output.pdf. The try-catch block handles potential errors using NutrientException:

document.ExportAsPdf("output.pdf");
Console.WriteLine("Successfully converted to output.pdf");
}
catch (NutrientException e)
{
Console.Error.WriteLine($"Error: {e.Message}");
Environment.Exit(1);
}

Configure conversion security

By default, conversion restricts access to the local network and blocks background connections and tasks. Public resources and document JavaScript remain available. Tighten or relax these settings according to how much you trust the source.

Configure these controls in the document’s conversion settings before opening HTML, MHTML, or email input:

SettingDefaultEffect
HtmlBlockPrivateNetworkAccesstrueRestricts access to the local network.
HtmlPrivateNetworkAllowListEmptyExact host names, IP addresses, or CIDRs (for example intranet.corp, 10.20.0.0/16, or fd00::/8) permitted through private-network blocking.
HtmlBlockFileAccessfalseBlocks local files except the input document. When disabled, files in the input directory and its subdirectories remain accessible.
HtmlBlockWebSocketsAndWorkerstrueBlocks background connections and tasks.
HtmlBlockNetworkAccessfalseBlocks all network requests.
HtmlScriptsExecutionDisabledfalseDisables document JavaScript.

For untrusted sources that need no external resources or JavaScript, set HtmlBlockNetworkAccess, HtmlScriptsExecutionDisabled, and HtmlBlockFileAccess to true. For trusted sources, relax only the restrictions needed by the document.

To enable access to a specific internal resource, add its host name, IP address, or CIDR range to the allow list. Entries exclude ports and URL schemes. Invalid entries fail when conversion starts. The allow list doesn’t override other blocking settings.

These settings don’t provide complete network isolation. Use network-level restrictions when converting untrusted content.

For URL inputs, the selected input origin remains accessible unless all network access is blocked.

Summary

The conversion has two steps:

  1. Open the HTML file.
  2. Export it as PDF.

Nutrient renders the HTML through Chrome and writes the result to output.pdf, so you don’t need to implement format-specific rendering logic.