当前位置: 首页 > Skill >

Markdown to PDF Converter (v2.0)

Markdown to PDF Converter (v2.0)

Markdown to PDF Converter (v2.0)

离线Markdown转PDF转换器,基于Pandoc与WeasyPrint,支持完整Unicode及本地表情缓存,可将Markdown转为专业级PDF...

2.0.0 2026.11.23 250
获取Skill文件查看使用说明
作 者:陈辰 许可证: 更新时间:2026.11.23
本文目录展开

Markdown to PDF Converter (Complete Version)

Overview

Convert Markdown documents to professional PDFs with FULL Unicode support, Chinese fonts, and colorful emojis (3660 emojis including all variants). Uses Pandoc + WeasyPrint with a local Twemoji cache to work offline after first run.

Quick Start

Convert a Markdown file to PDF:

bash scripts/md2pdf-local.sh input.md output.pdf

First run only: Downloads ~150MB emoji resources (Twemoji 14.0.0) from GitHub. Subsequent runs work offline.

Example:

bash scripts/md2pdf-local.sh report.md report.pdf

Features

  • ✅ Full Unicode support (Chinese, Japanese, Korean)
  • ✅ Complete emoji support (Twemoji 14.0.0, 3660 colorful PNGs)
  • ✅ All emoji variants (skin tones, hair styles, regional flags, etc.)
  • ✅ Offline operation after initial setup
  • ✅ Professional PDF layout with page numbers
  • ✅ Code highlighting, tables, blockquotes
  • ✅ Accurate emoji mapping via Python pre-generated lookup table

Technical Details

Dependencies

  • Pandoc - Universal document converter
  • WeasyPrint - CSS-to-PDF renderer
  • Python 3 - For emoji mapping generation
  • wget - For emoji download (first run only)

How It Works

  1. First run: Downloads Twemoji 14.0.0 to ~/.cache/md2pdf/emojis/
  2. Python script: Generates emoji → filename mapping table (emoji_mapping.json)
  3. Pandoc: Converts Markdown to HTML with a Lua filter that replaces emoji characters with local image references
  4. WeasyPrint: Renders HTML to PDF using:
    • AR PL UMing CN for Chinese characters
    • Local emoji images (PNG, 72x72px, colorful)
    • Professional CSS styling

Emoji Cache Location

~/.cache/md2pdf/
├── emojis/                    # 3660 colorful PNG files
│   ├── 0023-fe0f-20e3.png
│   ├── 1f600.png
│   └── ...
└── emoji_mapping.json         # Emoji to filename mapping
    {
      "🙀": "1f600.png",
      "⌛": "0023-fe0f-20e3.png",
      ...
    }

Emoji Mapping

The Python script generate_emoji_mapping.py scans all Twemoji files and creates a precise mapping from emoji characters to PNG filenames. This ensures accurate emoji replacement even for complex variants like skin tones and regional indicators.

Fonts

Primary Chinese font: AR PL UMing CN

Fallback: Noto Sans SC, Noto Sans CJK SC, Microsoft YaHei

Monospace: Menlo, Monaco

Version History

v2.0 (Current)

  • ✅ Switched to Twemoji 14.0.0 (complete version)
  • ✅ 3660 colorful emojis (including all variants)
  • ✅ Python pre-generated mapping for accurate emoji replacement
  • ✅ Fixed black-and-white emoji display issue
  • ✅ Proper support for emoji variants (skin tones, hair styles, etc.)

v1.0 (Previous)

  • Used emoji-datasource-google (~2000-3000 emojis)
  • Simple hex-based filename matching (inaccurate for variants)
  • Some emojis displayed as Unicode characters (black-and-white)

Troubleshooting

Font Issues

If Chinese characters display incorrectly, ensure AR PL UMing CN is installed:

# Ubuntu/Debian
sudo apt-get install fonts-arphic-uming

# Check if installed
fc-list | grep "AR PL UMing"

Emoji Not Showing

  1. Check if emoji cache exists: ls ~/.cache/md2pdf/emojis/
  2. Check if mapping exists: ls ~/.cache/md2pdf/emoji_mapping.json
  3. If missing, delete cache and re-run: rm -rf ~/.cache/md2pdf
  4. Verify emoji file exists: ls ~/.cache/md2pdf/emojis/1f600.png

Emoji Displaying as Black-and-White

This issue has been FIXED in v2.0. If you still see black-and-white emojis:

  1. Verify you're using the v2.0 script:

    grep "TWEMOJI_VERSION" scripts/md2pdf-local.sh
    # Should show: TWEMOJI_VERSION="14.0.0"
    
  2. Clear cache and regenerate:

    rm -rf ~/.cache/md2pdf
    bash scripts/md2pdf-local.sh test.md test.pdf
    

WeasyPrint Errors

Install missing dependencies:

# Ubuntu/Debian
sudo apt-get install python3-weasyprint

# Or via pip
pip3 install weasyprint

Python Script Errors

If generate_emoji_mapping.py fails:

# Check Python version
python3 --version
# Should be Python 3.6+

# Check emoji cache
ls ~/.cache/md2pdf/emojis

Resources

scripts/

md2pdf-local.sh - Main conversion script with automatic emoji caching and mapping

generate_emoji_mapping.py - Python script to generate emoji lookup table

Usage: Direct execution from any location (uses absolute paths):

bash /path/to/skills/md2pdf-converter/scripts/md2pdf-local.sh input.md output.pdf

Key Features:

  • Automatic Twemoji download and caching
  • Python pre-generated emoji mapping (accurate)
  • Lua filter for emoji replacement
  • CSS styling for professional output
  • Temporary file cleanup (automatic)

Comparison: v1.0 vs v2.0

Feature v1.0 (Old) v2.0 (New)
Emoji Source emoji-datasource-google Twemoji 14.0.0
Emoji Count ~2000-3000 3660
Color Display ❌ Unstable ✅ Stable
Variants Support ❌ Incomplete ✅ Complete
Mapping Accuracy ⚠️ Low ✅ High
Offline Support ✅ After first run ✅ After first run
First Run Size ~68MB ~150MB

Performance

  • First run: ~150MB download, 10-30 seconds (depending on network)
  • Subsequent runs: Offline, seconds-level conversion
  • Memory usage: ~150MB for emoji cache
  • PDF generation: 1-5 seconds per page

Limitations

  • Missing emojis (newer than Twemoji 14.0.0) will display as Unicode characters
  • First run requires internet connection (for Twemoji download)
  • Emoji cache size: ~150MB (3660 PNG files at 72x72px)

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,016
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,003
Apache开启.htaccess及使用方法详解

本文介绍如何在本地Apache环境中启用.htaccess文件,主要涉及修改httpd.conf中的AllowOverride参数。同时详细解析.htaccess的多种实用功能,包括自定义错误页面、目录密码保护、IP访问限制、URL自动转向、默认首页设置以及防止图片盗链等配置方法,并分析了使用.htaccess对服务器性能和安全性的潜在影响。

2026.05.09 1,001
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,001
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,000
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,000
Skill 文件
  • SKILL.md
    • Markdown to PDF Converter (Complete Version)
    • Overview
    • Quick Start
    • Features
    • Technical Details
      • Dependencies
      • How It Works
      • Emoji Cache Location
      • Emoji Mapping
      • Fonts
    • Version History
      • v2.0 (Current)
      • v1.0 (Previous)
    • Troubleshooting
      • Font Issues
      • Emoji Not Showing
      • Emoji Displaying as Black-and-White
      • WeasyPrint Errors
      • Python Script Errors
    • Resources
      • scripts/
    • Comparison: v1.0 vs v2.0
    • Performance
    • Limitations
  • 项目或源文件

相关 Skill

更多
Bookify - Convert Markdown to PDF or EPUB Bookify - Convert Markdown to PDF or EPUB 使用 md-bookify 将 Markdown 文件转换为带样式的 PDF 或 EPUB 电子书。适用于需要从 Markdown 内容生成 PDF 或 EPUB 的场景。
Markdown to PDF Markdown to PDF 将 Markdown文件转换为美观的 PDF,支持自定义样式、代码高亮和多种输出选项,适用于需要将 Markdown 转换为 PDF 的场景。
PDF Converter PDF Converter PDF转换工具包,采用AI布局分析和OCR技术,支持将PDF转换为Word、Markdown、JSON、PPT、CSV、HTML和XML,实现无缝的LLM数据处理。
file-to-pdf file-to-pdf 将各类文件批量转换为 PDF 格式。支持 Office 文档(Word/Excel/PowerPoint)、图片(JPG/PNG/BMP/GIF/WebP/TIFF)、HTML 网页、Markdown 文件和纯文本文件。当用户要求将文件转为 PDF、导出 PDF、把图片合并成 PDF、或批量转换文档格式时触发此技能。This skill should be used when users ask to convert files to PDF, export to PDF, merge images into a PDF, or batch convert documents to PDF format.
PDF 结构化抽取·带证据溯源 PDF 结构化抽取·带证据溯源 从图片型、扫描型、混合型或原生文本 PDF 中提取可审计的结构化字段,并把字段证据确定性映射回原始 PDF 页码、页标签、bbox、原文和证据截图。用于合同、报告、手册、表单、研究资料等需要自定义 JSON Schema 和逐字段溯源的 PDF 抽取任务;默认以 MinerU 为主解析器、Docling 为必装交叉复核器,PaddleOCR 为可选补充解析器。