Md2pdf Export logo

Md2pdf Export

Community
wentorai
md2pdf-export

Convert Markdown files to PDF, PNG, or JPEG using headless Chrome (Puppeteer), following the same methodology as VS Code's Markdown Preview Enhanced extension. Use this skill whenever the user asks to: export/convert/render markdown to PDF or image, generate a printable document from .md files, create publication-ready PDFs from markdown, set up a markdown-to-PDF pipeline, or install/configure the Node.js + Puppeteer + Chrome environment needed for headless rendering. Also trigger when the user mentions "md2pdf", "markdown export", "puppeteer PDF", "headless chrome PDF", "crossnote", "mume", or wants WYSIWYG-quality PDF output from markdown source files. This skill covers both environment setup AND the actual conversion process.

Overview

Publisherwentorai
RepositoryResearch-Claw
Skill namemd2pdf-export
Stars
859
Forks
117
Bundled files
6
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 6 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by wentorai on GitHub. Read the source before you install it.

Installation

Install the Md2pdf Export AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/wentorai/Research-Claw/tree/main/skills/md2pdf-export
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/wentorai/Research-Claw.git /tmp/Research-Claw
mkdir -p .claude/skills
cp -r /tmp/Research-Claw/skills/md2pdf-export .claude/skills/md2pdf-export
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Md2pdf Export in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Md2pdf Export on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Md2pdf Export is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Markdown → PDF/PNG/JPEG Export (Puppeteer Method)

Architecture Overview

The conversion pipeline mirrors Markdown Preview Enhanced's chromeExport():

Markdown (.md)
    │
    ▼  [markdown-it + plugins]
Standalone HTML (with embedded CSS, math, diagrams)
    │
    ▼  [Puppeteer launches headless Chrome]
Chrome loads the HTML via file:// protocol
    │
    ├──▶ page.pdf()        → PDF output
    ├──▶ page.screenshot() → PNG output
    └──▶ page.screenshot() → JPEG output

The key insight: Chrome IS the rendering engine. What Chrome renders is what you get — true WYSIWYG.


Step 0: Environment Check & Setup

Before any conversion, verify the environment is ready. Run the setup script:

bash
bash skills/md2pdf-export/scripts/setup-env.sh

This script is idempotent — safe to run multiple times. It handles:

  • Detecting OS (macOS / Ubuntu / Debian / Alpine / CentOS)
  • Installing Node.js (via nvm, prefers LTS)
  • Installing npm packages globally: puppeteer (which bundles Chromium)
  • Verifying Chrome/Chromium is launchable in headless mode
  • Printing a diagnostic summary

If the user's system already has Node.js ≥ 18 and puppeteer installed, the script skips those steps.

Manual Setup (if the script fails)

For environments where the automated script doesn't work (e.g. restricted Docker containers):

bash
# 1. Install Node.js >= 18
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
source ~/.bashrc  # or ~/.zshrc
nvm install --lts

# 2. Install puppeteer (bundles Chromium automatically)
npm install -g puppeteer

# 3. For Linux headless environments, install system dependencies
# Ubuntu/Debian:
sudo apt-get update && sudo apt-get install -y \
  ca-certificates fonts-liberation libasound2 libatk-bridge2.0-0 \
  libatk1.0-0 libcups2 libdbus-1-3 libdrm2 libgbm1 libgtk-3-0 \
  libnspr4 libnss3 libx11-xcb1 libxcomposite1 libxdamage1 \
  libxfixes3 libxrandr2 xdg-utils wget

# 4. Verify
node -e "const p = require('puppeteer'); p.launch({headless:'new'}).then(b => { console.log('OK'); b.close(); })"

Using an Existing Chrome Installation

If the system already has Chrome/Chromium installed, set the environment variable to skip Chromium download:

bash
export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true
export PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome  # or /usr/bin/chromium-browser

Step 1: Convert Markdown to HTML

Use markdown-it with plugins for a feature-rich render. The conversion script at skills/md2pdf-export/scripts/md2pdf.js handles this internally, but the logic is:

  1. Read the .md file
  2. Parse YAML front-matter (for puppeteer config overrides)
  3. Render Markdown → HTML via markdown-it with these plugins:
    • markdown-it-texmath + KaTeX for math ($...$, $$...$$)
    • markdown-it-highlightjs for syntax highlighting
    • markdown-it-anchor + markdown-it-toc-done-right for TOC
    • markdown-it-footnote for footnotes
  4. Wrap in a full HTML document with:
    • A CSS theme (GitHub-light by default, configurable)
    • Embedded styles for print (@media print rules)
    • All resources inlined (no external dependencies)

Step 2: Launch Headless Chrome & Export

The script then:

  1. Launches Puppeteer with headless: 'new' (new headless mode)
  2. Creates a new page, sets viewport (for PNG/JPEG) or paper size (for PDF)
  3. Loads the HTML via page.setContent() or page.goto('file://...')
  4. Waits for rendering to complete (waitUntil: 'networkidle0')
  5. Calls the appropriate Puppeteer API:
    • PDF: page.pdf({ path, format, printBackground, margin, ... })
    • PNG: page.screenshot({ path, fullPage: true, type: 'png' })
    • JPEG: page.screenshot({ path, fullPage: true, type: 'jpeg', quality })
  6. Closes the browser

Running the Conversion

Basic Usage

bash
# PDF (default)
node skills/md2pdf-export/scripts/md2pdf.js input.md

# PNG
node skills/md2pdf-export/scripts/md2pdf.js input.md --type png

# JPEG with quality
node skills/md2pdf-export/scripts/md2pdf.js input.md --type jpeg --quality 90

# Custom output path
node skills/md2pdf-export/scripts/md2pdf.js input.md -o output.pdf

# A3 landscape
node skills/md2pdf-export/scripts/md2pdf.js input.md --format A3 --landscape

Front-Matter Configuration

Users can embed Puppeteer config directly in the Markdown file's YAML front-matter:

yaml
---
puppeteer:
  format: A4
  landscape: false
  margin:
    top: "20mm"
    right: "20mm"
    bottom: "20mm"
    left: "20mm"
  printBackground: true
  displayHeaderFooter: true
  headerTemplate: '<span style="font-size:8px;width:100%;text-align:center;"><span class="title"></span></span>'
  footerTemplate: '<span style="font-size:8px;width:100%;text-align:center;"><span class="pageNumber"></span> / <span class="totalPages"></span></span>'
screenshot:
  fullPage: true
  width: 1200
  deviceScaleFactor: 2
export_on_save:
  puppeteer: true
---

CLI Options Reference

OptionDefaultDescription
--typepdfOutput type: pdf, png, jpeg
-o, --output<input>.pdfOutput file path
--formatA4Paper format (A3, A4, A5, Letter, Legal, Tabloid)
--landscapefalseLandscape orientation
--no-backgroundDisable printing background graphics
--margin10mmUniform margin (or use --margin-top etc.)
--quality80JPEG quality (1-100)
--scale1Device scale factor for screenshots
--width1200Viewport width for screenshots
--themegithubCSS theme: github, github-dark, minimal
--chrome-pathautoPath to Chrome/Chromium executable
--wait0Extra wait time in ms after page load
--tocfalseGenerate table of contents

Programmatic Usage (Node.js)

For integration into agent pipelines:

javascript
const { convertMarkdown } = require('skills/md2pdf-export/scripts/md2pdf.js');

const result = await convertMarkdown({
  inputPath: './paper.md',
  outputPath: './paper.pdf',
  type: 'pdf',               // 'pdf' | 'png' | 'jpeg'
  puppeteerConfig: {
    format: 'A4',
    printBackground: true,
    margin: { top: '20mm', bottom: '20mm', left: '15mm', right: '15mm' },
  },
  theme: 'github',
  chromePath: null,           // auto-detect
  waitTimeout: 1000,
  toc: true,
});

console.log(`Exported to: ${result.outputPath}`);

Troubleshooting

SymptomCauseFix
"Chromium revision is not downloaded"Puppeteer can't find ChromeRun npx puppeteer browsers install chrome or set PUPPETEER_EXECUTABLE_PATH
Blank PDFPage not fully rendered before exportIncrease --wait timeout, or check for async content
Missing fonts (CJK, etc.)System fonts not installedInstall fonts-noto-cjk (Ubuntu) or noto-fonts-cjk (Arch)
"No usable sandbox" on LinuxChrome sandboxing in DockerAdd --no-sandbox arg (already handled by the script in Docker detection)
Math not renderingKaTeX CSS not loadedEnsure markdown-it-texmath + KaTeX are in dependencies
Mermaid diagrams missingClient-side JS not executedUse --wait 2000 to give Mermaid time to render

Advanced: Batch Conversion

For converting an entire directory of Markdown files:

bash
# Convert all .md files in a directory to PDF
for f in docs/*.md; do
  node skills/md2pdf-export/scripts/md2pdf.js "$f" -o "output/$(basename "${f%.md}.pdf")"
done

Reference Files

  • references/puppeteer-config.md — Full Puppeteer page.pdf() and page.screenshot() API options
  • references/themes.md — Available CSS themes and how to create custom ones

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Md2pdf Export AI skill do?

Convert Markdown files to PDF, PNG, or JPEG using headless Chrome (Puppeteer), following the same methodology as VS Code's Markdown Preview Enhanced extension. Use this skill whenever the user asks to: export/convert/render markdown to PDF or image, generate a printable document from .md files, create publication-ready PDFs from markdown, set up a markdown-to-PDF pipeline, or install/configure the Node.js + Puppeteer + Chrome environment needed for headless rendering. Also trigger when the user mentions "md2pdf", "markdown export", "puppeteer PDF", "headless chrome PDF", "crossnote", "mume"...

Why use Md2pdf Export on TypingMind?

Because you install it once and use it with any model. Md2pdf Export is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Md2pdf Export in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/wentorai/Research-Claw/tree/main/skills/md2pdf-export. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Md2pdf Export?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Md2pdf Export?

As many as you like. As long as a model supports skills, you can use Md2pdf Export with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Md2pdf Export AI skill free?

It is published on GitHub by wentorai. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇