A comprehensive PDF generation toolkit that combines HTML, Markdown, and Razor-friendly templates with PuppeteerSharp-driven rendering. The package targets .NET 10.0 and focuses on documentation, reporting, and knowledge-base publishing scenarios.
| Folder/File | Description |
|---|---|
PdfGenerator.cs |
High-level faΓ§ade that orchestrates parsing, templating, and rendering |
Options/ |
Strongly-typed configuration objects for layout, TOC, headers/footers, and theming |
Models/ |
Data models for module descriptions, contributors, sections, and asset manifests |
Services/ |
Internal services (resource loader, Markdown engine, template renderer, metadata composer) |
templates/ |
Default HTML/CSS/JS assets embedded into the assembly |
var options = new PdfGeneratorOptions
{
Title = "DKNet Platform Overview",
Theme = PdfTheme.Dark,
TableOfContents = new TableOfContentsOptions { Enabled = true, MaxDepth = 3 }
};
var generator = new PdfGenerator(options, logger: logger);
await generator.GenerateFromMarkdownAsync(
markdownPath: "architecture.md",
outputPdfPath: "architecture.pdf",
cancellationToken: cancellationToken);
GenerateFromMarkdownAsync β Parses Markdown via Markdig with extension pipelines for tables, emojis, and syntax code blocks.GenerateFromHtmlAsync β Accepts raw HTML strings or files for direct rendering.GenerateFromTemplateAsync β Feed strongly typed models into Razor-compatible templates before rendering.PdfThemeOptions β Configure fonts, accent colours, syntax highlighting theme, and page background.HeaderFooterOptions β Custom HTML fragments rendered on every page; supports metadata tokens (page numbers, module info).TableOfContentsOptions β Toggle TOC visibility, numbering styles, and heading depth.ModuleInformation β Provide version numbers, changelog data, contributor lists, and release channels.templates/ are hydrated with module information and user options.IResourceProvider implementation or overriding paths via options.IConversionEvents to hook into lifecycle events (before/after render, asset injection).AdditionalResources on the options model.DKNet.Svc.PdfGenerators lives in the Application Layer of the Onion Architecture, orchestrating presentation-ready
assets for publication while keeping the Domain Layer agnostic of rendering concerns. Storage abstractions from the
Blob Storage packages can persist generated PDFs, and background jobs (see DKNet.AspCore.Tasks) can schedule batch exports.
PdfGenerator instance when producing multiple documents with identical configuration to reduce startup cost.Unit tests exercise Markdown parsing, option validation, and template selection. Integration tests leverage PuppeteerSharp with mocked Chromium binaries to verify TOC output, metadata propagation, and code highlighting.