huashu-md-to-pdf

Original🇨🇳 Chinese
Translated
1 scriptsChecked / no sensitive code detected

Convert Markdown documents into professional PDF whitepapers with Apple design style. Supports full Markdown syntax (code blocks, tables, blockquotes, lists, etc.). Automatically generates cover pages, table of contents, headers and footers. Use cases: Technical documents, whitepapers, tutorials, reports and other Markdown documents that require professional typesetting.

4installs
Added on

NPX Install

npx skill4agent add alchaincyf/huashu-skills huashu-md-to-pdf

SKILL.md Content (Chinese)

View Translation Comparison →

Markdown to PDF Skill

Convert Markdown documents into professional PDF whitepapers with Apple design style.

Core Features

  1. Professional Typesetting: Book-level typesetting quality, automatically handles page breaks, widows and orphans
  2. Apple Design: SF font system, modern and minimalist style, professional color scheme
  3. Complete Table of Contents: Automatically extracts chapter structure, two-column layout, clickable navigation
  4. Full Markdown Support: Correctly renders code blocks, tables, blockquotes, lists, etc.

Usage Instructions

Basic Usage

bash
# Convert a single file
python scripts/convert.py input.md

# Specify output file name
python scripts/convert.py input.md -o "我的白皮书.pdf"

# Customize title and author
python scripts/convert.py input.md --title "技术白皮书" --author "花叔"

Markdown Document Requirements

Your Markdown document should follow this structure:
markdown
# Document Title

## 1. Chapter 1
### 1.1 Section 1
### 1.2 Section 2

## 2. Chapter 2
### 2.1 Section 1
Key Rules:
  • Main chapters:
    ## 1. Title
    (number + dot + space + title)
  • Sub-chapters:
    ### 1.1 Title
    (number.number + space + title)
  • This ensures correct table of contents extraction

Design Features

Cover Design

  • Light gray gradient background
  • Large title: 64pt, clean and modern
  • Subtitle and meta information

Table of Contents Design

  • Two-column layout, single-page display
  • Main chapters in bold, sub-chapters indented
  • Clickable to jump to corresponding chapters

Body Typesetting

  • SF font family (Apple design language)
  • Line height 1.7, comfortable reading
  • Automatic page breaks for chapters
  • Widow and orphan control

Code Blocks

  • Light gray background + thin border
  • 8px rounded corners
  • SF Mono monospaced font
  • Automatically avoids page breaks

Tables

  • Clear grid lines
  • Light gray header
  • Automatically retains header (for long tables with page breaks)

Configuration Options

To customize styles, modify the CSS variables in
scripts/convert.py
:
python
# Primary color
PRIMARY_COLOR = '#06c'      # Apple blue
TEXT_COLOR = '#1d1d1f'      # Main text black
GRAY_COLOR = '#86868b'      # Light gray

# Font sizes
COVER_TITLE_SIZE = '64pt'
H2_SIZE = '22pt'
H3_SIZE = '17pt'
BODY_SIZE = '11pt'

Frequently Asked Questions

Q: Why is the table of contents empty?

A: Ensure your Markdown uses the correct chapter format:
  • ## 1. Title
    instead of
    ## Title
  • ### 1.1 Title
    instead of
    ### Title

Q: Code blocks are not displayed correctly?

A: Ensure they are wrapped with three backticks:
markdown
```python
def hello():
    print("Hello")
```

Q: Table formatting is messed up?

A: Use standard Markdown table syntax:
markdown
| Column 1 | Column 2 |
|-----|-----|
| Value 1 | Value 2 |

Q: How to modify fonts?

A: Edit the CSS in
scripts/convert.py
and modify the
font-family
property.

Q: The generated PDF is too large?

A: Check for large images, consider compressing images or using external links.

Dependency Installation

Install Python dependencies for first-time use:
bash
pip3 install markdown2 weasyprint
If you encounter WeasyPrint installation issues (macOS):
bash
brew install pango
pip3 install weasyprint

Examples

Generate Technical Document

bash
python scripts/convert.py tech-guide.md -o "技术指南.pdf"

Generate Whitepaper

bash
python scripts/convert.py whitepaper.md --title "产品白皮书" --author "团队"

Script Description

  • scripts/convert.py
    - Main conversion script
  • scripts/styles.css
    - CSS style definitions (embedded in the script)
  • templates/cover.html
    - Cover template (embedded in the script)

Technical Implementation

This Skill uses:
  • markdown2: Markdown parsing (supports extended syntax)
  • WeasyPrint: HTML to PDF conversion (supports CSS3)
  • Apple Design System: SF fonts, professional color scheme, modern typesetting

Changelog

v1.0 (2025-12-24)

  • Initial release
  • Supports full Markdown syntax
  • Apple design style
  • Automatic table of contents generation
  • Book-level typesetting quality

Produced by Uncle Hua | AI Native Coder · Independent Developer Official Account "Uncle Hua" | 300,000+ followers | AI Tools & Efficiency Improvement Masterpieces: Kitty Fill Light (Top 1 in AppStore Paid Charts) · Mastering DeepSeek in One Book