Md2pdf Exportのロゴ

Md2pdf Export

コミュニティ
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.

概要

公開者wentorai
リポジトリResearch-Claw
スキル名md2pdf-export
スター
859
フォーク
117
同梱ファイル
6
リンク
  • Markdown形式の指示

    モデルが必要に応じて読み込むSKILL.mdファイルです。関連するリクエストがあったときだけトークンを消費します。

  • どのLLMでも利用可能

    AIスキルはプロバイダー固有のコードではなく、通常のMarkdownなので、GPT、Claude、Gemini、Grok、ローカルモデルで利用できます。

  • 6個の同梱ファイル

    モデルが作業中に読み取れるスクリプト、テンプレート、参考資料です。ファイルは読み取り専用で、実行されることはありません。

  • オープンソース

    wentoraiがGitHubで公開しています。インストールする前にソースを確認してください。

インストール

AIスキル「Md2pdf Export」をTypingMindにインストールすれば、どのLLMでも利用できます。SKILL.mdを読み取れる別のAIエージェントに追加することもできます。

1

TypingMindにインストール

TypingMindはGitHubフォルダから直接スキルをインストールします。SKILL.mdを読み取り、リソースファイルをまとめてローカルに保存します。

  1. アプリを開き、「プラグイン」→「スキル」に移動します。
  2. 「GitHubからインストール」を選択します。
  3. 以下のスキルフォルダのURLを貼り付けて確定します。
    https://github.com/wentorai/Research-Claw/tree/main/skills/md2pdf-export
  4. スキルを利用したいチャットごとに、そのスキルを有効にしてください。
「プラグイン」→「スキル」→「スキルを追加」→「GitHubのURLから」を選択し、フォルダのURLを貼り付けて「続行」を押します。
2

別のAIエージェントにインストール

Agent Skills形式を読み取れるAIエージェントなら、このスキルを利用できます。フォルダをそのAIエージェントのスキルディレクトリにコピーしてください。

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
コピー後、新しいスキルを読み込むためにClaude Codeを再起動してください。

TypingMindで使用

TypingMindのチャットでMd2pdf Exportを有効にするだけで、あとはモデルが対応します。名前と説明がシステムプロンプトに含まれ、関連するリクエストがあると、モデルが指示の全文を自動で読み込みます。手動で呼び出す必要はなく、実際に使用されるまでトークンを消費しません。

関連するリクエストがあるとすぐに、モデルが自動的にMd2pdf Exportを読み込みます。

どのAIモデルでも利用可能

AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、Md2pdf Exportは作成時に想定されたモデルに縛られません。TypingMindに一度インストールすれば、ご自身のAPIキーを使って、GPT-5、Claude、Gemini、Grok、DeepSeek、Mistral、Llama、またはご自身で実行するローカルモデルで利用できます。

  • 必要なときだけ読み込み

    システムプロンプトには名前と説明だけが含まれます。関連するリクエストが初めてあったときに指示を取得するため、スキルを使わない間は指示の読み込みにトークンを消費しません。

  • チャットの途中でモデルを切り替え

    スキルはコードではなく指示なので、モデルを切り替えてもそのまま使えます。次のモデルも同じSKILL.mdを読み込みます。

スキルの指示

モデルが読み込むSKILL.mdの内容です。スキルはモデルが従う指示なので、インストールする前に確認してください。

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

同梱ファイル

スキルが読み込まれている間、モデルは必要に応じてこれらを読み取ります。読み取り可能なファイルとして提供され、実行されることはありません。

よくある質問

AIスキル「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"...

TypingMindでMd2pdf Exportを使うメリットは何ですか?

一度インストールすれば、どのモデルでも使えるからです。Md2pdf Exportはプロバイダー固有のコードではなく、通常のMarkdownで記述されているため、同じスキルをGPT-5、Claude、Gemini、Grok、ローカルモデルで利用できます。チャットの途中でモデルを切り替えても、そのまま使い続けられます。TypingMindは自分のAPIキーで動作するため、シート単位のサブスクリプションではなく、プロバイダーに直接料金を支払います。スキルとチャットは自分のストレージに保持されます。

TypingMindにMd2pdf Exportをインストールするにはどうすればよいですか?

TypingMindで「プラグイン」→「スキル」→「GitHubからインストール」を開き、https://github.com/wentorai/Research-Claw/tree/main/skills/md2pdf-exportを貼り付けてください。TypingMindがSKILL.mdを読み込み、関連ファイルをまとめて、チャットごとに有効にできるスキルとしてインストールします。

Md2pdf Exportを使えるAIモデルはどれですか?

TypingMindに接続したどのモデルでも利用できます。AIスキルはプロバイダー固有のコードではなく、通常のMarkdownで書かれた指示です。そのため、GPT、Claude、Gemini、Grok、ローカルモデルのいずれも、リクエストの内容がこのスキルの用途に合ったときに、このスキルを読み込めます。

Md2pdf Exportで使えるAIモデルの数に制限はありますか?

数に制限はありません。スキルに対応したモデルであれば、GPT、Claude、Gemini、Grok、DeepSeek、Mistral、Llamaなど、どのモデルでもMd2pdf Exportを利用できます。すべてTypingMind上で、自分のAPIキーを使って利用できます。

AIスキル「Md2pdf Export」は無料ですか?

wentoraiがGitHubで公開しています。ライセンス条件はリポジトリでご確認ください。ご利用のAIプロバイダーに支払うのは、使用したトークンの料金だけです。

AIスキルとは何ですか?

AIスキルは、特定のタスクの実行方法をAIモデルに教える、再利用可能な指示のセットです。オープンなAgent Skills形式に従い、名前と説明を含むSKILL.mdファイルに加え、モデルが必要とするスクリプト、テンプレート、参照ファイルで構成されます。モデルはリクエストがスキルに合致したときだけ指示を読み込むため、インストール済みのスキルも、使うまでは費用がかかりません。

AIスキルは、プラグインやMCPサーバーとどう違いますか?

プラグインやMCPサーバーは、モデルが呼び出せる新しいツールを提供します。ツールとは、どこかで実行され、結果を返すコードです。一方、AIスキルは、タスクへの取り組み方、従うべき手順、望ましい出力の例といった知識や進め方をモデルに伝えます。スキルは通常のMarkdownで記述されているため、サーバー、APIキー、実行環境は不要で、どのモデルでも利用できます。

すべて見る

今すぐ自分専用のAIワークスペースを作成

ニュースレターに登録すると、新機能や今後のプレゼント企画のお知らせが届きます👇