Converts markdown files to styled PDF documents using Node.js, marked, and puppeteer-core. Supports Chinese/CJK text, code syntax highlighting, tables, and images.
.md file to PDFbash
# Convert a markdown file to PDF
node convert.js input.md
# Specify output file
node convert.js input.md output.pdf
# Without page numbers
node convert.js input.md --no-page-numbers
First-time setup in the target project directory:
bash
mkdir -p .md-to-pdf-tool && cd .md-to-pdf-tool
npm init -y
npm install marked@4.3.0 puppeteer-core@19.11.1
Then copy the convert.js script from this skill's directory.
FeatureSupportHeadings (H1-H6)Styled with hierarchyCode blocksSyntax highlighting via highlight.jsTablesBordered with zebra stripingListsBulleted and numberedImagesEmbedded (relative paths resolved)LinksClickable in PDFCJK/ChineseFull supportPage numbersBottom center by default
Edit the CSS in convert.js to customize:
font-family in body stylecolor and background values--marginTop, --marginBottom, etc. in optionspre and code background colorsIssueSolutionBrowser not foundSet CHROME_PATH or EDGE_PATH environment variablePermission deniedUse Edge instead of Chrome, or run with elevated permissionsESM module errorsUse marked@4.3.0 and puppeteer-core@19.11.1 (CommonJS compatible)Large file timeoutIncrease timeout in page.setContent() options
The conversion script uses:
See convert.js in this skill directory for the complete implementation.