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), plus net11.0 ahead of its official release, while it’s still a release-candidate build; 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 (including embedded-file attachments and ZUGFeRD / Factur-X e-invoices), password-protecting and restricting PDFs with AES-256 encryption, 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 (an SVG filter with a pixel primitive is the one exception, rendered as a bitmap).
- Supported MathML Features — the full compatibility matrix for inline
<math>formulas, rendered as real vector PDF content using the font’s own OpenTypeMATHtable. - 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 (including embedded-file attachments and ZUGFeRD / Factur-X e-invoices), and returning PDFs from ASP.NET Core (controllers and Minimal APIs) and Azure Functions.
- Declarative Document-Building API — build a PDF directly from C# with
PdfGenerator.CreateDocument, no HTML/CSS strings required: pages, containers, text, images, rows/columns, tables, lists, repeating headers/footers with page numbers, a document-level stylesheet with class/id selectors, splicing in HTML fragments (with slots) where needed, and stamping pages of an existing PDF over or under the document. - Command-Line Tool — the standalone
peachpdfCLI (a self-contained Native AOT binary) for rendering HTML to PDF from the shell, without writing any code. - PeachDrawing.Text — the font and text engine as its own NuGet package, with no third-party dependencies: loading and matching fonts, bidirectional text, script itemization, hyphenation and emoji presentation.
- PeachDrawing.Core — the drawing-surface abstraction PeachPDF targets to write PDF (
Canvas,RenderContext,Brush/Pen/GraphicsPath), as its own NuGet package — implement it yourself to target a different backend entirely. - PeachDrawing — a standalone CPU software rasterizer implementing
PeachDrawing.Core, usable with no PeachPDF reference at all: draw shapes, text and images onto a bitmap and save it in any PeachImage-supported format. - PeachDrawing.PDF — the PDF
CanvasPeachPDF renders through, usable with no PeachPDF reference at all: draw pages with the same drawing API and write them as PDF, with embedded font subsets and optional AES-256 encryption. - PeachDrawing.Svg — a vector SVG
Canvasfor the same drawing API, usable with no PeachPDF reference at all: draw pages and write them as SVG, with curves, gradients, clips and glyph outlines kept as vector content (or selectable text with an embedded subset font). - PeachBrackets — the HTML, CSS, SVG and MathML engine PeachPDF is built on, usable with no PDF involved: load a document, lay it out into pages, and paint each page onto any canvas.
- PeachImage — the pure .NET image codec library PeachPDF decodes images with: load, convert, resize and save JPEG, PNG, GIF, WebP, AVIF, BMP, TIFF and JPEG XL, with no native dependencies.
- Feature Showcase — real PDFs rendered by the current release at site build time, each paired with the exact HTML (or, for the declarative API, C#) source it was generated from.
- API Reference — generated reference for every public type and member of PeachPDF, always in sync with the latest source, with a reference for each of the
PeachDrawing.Core,PeachDrawing,PeachDrawing.TextandPeachImagepackages beside it.