DKNet.Svc.PdfGenerators
10.1.24
dotnet add package DKNet.Svc.PdfGenerators --version 10.1.24
NuGet\Install-Package DKNet.Svc.PdfGenerators -Version 10.1.24
<PackageReference Include="DKNet.Svc.PdfGenerators" Version="10.1.24" />
<PackageVersion Include="DKNet.Svc.PdfGenerators" Version="10.1.24" />
<PackageReference Include="DKNet.Svc.PdfGenerators" />
paket add DKNet.Svc.PdfGenerators --version 10.1.24
#r "nuget: DKNet.Svc.PdfGenerators, 10.1.24"
#:package DKNet.Svc.PdfGenerators@10.1.24
#addin nuget:?package=DKNet.Svc.PdfGenerators&version=10.1.24
#tool nuget:?package=DKNet.Svc.PdfGenerators&version=10.1.24
DKNet.Svc.PdfGenerators
PDF generation from HTML or Markdown, via headless Chromium (PuppeteerSharp) and Markdig. Fork of
Markdown2Pdf 2.x — see THIRD-PARTY-NOTICES.md in the package for upstream attribution.
Features
IPdfGenerator— convert an HTML string, an HTML file, a Markdown file, or several Markdown files into one PDF- Chromium print layout: paper format, orientation, scale, margins, and repeated HTML header/footer templates
- Chromium is downloaded on demand when no
ChromePathis configured, so a container needs no browser baked in --no-sandboxis applied automatically whenCIorGITHUB_ACTIONSis"true"
Installation
dotnet add package DKNet.Svc.PdfGenerators
Quick Start
using DKNet.Svc.PdfGenerators;
using DKNet.Svc.PdfGenerators.Options;
using Microsoft.Extensions.DependencyInjection;
builder.Services.AddPdfGenerator(new PdfGeneratorOptions
{
MarginOptions = new MarginOptions { Top = "2cm", Bottom = "2cm", Left = "1.5cm", Right = "1.5cm" }
});
public sealed class ReportExporter(IPdfGenerator pdfGenerator)
{
// writes ./reports/monthly.pdf and returns its full path
public Task<string> ExportAsync(string markdownPath) =>
pdfGenerator.ConvertMarkdownFileAsync(markdownPath, "reports/monthly.pdf");
}
AddPdfGenerator(PdfGeneratorOptions? options = null) builds one PdfGenerator immediately and registers it
as a singleton IPdfGenerator. The call is idempotent, so the first call's options are the ones the
instance keeps for the process lifetime.
Configuration — PdfGeneratorOptions
The Applied column says whether the current PdfGenerator pipeline reads the value. Several option types
carried over from upstream are settable and serializable but never read — do not design a document around them.
| Option | Type | Default | Effect | Applied |
|---|---|---|---|---|
Format |
PaperFormat (PuppeteerSharp) |
PaperFormat.A4 |
Paper size passed to Chromium. | ✅ |
IsLandscape |
bool |
false |
Landscape orientation. | ✅ |
Scale |
decimal |
1 |
Render scale. | ✅ |
MarginOptions |
MarginOptions? |
null |
Top/Bottom/Left/Right as CSS strings ("1cm"); null leaves Chromium's defaults. |
✅ |
HeaderHtml |
string? |
null |
Chromium header template; setting it (or FooterHtml) turns the header/footer on. |
✅ |
FooterHtml |
string? |
null |
Chromium footer template. | ✅ |
ChromePath |
string? |
null |
Path to an existing Chromium/Chrome; null downloads a build on demand. |
✅ |
Theme |
Theme |
Theme.Github |
Github / Latex / None / Custom(cssPath). |
❌ |
CodeHighlightTheme |
CodeHighlightTheme |
CodeHighlightTheme.Github |
One of 75 highlight.js stylesheets exposed as static properties. | ❌ |
ModuleOptions |
ModuleOptions |
ModuleOptions.Remote |
Remote / None / FromLocalPath(path) for MathJax, Mermaid and highlight.js assets. |
❌ |
TableOfContents |
TableOfContentsOptions? |
null |
See the nested table below. | ❌ |
DocumentTitle |
string? |
null |
Document title. | ❌ |
MetadataTitle |
string? |
null |
PDF metadata title. | ❌ |
CustomHeadContent |
string? |
null |
Extra markup for the generated <head>. |
❌ |
KeepHtml |
bool |
false |
Keep the intermediate HTML for debugging. | ❌ |
EnableAutoLanguageDetection |
bool |
false |
Auto-detect code-block languages. | ❌ |
Nested option types
MarginOptions — Top, Bottom, Left, Right, all string?, all null by default.
TableOfContentsOptions:
| Option | Type | Default | Effect |
|---|---|---|---|
MinDepthLevel |
int |
1 |
Shallowest heading level; outside 1..6 throws ArgumentOutOfRangeException. |
MaxDepthLevel |
int |
6 |
Deepest heading level; same guard. |
ListStyle |
ListStyle |
OrderedDefault |
None, OrderedDefault, Unordered, Decimals. |
HasColoredLinks |
bool |
false |
Leave TOC links in the theme's link colour. |
PageNumberOptions |
PageNumberOptions? |
null |
Non-null asks for page numbers. |
PageNumberOptions — TabLeader (Leader, default Leader.Dots; values None, Dots, Underline, Dashes).
ModuleOptions has a protected internal constructor; get an instance from ModuleOptions.None,
ModuleOptions.Remote, or ModuleOptions.FromLocalPath(path). Theme has no public constructor; use
Theme.Github, Theme.Latex, Theme.None, or Theme.Custom(cssPath) — PredefinedTheme is internal, so a
predefined theme can be selected but not constructed or extended.
SerializableOptions mirrors PdfGeneratorOptions with nullable, mostly string-typed properties and converts
via ToPdfGeneratorOptions(); an unset property leaves the target at its default. Named values resolve by
reflection against the target type's static properties: an unknown Theme string becomes Theme.Custom(value),
an unknown ModuleOptions string becomes ModuleOptions.FromLocalPath(value), and an unknown Format or
CodeHighlightTheme string is ignored. InlineOptionsParser.ParseYamlFrontMatter(path) reads the same shape
out of a Markdown file's front matter using hyphenated keys.
Documentation
Full feature reference, diagrams, and gotchas: https://github.com/baoduy/DKNet/blob/main/docs/Services/DKNet.Svc.PdfGenerators.md
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Markdig (>= 1.3.2)
- PdfPig (>= 0.1.16)
- PuppeteerSharp (>= 25.8.0)
- YamlDotNet (>= 18.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 10.1.24 | 39 | 9/11/2026 |
| 10.1.23 | 36 | 9/11/2026 |
| 10.1.22 | 42 | 9/11/2026 |
| 10.1.21 | 45 | 9/11/2026 |
| 10.1.20 | 65 | 9/9/2026 |
| 10.1.19 | 85 | 9/3/2026 |
| 10.1.18 | 83 | 9/3/2026 |
| 10.1.17 | 87 | 9/3/2026 |
| 10.1.16 | 86 | 9/3/2026 |
| 10.1.15 | 81 | 9/1/2026 |
| 10.1.14 | 81 | 9/1/2026 |
| 10.1.13 | 90 | 8/31/2026 |
| 10.1.12 | 100 | 8/25/2026 |
| 10.1.11 | 101 | 8/24/2026 |
| 10.1.10 | 101 | 8/22/2026 |
| 10.1.9 | 102 | 8/22/2026 |
| 10.1.8 | 94 | 8/21/2026 |
| 10.1.7 | 98 | 8/21/2026 |
| 10.1.6 | 94 | 8/21/2026 |
| 10.1.5 | 120 | 8/20/2026 |