Skip to content

Instantly share code, notes, and snippets.

@januszm
Created June 30, 2026 11:02
Show Gist options
  • Select an option

  • Save januszm/4a02ac002bbd09bfc63e8d3e0a24d390 to your computer and use it in GitHub Desktop.

Select an option

Save januszm/4a02ac002bbd09bfc63e8d3e0a24d390 to your computer and use it in GitHub Desktop.
Markdown to PDF build CLI
#!/usr/bin/env bash
# Requires: pandoc (brew install pandoc), Google Chrome
set -euo pipefail
MD="file.md"
HTML="file.html"
CSS="file.css"
PDF="file.pdf"
CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
# 1. Markdown -> standalone HTML (custom CSS embedded, wrapped in .page div)
pandoc "$MD" \
--standalone \
--css="$CSS" \
--include-before-body=page-open.html \
--include-after-body=page-close.html \
--embed-resources \
-o "$HTML"
# 2. HTML -> PDF via headless Chrome
"$CHROME" \
--headless \
--disable-gpu \
--print-to-pdf="$PDF" \
--no-pdf-header-footer \
"file://$(pwd)/$HTML"
echo "Built $HTML and $PDF from $MD"
# page-open.html
# <div class="page">
# page-close.html
# </div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment