Markdown to PDF Conversion: Format Markdown into Local A4 PDF

Introduction

When writing proposals, meeting minutes, or archiving materials, Markdown facilitates version control, but external delivery often requires PDFs. Manually copying to Word and exporting, or temporarily assembling a Pandoc/LaTeX pipeline, can easily lead to pitfalls regarding styles and Chinese file paths. Below is an introduction to the community Skill “Markdown to PDF” on SkillHub (coordinates @user_09b3713d/md2pdf): once installed into the Agent’s skills directory, it can convert .md files into local PDFs with layout formatting following a fixed process.

What is this

“Markdown to PDF” is a skill from the SkillHub community source, categorized under office-efficiency, published by user_09b3713d. The platform description is just one sentence: Convert Markdown format to PDF format. The SKILL.md within the actual installed package positions it as MD2PDF—a general document converter: converting any Markdown to A4 print-ready PDFs. It typeset HTML using python-markdown, performs headless printing via Chrome/Edge/Chromium, and validates page counts using pypdf. The tags indicate requires_api_key=false, meaning no additional API Key is needed for invocation.

The platform page (as of capture) shows version v1.0.0, rating 100000, downloads 2739, and installs 31.

Core Features

The following capabilities are derived from the SKILL.md and scripts/md2pdf.py within the installed package and can be verified against local files:

  1. Three style templates: formal (formal black and white), business (business blue), and academic (academic serif), corresponding to styles/formal.css, styles/business.css, and styles/academic.css.
  2. Markdown structure: Supports tables, fenced code blocks, and blockquotes (markdown extensions tables, fenced_code).
  3. Conversion pipeline: md → typeset HTML → browser headless --print-to-pdf → PDF; removes PDF headers and footers by default; includes retry logic for older Chrome versions in case of exceptions.
  4. Environment self-healing: Python 3.8+; the script attempts automatic pip install if markdown or pypdf is missing (requires internet connection on first run); automatic browser detection, or specify path via --browser.
  5. Agent-side conventions: When invoking the skill, prompt the user to select a style template first (can be skipped if the user has explicitly specified one); present the generated PDF to the user.

Installation and Activation

First, perform an environment check, then install the skill into the skills directory recognized by the current Agent (SkillHub documentation emphasizes using --dir, otherwise the default ./skills/ might not be loaded).

1. Check SkillHub CLI

command -v skillhub && skillhub --version

If not installed, follow the official installation instructions to execute the full installation (the example below is the recommended method):

curl -fsSL https://skillhub-1388575217.cos.ap-guangzhou.myqcloud.com/install/install.sh | bash

2. Install this Skill

Search to view coordinates and installation methods; the installation command is:

skillhub install md2pdf --namespace user_09b3713d --dir <your Agent skills directory>

Common directories (from SkillHub installation documentation):

  • Cursor: ~/.cursor/skills/
  • Claude Code: ~/.claude/skills/
  • Codex: ~/.codex/skills/ or .agents/skills/ under the project

Upon successful installation, the package will be placed in a subdirectory similar to @user_09b3713d/md2pdf/, containing SKILL.md and scripts/md2pdf.py. After modifying skills, restart or refresh the Agent according to your client’s requirements to activate the skill.

Typical Usage

In Conversation: When a user requests “export this md to PDF,” the Agent follows SKILL.md to first ask the user to select formal / business / academic via Q&A, then executes the script.

Command Line One-click Conversion (replace paths with local installation directory):

python <skill_dir>/scripts/md2pdf.py "<input.md>" "<output.pdf>" --style <formal|business|academic>

Notes:

  • If --style is omitted, the default is formal.
  • If the output PDF path is omitted, the PDF is written to the same directory as the source .md, with the filename original_name_style.pdf.
  • The script prints the intermediate .print.html path for easy preview or troubleshooting.

For troubleshooting or when HTML is needed only, you can follow SKILL.md to perform steps manually: first md→HTML (template concatenation must use __BODY__/__CSS__ placeholders with replace, avoid % formatting or f-strings to prevent conflicts with % and {} in CSS), then manually invoke the browser for headless printing.

Applicable Scenarios and Notes

Suitable for: Scenarios where reports, minutes, proposals, or thesis-style Markdown need to be saved as local PDFs with fixed A4 layouts and three preset styles; requires Chrome/Edge/Chromium to be installed locally or willingness to specify via --browser.

Notes:

  • Relies on a headless browser; errors will occur if the browser cannot be detected, requiring local installation or explicit specification.
  • The first run may trigger pip to install dependencies, requiring network access and a writable Python environment.
  • SKILL.md mentions handling methods for special environments like WorkBuddy and PowerShell output; if other Agents do not return stdout, output can be redirected to a file and then read.
  • There are other skills with the same or similar names (md2pdf) on SkillHub (different namespace); when installing, ensure to use install md2pdf --namespace user_09b3713d corresponding to @user_09b3713d/md2pdf.

Conclusion

“Markdown to PDF” consolidates “Select Template → md to HTML → Headless Print PDF → Validate” into a reproducible pipeline, suitable for handling daily Markdown deliverables within an Agent. For installation and priority source instructions, see SkillHub Installation Documentation; for the skill page, see SkillHub - Markdown to PDF, and the clue address is https://api.skillhub.cn/user_09b3713d/md2pdf.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye