PeachPDF
PeachPDF
PdfGenerator Class
Renders HTML (and optionally CSS) into a PDF document entirely in-process, with no external
browser or process dependency. This is the main entry point for PeachPDF: use one of the
GeneratePdf overloads to create a new PeachPdfDocument, or one of the
AddPdfPages overloads to append rendered pages to an existing one.
public class PdfGenerator
Inheritance System.Object → PdfGenerator
Remarks
A PdfGenerator instance is not thread-safe. Its brush/pen caches, font
resolver, and network loader are owned exclusively by that instance, so calling its methods
concurrently from multiple threads on the same instance (or reusing one instance across
overlapping renders) is not supported and can corrupt its internal state. This includes every
custom font registered on it — via @font-face or AddFontFromStream(Stream) — whose
resolved glyph/metrics data lives in caches private to that instance, so two instances that
register different bytes under the same font family name never collide.
Using a separate
| Methods | |
|---|---|
| AddFontFamilyMapping(string, string) | Adds a font mapping from fromFamily to toFamily iff the fromFamily is not found. When the fromFamily font is used in rendered html and is not found in existing fonts (installed or added) it will be replaced by toFamily. |
| AddFontFromStream(Stream) | Add a font to be rendered |
| AddFontFromStream(Stream, IReadOnlyList<RuneRange>) | Add a font to be rendered, restricting it to the given codepoint ranges - the programmatic equivalent of an @font-faceunicode-range descriptor. Characters outside these ranges resolve to another registered font (per-codepoint font matching). Pass an empty list to register a font that is never selected by codepoint coverage. |
| AddPdfPages(PeachPdfDocument, string, PageSize, int, PeachPdfCssContent) | Create PDF pages from given HTML and appends them to the provided PDF document. |
| AddPdfPages(PeachPdfDocument, string, PdfGenerateConfig, PeachPdfCssContent) | Create PDF pages from given HTML and appends them to the provided PDF document. |
| GeneratePdf(string, PageSize, int, PeachPdfCssContent) | Create PDF document from given HTML. |
| GeneratePdf(string, PdfGenerateConfig, PeachPdfCssContent) | Create PDF document from given HTML. |
| ParseStyleSheet(string, bool) | Parses the given stylesheet into a reusable PeachPdfCssContent object. If combineWithDefault is true the parsed css blocks are added to the default css data (as defined by the CSS 2.1 default stylesheet for HTML), merged if class name already exists. If false only the data in the given stylesheet is returned. |