DKNet

DKNet.Svc.PdfGenerators

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.

🧰 Feature Set

πŸ—‚οΈ Project Structure

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

πŸš€ Quick Start

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);

βš™οΈ Configuration Highlights

Content Sources

Layout & Theming

Rendering Pipeline

  1. Content is normalised (Markdown β†’ HTML) and merged with YAML front matter metadata.
  2. Templates from templates/ are hydrated with module information and user options.
  3. PuppeteerSharp spins up a headless Chromium instance to render the HTML to PDF with the specified paper size.
  4. Post-processors update metadata, embed outlines, and wire up TOC links.

🧩 Extensibility

🧱 Architectural Role

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.

βœ… Best Practices

πŸ§ͺ Testing Guidance

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.