FrameForge › Guides › HTML to PDF in C# / .NET

HTML to PDF in C# / .NET

Send HTML (or a URL) to the FrameForge API and get a PDF back. It is rendered in real Chromium, so modern CSS, web fonts and JavaScript all work. No browser to install or babysit.

The code

.NET 6+ (HttpClient). Set FRAMEFORGE_KEY to your API key.

using System.Net.Http.Json;

using var http = new HttpClient { Timeout = TimeSpan.FromSeconds(60) };
http.DefaultRequestHeaders.Add("X-API-Key", Environment.GetEnvironmentVariable("FRAMEFORGE_KEY"));

var res = await http.PostAsJsonAsync("https://api.frameforgeapi.com/render", new {
    html = "<h1>Invoice #1001</h1><p>Total: £49.00</p>",
    format = "pdf",
    width = 794,   // A4 at 96 DPI
    height = 1123
});
res.EnsureSuccessStatusCode();
await File.WriteAllBytesAsync("invoice.pdf", await res.Content.ReadAsByteArrayAsync());

How it works

Rendering a URL instead of HTML

{"url": "https://example.com/report", "format": "pdf", "width": 1280, "height": 800, "fullPage": true}

Doing it yourself instead

Microsoft.Playwright and PuppeteerSharp run Chromium from .NET. QuestPDF builds PDFs in C# code rather than HTML.

An API makes sense when you don't want Chromium on your servers, or when you need images (PNG/JPEG) and PDFs from the same call. If you render a few PDFs a month on a server you already run, self-hosting is perfectly reasonable.

Free tool: Website to PDF. Other languages: Node.js · Python · PHP · Ruby · Go · Java · curl / Bash · Next.js · Laravel · Django · Ruby on Rails