How jhaygood86/peachpdf works
PeachPDF is a pure .NET 8+ HTML/CSS-to-PDF renderer, with optional direct C# document construction. The principal workflow is initiated by an external .NET library consumer calling PdfGenerator.GeneratePdf; PeachPDF loads supplied or configured content, resolves document styling and layout, renders specialized text/vector content, and returns a PDF document the consumer can save.
Public interfaces and hosts
• External .NET library consumer — null repository path; invokes the documented PdfGenerator.GeneratePdf or CreateDocument API and owns saving the returned document.
• .NET rendering facade — src/PeachPDF; exposes the documented HTML rendering, configuration, font-registration, and declarative document-building API.
• External CLI user — null repository path; invokes the documented peachpdf shell command.
• CLI conversion runner — src/PeachPDF.Cli/CliRunner.cs; participates in the standalone command-line HTML-to-PDF conversion application, though its detailed wiring was not sampled.
• External browser-demo user — null repository path; supplies content in the WebAssembly demo.
• WebAssembly demo host — src/PeachPDF.Demo.BlazorWasm/Program.cs; hosts the browser demo that the README says runs the same renderer locally for HTML, MHTML, and ZIP input.
Content, CSS, and document layout
• External content/resource source — null repository path; represents caller-selected local files, MHTML streams, or HTTP URI resources.
• Network and local resource loading — src/PeachPDF/Network; contains the loader subsystem documented to resolve HTML and relative stylesheets, images, and fonts from file, URI, MHTML, or data sources.
• CSS parser, cascade, and property model — src/PeachPDF/CSS; provides the CSS token, parser, rule, selector, value, and typed-property machinery used by rendering.
• HTML DOM, pagination, and box layout — src/PeachPDF/Html/Core; owns HTML box-tree construction, CSS layout, fragmentation, painting support, and document-level rendering behavior.
• Generated-content resolver — src/PeachPDF/Html/Core/Dom/CssContentEngine.cs; tokenizes CSS content, resolves text, quotes, images/gradients, counters, strings, and leader() segments for boxes and pseudo-elements.
• CSS counter resolver — src/PeachPDF/Html/Core/Dom/CssCounterEngine.cs; inherits, resets, sets, increments, and formats CSS counters for generated content and list markers, with decimal fallback for invalid styles.
Text and fonts
• Bidi and text-shaping support — src/PeachPDF/Text/Bidi; supplies the text-direction subsystem used by layout’s documented UAX#9 bidi behavior.
• Automatic hyphenation engine — src/PeachPDF/Text/HyphenationEngine.cs; lazily loads embedded Brotli-compressed patterns for roughly 70 languages, resolves BCP-47-like language tags, and applies Liang/TeX hyphenation scoring.
• Font discovery and OpenType processing — src/PeachPDF/Fonts; provides system/custom/web-font support and OpenType data needed for glyph selection, fallback, metrics, and specialized layout.
Specialized vector layout
• SVG rendering subsystem — src/PeachPDF/Svg; implements the repository’s native-vector SVG capability for inline and referenced SVG content.
• MathML Core layout engine — src/PeachPDF/MathML/MathLayoutEngine.cs; transforms a MathML node tree into positioned math boxes, using OpenType MATH metrics and glyph assemblies where available, with metric fallbacks otherwise.
PDF output
• Embedded PDF graphics and serialization backend — src/PeachPDF/PdfSharpCore; is the embedded fork identified by the README as PeachPDF’s PDF document, drawing, structure, annotation, and serialization implementation.
• External PDF document/output destination — null repository path; is the returned document and any stream or file destination written through its documented Save operation.
Relationships
• External .NET library consumer -> .NET rendering facade: invokes GeneratePdf or CreateDocument; evidence: README API examples.
• .NET rendering facade -> Network and local resource loading: requests configured content and relative assets when a NetworkLoader is used; evidence: README loader examples.
• Network and local resource loading -> External content/resource source: reads local, MHTML, or HTTP-backed document resources; evidence: README behavior.
• .NET rendering facade -> HTML DOM, pagination, and box layout: submits HTML or the declaratively built document for rendering; evidence: README describes HTML-to-PDF and C# document construction.
• HTML DOM, pagination, and box layout -> CSS parser, cascade, and property model: applies CSS parsing and resolved properties during box layout; evidence: CSS/HTML subsystem organization and the generated-content implementation’s CSS parser use.
• HTML DOM, pagination, and box layout -> Generated-content resolver: resolves pseudo-element and box content during layout; evidence: generated-content source identifies CssBox.ParseToWordsWithLeaders as its consumer.
• Generated-content resolver -> CSS parser, cascade, and property model: tokenizes and parses content and image values through CssValueParser; evidence: direct calls in the source.
• Generated-content resolver -> CSS counter resolver: resolves counter() content through the shared counter-style resolver; evidence: counter-engine source documentation names CssContentEngine.
• HTML DOM, pagination, and box layout -> Bidi and text-shaping support: applies bidi resolution and line reordering for mixed-direction text; evidence: sampled layout tests identify real UAX#9 handling in layout.
• HTML DOM, pagination, and box layout -> Automatic hyphenation engine: requests hyphenation points for hyphens: auto; evidence: hyphenation-engine source documentation names CssBox.ParseToWords and CssLayoutEngine.FlowBox.
• HTML DOM, pagination, and box layout -> SVG rendering subsystem: renders supported SVG document content as vectors; evidence: README feature description.
• HTML DOM, pagination, and box layout -> MathML Core layout engine: dispatches inline MathML to specialized math layout; evidence: README MathML support and the engine’s MathNode-to-MathBox role.
• MathML Core layout engine -> Font discovery and OpenType processing: resolves math fonts and reads OpenType MATH metrics/assemblies; evidence: direct ResolveFont and OpenType imports in the source.
• HTML DOM, pagination, and box layout -> Embedded PDF graphics and serialization backend: renders the laid-out document into a PDF representation; evidence: documented HTML-to-PDF product behavior, although the bridge call site was not sampled.
• Embedded PDF graphics and serialization backend -> External PDF document/output destination: materializes the PDF document that callers save; evidence: README document.Save(stream) examples.
• .NET rendering facade -> External .NET library consumer: returns the generated PDF document; evidence: README assignment of await generator.GeneratePdf(...).
• External CLI user -> CLI conversion runner: starts conversion with peachpdf report.html -o report.pdf; evidence: README CLI example.
• CLI conversion runner -> External PDF document/output destination: creates the requested PDF file; evidence: README describes the command as HTML-to-PDF conversion.
• External browser-demo user -> WebAssembly demo host: supplies browser-local HTML, MHTML, or ZIP content; evidence: README demo description.
• WebAssembly demo host -> .NET rendering facade: renders with the same library in WebAssembly; evidence: README statement.
Coverage limits
The sampled source does not include PdfGenerator, network-loader implementations, CLI startup code, or the renderer-to-PDF bridge, so their precise call order, object lifetimes, and error handling cannot be established. SVG and demo internals were not sampled; their responsibilities above rely on documented behavior plus repository organization.
Main entry points: Core HTML Layout Engine · PeachPDF .NET Rendering Facade · CssContentEngine.cs Generated Content Resolver · CliRunner.cs CLI Conversion Runner
Components 19
Public Interfaces
Library, CLI, and browser-demo entry points
- .NET Library Consumer · Calls GeneratePdf or CreateDocument and saves the returned document
- .NET Rendering Facade · Documented HTML rendering, configuration, font registration, and document-building API
src/PeachPDF - External CLI User · Invokes the peachpdf shell command
- CLI Conversion Runner · Runs standalone command-line HTML-to-PDF conversion
src/PeachPDF.Cli/CliRunner.cs - External Browser-Demo User · Supplies content to the WebAssembly demo
- WebAssembly Demo Host · Hosts browser-local rendering for HTML, MHTML, and ZIP input
src/PeachPDF.Demo.BlazorWasm/Program.cs
Content and Layout
Resource loading, CSS, HTML layout, and generated content
- External Content Source · Caller-selected local files, MHTML streams, or HTTP URI resources
- Resource Loading · Resolves HTML and relative stylesheets, images, and fonts
src/PeachPDF/Network - CSS Parser and Cascade · Parses CSS rules, selectors, values, and typed properties
src/PeachPDF/CSS - HTML Layout Engine · Builds box trees, paginates, fragments, paints, and renders documents
src/PeachPDF/Html/Core - Generated Content Resolver · Resolves content tokens, quotes, images, counters, strings, and leaders
src/PeachPDF/Html/Core/Dom/CssContentEngine.cs - CSS Counter Resolver · Handles counter inheritance, resets, increments, and formatting
src/PeachPDF/Html/Core/Dom/CssCounterEngine.cs
Text and Fonts
Text direction, hyphenation, and font processing
- Bidi Text Shaping · Provides text direction and UAX#9 line reordering
src/PeachPDF/Text/Bidi - Automatic Hyphenation · Loads language patterns and computes hyphenation points
src/PeachPDF/Text/HyphenationEngine.cs - Font and OpenType Processing · Provides font discovery, fallback, metrics, glyph selection, and OpenType data
src/PeachPDF/Fonts
Specialized Layout
SVG and MathML rendering
- SVG Rendering · Renders inline and referenced SVG content as native vectors
src/PeachPDF/Svg - MathML Layout Engine · Positions MathML boxes using OpenType MATH metrics and glyph assemblies
src/PeachPDF/MathML/MathLayoutEngine.cs
PDF Output
PDF serialization and output destinations
- PDF Graphics Backend · Embedded document, drawing, structure, annotation, and serialization implementation
src/PeachPDF/PdfSharpCore - PDF Output Destination · Returned document and stream or file destination written through Save
Connections 20
- .NET Library Consumer → .NET Rendering Facade: invokes API · Calls GeneratePdf or CreateDocument
- .NET Rendering Facade → Resource Loading: requests resources · Requests configured content and relative assets when using a NetworkLoader
- Resource Loading → External Content Source: reads resources · Reads local, MHTML, or HTTP-backed document resources
- .NET Rendering Facade → HTML Layout Engine: submits document · Submits HTML or a declaratively built document for rendering
- HTML Layout Engine → CSS Parser and Cascade: applies CSS · Applies parsed and resolved properties during box layout
- HTML Layout Engine → Generated Content Resolver: resolves content · Resolves pseudo-element and box content during layout
- Generated Content Resolver → CSS Parser and Cascade: parses values · Tokenizes and parses content and image values
- Generated Content Resolver → CSS Counter Resolver: resolves counters · Uses the shared counter-style resolver for counter content
- HTML Layout Engine → Bidi Text Shaping: reorders text · Applies bidi resolution and line reordering
- HTML Layout Engine → Automatic Hyphenation: requests hyphenation · Requests points for hyphens: auto
- HTML Layout Engine → SVG Rendering: renders SVG · Renders supported SVG document content as vectors
- HTML Layout Engine → MathML Layout Engine: dispatches MathML · Dispatches inline MathML to specialized layout
- MathML Layout Engine → Font and OpenType Processing: resolves math fonts · Reads OpenType MATH metrics and assemblies
- HTML Layout Engine → PDF Graphics Backend: renders PDF · Renders the laid-out document into a PDF representation
- PDF Graphics Backend → PDF Output Destination: writes document · Materializes the PDF document callers save
- .NET Rendering Facade → .NET Library Consumer: returns document · Returns the generated PDF document
- External CLI User → CLI Conversion Runner: starts conversion · Invokes peachpdf report.html -o report.pdf
- CLI Conversion Runner → PDF Output Destination: creates PDF file · Creates the requested PDF file
- External Browser-Demo User → WebAssembly Demo Host: supplies content · Supplies browser-local HTML, MHTML, or ZIP content
- WebAssembly Demo Host → .NET Rendering Facade: renders locally · Uses the same library in WebAssembly