---
title: "Create PDF from HTML in C# | Nutrient .NET SDK"
canonical_url: "https://www.nutrient.io/guides/dotnet/pdf-generation/from-html/"
md_url: "https://www.nutrient.io/guides/dotnet/pdf-generation/from-html.md"
last_updated: "2026-06-09T10:21:54.363Z"
description: "Learn how to generate a PDF from HTML files or websites using C#. Step-by-step guide with code examples included."
---

# Generate a PDF from HTML in C#

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](https://www.nutrient.io/sdk/dotnet/getting-started.md) guide.

```csharp

using GdPicture14;

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

```

## Set up the web browser engine

Configure a Chrome headless shell for HTML rendering:

```csharp

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](https://www.nutrient.io/guides/dotnet/deployment/headless-modes-google-chrome.md) guide.

## Convert the HTML

Create a document converter instance:

```csharp

using GdPictureDocumentConverter converter = new GdPictureDocumentConverter();

```

Load HTML from a URL:

```csharp

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

```

Save the rendered output to PDF:

```csharp

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](https://www.nutrient.io/guides/dotnet/best-practices.md#error-handling) 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.
---

## Related pages

- [Create PDFs from byte arrays in C#](/guides/dotnet/pdf-generation/byte-array.md)
- [Generate PDFs in.NET](/guides/dotnet/pdf-generation.md)
- [Create tagged PDFs in C#](/guides/dotnet/pdf-generation/tagged.md)
- [Create thumbnails from PDFs in C#](/guides/dotnet/pdf-generation/thumbnail-preview.md)
- [Generating PDF/UA from Word templates](/guides/dotnet/pdf-generation/word-template-to-pdf-ua.md)
- [Generate a PDF from a DOCX template in C#](/guides/dotnet/pdf-generation/from-word-template.md)
- [Create PDFs from scratch in C#](/guides/dotnet/pdf-generation/from-scratch.md)

