A simple CLI tool for converting markdown to PDF.
It uses md4w
to convert markdown to HTML and playwright-core
(headless Chrome) to further convert the HTML to PDF. It also uses shiki
for code highlighting.
To run it, you need to have Google Chrome installed separately from the CLI.
deno install -grA jsr:@ryu/md2pdf/cli
Note: If you want to update the CLI, please reinstall with -f
flag.
md2pdf: A simple CLI tool for converting markdown to PDF.
Usage: md2pdf [OPTION]... [FILE]...
Options:
-w, --watch Watch for file changes.
-h, --help Print help.
-v, --version Print version.
--stylesheet Set CSS file path used for rendering.
The pdf is generated into the same directory as the markdown file and uses the same filename (with .pdf
extension):
md2pdf file.md
Convert multiple markdown files:
md2pdf file1.md file2.md file3.md
Watch for file changes and automatically regenerate PDF when the markdown file is modified:
md2pdf --watch file.md
This is useful for continuous development where you want to see PDF updates in real-time as you edit your markdown.
md2pdf supports reading from stdin
and writing to stdout
.
You can pipe markdown content directly to md2pdf, making it easy to integrate with other CLI tools:
# Convert piped input to PDF
cat file.md | md2pdf > path/to/output.pdf
# Use with curl to convert remote markdown
curl -s https://raw.githubusercontent.com/ryuapp/md2pdf/main/README.md | md2pdf > README.pdf
We can specify CSS file used in the front matter of markdown.
---
stylesheet: ./github.css
---
# Hello World
- md-to-pdf - Markdown to PDF CLI for Node.js.