Docs 1.20.0: Markdown
Download PDF Changelog

This is the manual for PdfPecker 1.20.0. Read it for the latest version, 1.25.0.

Markdown

Markdown goes to PDF through the same engine as HTML: it is turned into HTML with a GitHub-like stylesheet first, so everything on HTML and CSS support applies to it. You can also stop at the HTML.

// Markdown to PDF, styled like a GitHub README
byte[] pdf = MarkdownToPdf.Convert(File.ReadAllText("README.md"));

// File to file; relative image paths resolve against the Markdown file's folder
MarkdownToPdf.ConvertFile("README.md", "README.pdf", new PdfOptions { FooterText = "Page {page} of {pages}" });

// Markdown to HTML: a body fragment, or a complete page with the stylesheet
string fragment = MarkdownToHtml.Convert("# Hello\n\n*World*");     // <h1 id="hello">Hello</h1>\n<p><em>World</em></p>
string page = MarkdownToHtml.ConvertDocument(markdown);
MarkdownToHtml.ConvertFile("README.md", "README.html");

MarkdownOptions switches the GitHub extensions off for strict CommonMark (GitHubExtensions = false), drops heading ids (HeadingIds = false), shows raw HTML as text (AllowRawHtml = false), replaces the stylesheet (StyleSheet, see MarkdownToHtml.DefaultStyleSheet) or sets the title (default: the front matter's title, else the first heading). MarkdownToPdf takes PdfOptions and MarkdownOptions side by side.

What is supported

CommonMark 0.31 (651 of the 652 spec examples pass; the one miss is an exotic HTML5 entity name) plus the GitHub Flavored Markdown extensions: tables with column alignment, ~~strikethrough~~, task list items (- [x]) and bare www./https:///e-mail autolinks, along with footnotes, definition lists and YAML front matter (see below). Headings get GitHub-style ids, so [see below](#heading-text) links work in the PDF too. The parser runs in linear time on hostile input (deep nesting, unclosed brackets, long delimiter runs). See Limitations for what is not supported.

Footnotes, definition lists and front matter

Footnotes use GitHub's syntax and are numbered in the order they are first referenced. MarkdownToPdf puts each note at the bottom of the page that references it, with the CSS float: footnote engine, so this also works with your own StyleSheet; MarkdownToHtml lists the notes at the end with links back to the text, as GitHub does.

PdfPecker has no dependencies.[^bcl]

[^bcl]: Only the .NET base class library.

A definition list is a term on its own line followed by one or more lines starting with : , as in PHP Markdown Extra and markdown-it. Front matter between --- lines at the very start of the file is not shown; its title becomes the document's title (the PDF title, and <title> in HTML) unless MarkdownOptions.Title is set.

---
title: Release notes
---

Subset
: Only the glyphs a document uses are embedded.

All three are GitHub extensions, so GitHubExtensions = false turns them off along with tables and strikethrough.