Markdown to PDF Converter (v2.0)
by @tianxingleo
Offline Markdown to PDF converter with full Unicode support using Pandoc + WeasyPrint + local emoji cache. Converts Markdown documents to professional PDFs w...
clawhub install md2pdf-converterπ About This Skill
name: md2pdf-converter description: Offline Markdown to PDF converter with FULL Unicode support using Pandoc + WeasyPrint + local Twemoji cache (3660 colorful emojis). Converts Markdown documents to professional PDFs with Chinese fonts and colorful emojis (complete version with all variants). Use when user needs to convert Markdown reports or documents to PDF, generate PDFs with emoji support, create PDFs with proper Chinese character rendering, or work offline after initial setup.
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
Technical Details
Dependencies
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)
v1.0 (Previous)
Troubleshooting
Font Issues
If Chinese characters display incorrectly, ensure AR PL UMing CN is installed:
# Ubuntu/Debian
sudo apt-get install fonts-arphic-umingCheck 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-weasyprintOr 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:
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
Limitations
π‘ Examples
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
π Tips & Best Practices
Font Issues
If Chinese characters display incorrectly, ensure AR PL UMing CN is installed:
# Ubuntu/Debian
sudo apt-get install fonts-arphic-umingCheck 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-weasyprintOr 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