Getting Started
PeachPDF is a pure .NET HTML → PDF rendering library. It doesn’t shell out to Puppeteer, wkhtmltopdf, or any other external process — everything from HTML parsing to PDF output runs in-process, so it works in virtually any environment where .NET runs (containers, serverless, trimmed/AOT deployments) and benefits automatically from future .NET performance improvements.
.NET support. PeachPDF runs on every currently-supported version of .NET — .NET 8 and newer — following Microsoft’s .NET support policy. The NuGet package builds against the Long-Term-Support targets (net8.0 and net10.0); the Standard-Term-Support releases in between (such as .NET 9) aren’t separate build targets but are fully supported — the net8.0 build runs on them unchanged.
Try it first. Render an HTML file to PDF in your browser — no install, no server. The demo is PeachPDF itself running on WebAssembly, so what it produces is what the library produces.
Quick Start
Install the PeachPDF package from nuget.org:
dotnet add package PeachPDF
Render HTML to a PDF stream. All images and assets must be local to the file system or in data: URIs:
PdfGenerateConfig pdfConfig = new(){
PageSize = PageSize.Letter,
PageOrientation = PageOrientation.Portrait
};
PdfGenerator generator = new();
var stream = new MemoryStream();
var document = await generator.GeneratePdf(html, pdfConfig);
document.Save(stream);
For more usage examples — rendering self-contained MHTML files, fetching HTML from a remote URI, sharing a parsed CSS context across renders, saving to disk, working with fonts, enabling tagged PDF (PDF/UA) output, generating PDF/A-conformant output, and returning PDFs from ASP.NET Core or Azure Functions endpoints — see Usage Examples.
Thread safety
A PdfGenerator instance is not thread-safe. Use a separate instance per thread — e.g. one per web request or one per item in a parallel batch — which is safe and is the intended way to generate PDFs concurrently. See Thread safety in Usage Examples for the full explanation and code samples.
Trimming and Native AOT
PeachPDF is built to be trimming-safe and Native AOT-compatible: the library sets IsTrimmable and IsAotCompatible, so it compiles cleanly under the trim and AOT analyzers and publishes as a fully native, self-contained executable with no runtime code generation. You can reference it from a PublishTrimmed or PublishAot application and generate PDFs from the native binary without any additional configuration. All platform interop uses source-generated LibraryImport marshalling rather than reflection-based DllImport, so nothing PeachPDF calls is stripped by the trimmer. The standalone peachpdf command-line tool is itself published this way — a fully native, self-contained binary per platform.
Guides
- Architecture — how PeachPDF converts HTML to PDF: the HTML parser, DOM model, CSS parser, layout engine, painting layer, and PDF renderer.
- HTML & CSS Support — the full compatibility matrix of supported HTML elements, CSS properties, selectors, and at-rules, including notes on gaps and PeachPDF-specific extensions.
- Supported SVG Features — the full compatibility matrix for inline and standalone SVG, rendered as real vector PDF content rather than rasterized bitmaps.
- How PeachPDF Is Tested — the automated test suite, the CI matrix, the diff-coverage gate, and the two-renderer rasterization checks that verify output actually renders correctly.
- Usage Examples — copy-pasteable examples: local HTML strings, MHTML files, HTTP fetching, shared CSS contexts, saving to disk, fonts, tagged PDF (PDF/UA) output, PDF/A-conformant output, and returning PDFs from ASP.NET Core (controllers and Minimal APIs) and Azure Functions.
- Command-Line Tool — the standalone
peachpdfCLI (a self-contained Native AOT binary) for rendering HTML to PDF from the shell, without writing any code. - Feature Showcase — real PDFs rendered by the current release at site build time, each paired with the exact HTML source it was generated from.
- API Reference — generated reference for every public type and member, always in sync with the latest source.