A markdown renderer for PDFKit using mdast syntax tree.
MIT License
This package provides basic markdown rendering capabilites for PDFKit.
Given a mdast syntax tree as input, content is rendered to a given PDFDocument.
See the output for this README.md at README.pdf.
To render a given markdown string, install:
yarn add pdfkit-markdown mdast unified remark-parse
import { MarkdownRenderer } from "pdfkit-markdown";
import remarkParse from "remark-parse";
import { unified } from "unified";
import PDFDocument from "pdfkit";
...
const tree = unified()
.use(remarkParse)
.parse("Markdown **Text**")
const doc = new PDFDocument()
new MarkdownRenderer(doc, { /* optional settings */ }).render(tree);
Currently supported elements:
Unsupported elements:
Fonts, sizes, indents etc. are configurable, see documentation on constructor.
pdfkit-commonmark provides similar functionality, but does not support TypeScript and uses the less maintained CommonMark parser.