MdToPdf.Renderer
6.2.0-preview-2
dotnet add package MdToPdf.Renderer --version 6.2.0-preview-2
NuGet\Install-Package MdToPdf.Renderer -Version 6.2.0-preview-2
<PackageReference Include="MdToPdf.Renderer" Version="6.2.0-preview-2" />
<PackageVersion Include="MdToPdf.Renderer" Version="6.2.0-preview-2" />
<PackageReference Include="MdToPdf.Renderer" />
paket add MdToPdf.Renderer --version 6.2.0-preview-2
#r "nuget: MdToPdf.Renderer, 6.2.0-preview-2"
#:package MdToPdf.Renderer@6.2.0-preview-2
#addin nuget:?package=MdToPdf.Renderer&version=6.2.0-preview-2&prerelease
#tool nuget:?package=MdToPdf.Renderer&version=6.2.0-preview-2&prerelease
MdToPdf.Renderer
A .NET 8 library that converts Markdown to PDF using PdfSharp 6.x.
No headless browser, no external process - a pure managed pipeline from Markdown string to PdfDocument.
Features
- Headings - ATX-style H1-H6 with proportional sizing
- Inline formatting - bold, italic, inline code, and combinations
- Fenced code blocks - monospace font with a shaded background
- Blockquotes - with a left accent bar
- Lists - unordered and ordered, including nested levels
- Hyperlinks - external URLs and
#anchorinternal links with PDF annotations - Images - local file paths and
data:URIs - Thematic breaks - rendered as a thin horizontal rule
- Auto-bookmarks - PDF outline built automatically from heading hierarchy
- Password protection - user/owner passwords with granular permissions
- Compression - DEFLATE content-stream compression
- Progress reporting - callback with 0-100 percent as pages are rendered
- Per-page error handling - continue or abort on render failures
- Custom fonts - register TTF bytes or load a folder at startup
Installation
dotnet add package MdToPdf.Renderer
Usage
Minimal
using MdToPdf.Renderer;
using var doc = PdfGenerator.GeneratePdf(markdown, new PdfOptions
{
PageSize = PageSize.A4,
MarginTop = 40, MarginBottom = 40,
MarginLeft = 50, MarginRight = 50
});
doc.Save("output.pdf");
Fluent builder
var bytes = await PdfGenerator.Create()
.WithPageSize(PageSize.A4)
.WithMargin(40)
.WithBookmarks()
.WithCompression()
.GeneratePdfAsync(markdown);
await File.WriteAllBytesAsync("output.pdf", bytes);
Async (returns byte[])
byte[] bytes = await PdfGenerator.GeneratePdfAsync(markdown, options);
PdfOptions reference
PageSize(XSize, default A4) - usePageSize.A4,Letter,Legal,A3PageOrientation(default Portrait) -PortraitorLandscapeMarginTop / MarginBottom / MarginLeft / MarginRight(double, default 0) - page margins in pointsBaseFontSize(double, default 11) - body text size in pointsBodyFontFamily(string, default"Arial") - font family for body textMonospaceFontFamily(string, default"Courier New") - font family for code blocksLineHeight(double, default 1.4) - line height multiplierAutoBookmarks(bool, defaultfalse) - build PDF outline from headingsCompressOutput(bool, defaultfalse) - DEFLATE compress content streamsSecurity(PdfSecurityOptions?, defaultnull) - password and permissionsOnProgress(Action<int>?) - callback with percent 0–100OnRenderError(Action<Exception>?) - per-page error callbackContinueOnError(bool, defaultfalse) - skip failed pages instead of throwingImageLoadFailureMode(defaultRenderAltText) -RenderAltTextorThrow
Auto-bookmarks
var doc = PdfGenerator.Create()
.WithBookmarks()
.GeneratePdf(markdown);
Headings become a nested PDF outline. H1 at the root, H2 nested under the preceding H1, and so on.
Internal #anchor links in the Markdown resolve to heading positions via slug matching.
Password protection
var options = new PdfOptions
{
Security = new PdfSecurityOptions
{
UserPassword = "open",
OwnerPassword = "admin",
Permissions = PdfPermissions.Print | PdfPermissions.CopyContent
}
};
PdfPermissions flags: Print, HighQualityPrint, ModifyContent, CopyContent,
Annotate, FillForms, AssembleDocument, All, ReadOnly, None.
Compression
var doc = PdfGenerator.Create()
.WithCompression()
.GeneratePdf(markdown);
Enables DEFLATE compression on all content streams. Produces smaller files at the cost of slightly longer generation time.
Progress and error handling
var options = new PdfOptions
{
OnProgress = pct => Console.WriteLine($"Rendering: {pct}%"),
OnRenderError = ex => logger.LogError(ex, "Page render failed"),
ContinueOnError = true
};
OnProgress fires at 0 % before the first page and at (page / total) × 100 after each page.
When ContinueOnError is true, a failed page is left blank and rendering continues;
otherwise the exception propagates after calling OnRenderError.
Custom fonts
// Register a single font
byte[] fontBytes = File.ReadAllBytes("MyFont-Regular.ttf");
PdfGenerator.Create()
.WithFont("MyFont", fontBytes)
.GeneratePdf(markdown);
// Or load a whole folder at startup
PdfGenerator.LoadFontsFromFolder("/app/fonts");
On Windows, common system fonts (Arial, Calibri, Segoe UI, Verdana, etc.) are resolved
automatically. Custom fonts registered via WithFont take precedence over system mapping.
License
MIT. PDF rendering by PdfSharp (MIT, see NOTICE.txt).
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net8.0
- PDFsharp (>= 6.2.4)
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 |
|---|---|---|
| 6.2.0-preview-2 | 69 | 4/26/2026 |
| 6.2.0-preview-1 | 58 | 4/24/2026 |