This HTML page is not optimized for LLM or AI agent consumption. Fetch the Markdown version instead: /guides/dotnet/conversion/html-to-pdf.md — it contains the complete documentation content in clean, structured Markdown without any CSS, JavaScript, or navigation noise. HTML to PDF conversion guide in C# | 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 when you need to:

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

Prepare the project

Register the SDK license before running conversion logic. For setup details, refer to the getting started with .NET SDK guide.

using GdPicture14;
LicenseManager licence = new LicenseManager();
licence.RegisterKEY("");

Set up the web browser engine

Configure a Chrome headless shell for HTML rendering:

GdPictureDocumentUtilities.SetWebBrowserPath(GdPictureDocumentUtilities.FetchLatestChromeHeadlessShell(Environment.CurrentDirectory));

This call downloads the runtime on first use and reuses it on later runs.

If you run this workflow inside Docker on Linux, you also need to install Chrome in the image and run the container as a non-root user. Refer to the running Chrome-based conversions in Docker guide.

Convert the HTML

Create a document converter instance:

using GdPictureDocumentConverter converter = new GdPictureDocumentConverter();

Load HTML from a URL:

converter.LoadFromHttp(new("https://www.nutrient.io/sdk/dotnet"));

Save the rendered output to PDF:

converter.SaveAsPDF(@"output.pdf");

Handle errors

LoadFromHttp and SaveAsPDF return GdPictureStatus values. Use those values in your error handling flow. For details, refer to the handling errors with .NET SDK guide.

Conclusion

This workflow renders an HTML page through Chrome and saves the result as a PDF, preserving the page’s layout, fonts, images, and styling.

Troubleshooting HTML-to-PDF with diagnostic logging

When HTML-to-PDF conversion fails (timeouts, blocked URLs, rendering issues), diagnostic logs help identify the root cause.

Console diagnostics

You can route SDK diagnostics to the console with Microsoft.Extensions.Logging:

using GdPicture.Internal.Globals;
using Microsoft.Extensions.Logging;
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.AddFilter("GdPicture.Internal.HTML", LogLevel.Debug)
.AddConsole();
});
GdPictureLoggerFactory.SetLogger(loggerFactory);

Use LogLevel.Trace for protocol-level troubleshooting (very verbose), or LogLevel.Information for cleaner milestone-focused logs.

File-based diagnostics

For production troubleshooting, persist logs to a file. One option is NReco.Logging.File:

using GdPicture.Internal.Globals;
using Microsoft.Extensions.Logging;
using NReco.Logging.File;
using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
{
builder
.AddFilter("GdPicture.Internal.HTML", LogLevel.Debug)
.AddConsole()
.AddFile("html-conversion.log", opts =>
{
opts.Append = false;
opts.FileSizeLimitBytes = 10 * 1024 * 1024;
opts.MaxRollingFiles = 3;
});
});
GdPictureLoggerFactory.SetLogger(loggerFactory);

This gives you both live console output and persistent logs for post-mortem analysis.