Skip to content

PuppeteerSharp HTML to PDF on Azure App Service and Docker in Production

PuppeteerSharp converts HTML to PDF well on a developer laptop. On Windows App Service the sandbox blocks the graphics calls a browser needs, and on Linux the stock .NET image lacks Chromium's libraries. Here is the deployment matrix, a Dockerfile that works and what a year of running it costs.

Live demo

Runs in your browser. Nothing is uploaded. One PDF free to try, then a plan.

Your PDF is downloading. That was the free one. The Starter plan converts as many as you need, for $49 a month or $288 a year, half price.

See the plan

PuppeteerSharp converts HTML to PDF with a real Chromium browser, so the output matches what you see in Chrome, and the library itself is MIT licensed and free. The trouble starts at deployment. On Windows Azure App Service the sandbox blocks most of the graphics calls a browser needs, on Linux the stock .NET image ships without the shared libraries Chromium loads, and on serverless plans the browser is a poor fit for size and cold starts. In practice PuppeteerSharp works in production inside a container you build and own, or you hand the browser to a rendering API and keep one HTTP call in your code.

The short answer

If you already run containers on Linux (Azure Container Apps, AKS, App Service with a custom container), PuppeteerSharp is a sound choice: install Chromium in the image, point ExecutablePath at it and budget a few hours a month for upkeep. If your app runs on Windows App Service or a Functions consumption plan and you do not want to move it, the browser cannot live there, and a call to a service such as SitePDF is the shorter road. The deployment matrix and the cost math below show where the line falls.

What PuppeteerSharp HTML to PDF looks like in code

The happy path is short, which is why it wins so many comparisons. The package on NuGet was at version 25.17.1 in mid November 2026 and targets .NET 8 and .NET Standard 2.0.

using PuppeteerSharp;
using PuppeteerSharp.Media;

await new BrowserFetcher().DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });
await using var page = await browser.NewPageAsync();
await page.SetContentAsync(html);
byte[] pdf = await page.PdfDataAsync(new PdfOptions
{
    Format = PaperFormat.Letter,
    PrintBackground = true,
    MarginOptions = new MarginOptions { Top = "20mm", Bottom = "20mm" }
});

Every line of that is fine on a laptop. The first line is the one that bites in production: BrowserFetcher downloads a full Chrome build at runtime into a writable folder, and the browser it launches expects a desktop style environment. Where your app runs decides whether either assumption holds.

Does PuppeteerSharp work on Azure App Service?

On Windows App Service, plan for no. Microsoft's Azure Web App sandbox notes say the sandbox blocks almost all Win32k APIs, so most User32 and GDI32 calls fail, and list only a few PDF engines that work on Basic and higher plans. Headless Chromium is not on that list. Linux App Service and Windows containers do not have that sandbox.

That page is specific about what does work on Windows plans: SQL Reporting, Telerik reporting, EVOPDF, and wkhtmltopdf based tools such as Rotativa and NReco, all on Basic or higher, and even those fall back to system fonts instead of your custom ones. It also names Syncfusion, Siberix and Spire.PDF as failing, and says PhantomJS and Selenium are not supported. If you are on Rotativa today because it was the one thing that ran there, our Rotativa alternative for ASP.NET Core covers what to move to.

Where PuppeteerSharp runs on Azure and where it does not

Hosting targetDoes Chromium startWhat you have to doVerdict
App Service, Windows, code deployNot reliably; the sandbox blocks the graphics calls it needsNothing practical inside the sandboxMove the browser elsewhere
App Service, Linux, code deployFails on missing libraries such as libnss3 and libgbmInstall packages at startup on every restart, fragileSwitch to a custom container
App Service with a custom Linux containerYesBuild and patch an image with Chromium and fontsWorks, you own the image
Azure Functions, Windows consumption planSame sandbox as Windows App ServiceNothing practicalUse an API or a container
Azure Container Apps or AKSYesImage, memory limits, a concurrency cap per replicaThe best self-hosted option
Any host, rendering APINo browser in your appOne HTTP call with an API keyWorks everywhere, billed per render

How do I run PuppeteerSharp in Docker?

Install Chromium and its fonts from the distribution in your image, skip BrowserFetcher, and point ExecutablePath at the installed binary. The official .NET runtime images are Debian based, so the packages are one apt line. Pass --no-sandbox only when the container already runs as a non-root user with no other untrusted workloads.

FROM mcr.microsoft.com/dotnet/aspnet:8.0
RUN apt-get update \
 && apt-get install -y --no-install-recommends chromium fonts-liberation fonts-noto-color-emoji \
 && rm -rf /var/lib/apt/lists/*
ENV CHROME_PATH=/usr/bin/chromium
WORKDIR /app
COPY ./publish .
USER app
ENTRYPOINT ["dotnet", "Invoices.dll"]
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true,
    ExecutablePath = Environment.GetEnvironmentVariable("CHROME_PATH"),
    Args = new[] { "--no-sandbox", "--disable-dev-shm-usage" }
});

Three details save most of the debugging time. Launch one browser per process and reuse it, opening a new page per document, because a cold browser launch costs far more than a render. Cap concurrent pages per replica, since every open tab holds its own memory and a month end batch can push a small container into an out of memory restart. And install every font your templates reference, because a missing font falls back silently and the invoice still prints, just in the wrong typeface. Our list of reasons fonts do not load in HTML to PDF covers the cases that survive a correct Dockerfile.

Does PuppeteerSharp need Chrome installed?

Yes, it drives a real Chrome or Chromium. By default BrowserFetcher downloads a build at runtime, which needs network access and a writable folder on first start. In containers it is cleaner to install Chromium in the image and set ExecutablePath, so every replica starts with the same, scanned browser version.

What a year of self-hosting costs against an API

Take a .NET team that sends 8,000 invoices and statements a month. The assumptions are labelled so you can swap in your own: 12 hours to build, test and wire the container into the pipeline, 2 hours a month for Chromium and package updates, font fixes and the odd memory incident, at $100 an hour. Hosting is left out because most teams fold the replica into capacity they already pay for, which makes the comparison generous to self-hosting.

LinePuppeteerSharp in your containerSitePDF Starter API
Setup12 h, $1,200About 1 h to swap the call, $100
Upkeep for 12 months24 h, $2,400None for the renderer
Subscription$0, MIT license$288 billed yearly, 10,000 renders a month
Year one totalAbout $3,600About $388

The gap closes as volume grows and once the upkeep is routine. At several hundred thousand documents a month, with a platform team that already runs browsers for testing, keeping PuppeteerSharp is often right. Below that, the labor line usually dominates. The C# PDF library comparison puts the commercial .NET libraries in the same table if you would rather buy a license than run a browser, and the general library versus API breakdown walks through the decision for any stack.

Swapping PuppeteerSharp for one HTTP call

Your HTML pipeline stays as it is. Whatever produces the string today, Razor, a Handlebars template or a Blazor component rendered to HTML, keeps producing it, and only the last step changes:

using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new("Bearer", apiKey);
var form = new FormUrlEncodedContent(new Dictionary<string, string>
{
    ["html"] = html,
    ["format"] = "Letter",
    ["archive"] = "true"
});
var res = await http.PostAsync("https://api.sitepdf.com/v1/render", form);
var json = await res.Content.ReadFromJsonAsync<RenderResult>();
// json.PdfUrl links to the finished PDF; the archived copy is kept with a timestamp

The same Chromium engine lays out the page, so output that looked right under PuppeteerSharp looks the same here, headers and footers included. Blazor teams can follow the component specific steps on the Blazor HTML to PDF page, and anyone weighing other headless browser setups will find the trade offs on the Puppeteer alternative page. If what you really wanted from a headless browser was to watch a competitor's pricing page for changes rather than print documents, a monitoring service such as Websitechange does that job without any browser in your app.

When to keep PuppeteerSharp

Keep it when you already run Linux containers, your volume is high and steady, documents contain data that must not leave your network, or you need browser automation beyond PDFs, such as end to end tests. It is a well maintained library with frequent releases, and the cost above is mostly people time. Move off it when the app is pinned to Windows App Service, when nobody on the team wants to own a browser image, or when you need proof of what each document said on the day it was sent, which the archive on every SitePDF render provides. Plans and render limits are on the pricing page.

Frequently asked questions

Is PuppeteerSharp free for commercial use?

Yes. PuppeteerSharp is published under the MIT license, so you can use it in commercial software without a fee. The cost is operational: you run and patch a Chromium browser, size memory for it, install fonts, and handle crashes, which is where most teams spend their budget instead of on a license.

Why does PuppeteerSharp fail to launch on Linux App Service?

The built-in .NET images for Linux App Service do not include the shared libraries Chromium needs, such as libnss3 and libgbm, so the browser exits as soon as it starts. Installing them in a startup script is lost on restarts. A custom container with Chromium installed in the image is the reliable fix.

Can I use PuppeteerSharp in Azure Functions?

Not on the Windows consumption plan, which shares the App Service sandbox that blocks the graphics calls a browser needs. A Linux Functions app running your own container image can work, but cold starts include launching Chromium. For occasional documents, calling a rendering API from the function is simpler and faster.

How much memory does PuppeteerSharp need?

It depends on the page, so measure your own templates. Each open page is a separate renderer process with its own memory, and long tables or large images raise it. Reuse one browser, cap concurrent pages per replica, and set a container memory limit with headroom for your heaviest document.

Written by the team behind SitePDF, an HTML to PDF API that archives every page it renders. The in-browser converter is free to try, and API plans start at $49 a month, half price billed yearly.

Get started

Render and archive with one API call

A pixel perfect PDF and a dated copy of the page from the same request. Plans from $49 a month, half price billed yearly.

HTML to PDF, in your browser

Buy the plan