$npx -y skills add lovstudio/any2pdf --skill lovstudio-any2pdfConvert Markdown documents to professionally typeset PDF files with reportlab. Handles CJK/Latin mixed text, fenced code blocks, tables, blockquotes, Obsidian callouts, inline images, emoji fallback, LaTeX-style formulas, cover pages, clickable TOC, PDF bookmarks, watermarks, and
| 1 | # any2pdf — Markdown to Professional PDF |
| 2 | |
| 3 | This skill converts any Markdown file into a publication-quality PDF using Python's |
| 4 | reportlab library. It was developed through extensive iteration on real Chinese |
| 5 | technical reports and solves several hard problems that naive MD→PDF converters |
| 6 | get wrong. |
| 7 | |
| 8 | ## When to Use |
| 9 | |
| 10 | - User wants to convert `.md` → `.pdf` |
| 11 | - User has a markdown report/document and wants professional typesetting |
| 12 | - Document contains CJK characters (Chinese/Japanese/Korean) mixed with Latin text |
| 13 | - Document has fenced code blocks, markdown tables, or nested lists |
| 14 | - Document has local/remote images, Obsidian callouts, emoji, or math formulas |
| 15 | - User wants a cover page, table of contents, or watermark in their PDF |
| 16 | |
| 17 | ## Quick Start |
| 18 | |
| 19 | ```bash |
| 20 | python md2pdf/scripts/md2pdf.py \ |
| 21 | --input report.md \ |
| 22 | --output report.pdf \ |
| 23 | --title "My Report" \ |
| 24 | --author "Author Name" \ |
| 25 | --theme warm-academic |
| 26 | ``` |
| 27 | |
| 28 | All parameters except `--input` are optional — sensible defaults are applied. |
| 29 | |
| 30 | ## Pre-Conversion Options (MANDATORY) |
| 31 | |
| 32 | **IMPORTANT: You MUST use the `AskUserQuestion` tool to ask these questions BEFORE |
| 33 | running the conversion. Do NOT list options as plain text — use the tool so the user |
| 34 | gets a proper interactive prompt. Ask all options in a SINGLE `AskUserQuestion` call.** |
| 35 | |
| 36 | Use `AskUserQuestion` with the following template. The tone should be friendly and |
| 37 | concise — like a design assistant, not a config form: |
| 38 | |
| 39 | ``` |
| 40 | 开始转 PDF!先帮你确认几个选项 👇 |
| 41 | |
| 42 | ━━━ 📐 设计风格 ━━━ |
| 43 | a) 暖学术 — 陶土色调,温润典雅,适合人文/社科报告 |
| 44 | b) 经典论文 — 棕色调,灵感源自 LaTeX classicthesis,适合学术论文 |
| 45 | c) Tufte — 极简留白,深红点缀,适合数据叙事/技术写作 |
| 46 | d) 期刊蓝 — 藏蓝严谨,灵感源自 IEEE,适合正式发表风格 |
| 47 | e) 精装书 — 咖啡色调,书卷气,适合长篇专著/技术书 |
| 48 | f) 中国红 — 朱红配暖纸,适合中文正式报告/白皮书 |
| 49 | g) 水墨 — 纯灰黑,素雅克制,适合文学/设计类内容 |
| 50 | h) GitHub — 蓝白极简,程序员熟悉的风格 |
| 51 | i) Nord 冰霜 — 蓝灰北欧风,清爽现代 |
| 52 | j) 海洋 — 青绿色调,清新自然 |
| 53 | |
| 54 | ━━━ 🖼 扉页图片(封面之后的全页插图) ━━━ |
| 55 | 1) 跳过 |
| 56 | 2) 我提供本地图片路径 |
| 57 | 3) AI 根据内容自动生成一张 |
| 58 | |
| 59 | ━━━ 💧 水印 ━━━ |
| 60 | 1) 不加 |
| 61 | 2) 自定义文字(如 "DRAFT"、"内部资料") |
| 62 | |
| 63 | ━━━ 📇 封底物料(名片/二维码/品牌) ━━━ |
| 64 | 1) 跳过 |
| 65 | 2) 我提供图片 |
| 66 | 3) 纯文字信息 |
| 67 | |
| 68 | 示例回复:"a, 扉页跳过, 水印:仅供学习参考, 封底图片:/path/qr.png" |
| 69 | 直接说人话就行,不用记编号 😄 |
| 70 | ``` |
| 71 | |
| 72 | ### Mapping User Choices to CLI Args |
| 73 | |
| 74 | | Choice | CLI arg | |
| 75 | |--------|---------| |
| 76 | | Design style a-j | `--theme` with value from table below | |
| 77 | | Frontispiece local | `--frontispiece <path>` | |
| 78 | | Frontispiece AI | Generate image first, then `--frontispiece /tmp/frontispiece.png` | |
| 79 | | Watermark text | `--watermark "文字"` | |
| 80 | | Back cover image | `--banner <path>` | |
| 81 | | Back cover text | `--disclaimer "声明"` and/or `--copyright "© 信息"` | |
| 82 | |
| 83 | ### Theme Name Mapping |
| 84 | |
| 85 | | Choice | `--theme` value | Inspiration | |
| 86 | |--------|----------------|-------------| |
| 87 | | a) 暖学术 | `warm-academic` | Lovstudio design system | |
| 88 | | b) 经典论文 | `classic-thesis` | LaTeX classicthesis | |
| 89 | | c) Tufte | `tufte` | Edward Tufte's books | |
| 90 | | d) 期刊蓝 | `ieee-journal` | IEEE journal format | |
| 91 | | e) 精装书 | `elegant-book` | LaTeX ElegantBook | |
| 92 | | f) 中国红 | `chinese-red` | Chinese formal documents | |
| 93 | | g) 水墨 | `ink-wash` | 水墨画 / ink wash painting | |
| 94 | | h) GitHub | `github-light` | GitHub Markdown style | |
| 95 | | i) Nord | `nord-frost` | Nord color scheme | |
| 96 | | j) 海洋 | `ocean-breeze` | — | |
| 97 | |
| 98 | ### Handling AI-Generated Frontispiece |
| 99 | |
| 100 | If user chose AI generation: read the document title + first paragraphs, use an |
| 101 | image generation tool to create a themed illustration matching the chosen design |
| 102 | style, show for approval, then pass via `--frontispiece /path/to/image.png` |
| 103 | |
| 104 | ## Architecture |
| 105 | |
| 106 | ``` |
| 107 | Markdown → Preprocess (split merged headings) → Parse (code-fence-aware) → Story (reportlab flowables) → PDF build |
| 108 | ``` |
| 109 | |
| 110 | Key components: |
| 111 | 1. **Font system**: Palatino (Latin body), Songti SC (CJK body), Menlo (code) on macOS; auto-fallback on Linux |
| 112 | 2. **CJK wrap |