Created
June 30, 2026 11:02
-
-
Save januszm/4a02ac002bbd09bfc63e8d3e0a24d390 to your computer and use it in GitHub Desktop.
Markdown to PDF build CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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