home / skills / daymade / claude-code-skills / pdf-creator

pdf-creator skill

/pdf-creator

This skill creates high quality PDFs from markdown with Chinese font support using WeasyPrint, ideal for formal documents and reports.

npx playbooks add skill daymade/claude-code-skills --skill pdf-creator

Review the files below or copy the command above to add this skill to your agents.

Files (4)
SKILL.md
2.0 KB
---
name: pdf-creator
description: Create PDF documents from markdown with proper Chinese font support using weasyprint. This skill should be used when converting markdown to PDF, generating formal documents (legal, trademark filings, reports), or when Chinese typography is required. Triggers include "convert to PDF", "generate PDF", "markdown to PDF", or any request for creating printable documents.
---

# PDF Creator

Create professional PDF documents from markdown with proper Chinese font support.

## Quick Start

Convert a single markdown file:

```bash
uv run --with weasyprint --with markdown scripts/md_to_pdf.py input.md output.pdf
```

Batch convert multiple files:

```bash
uv run --with weasyprint --with markdown scripts/batch_convert.py *.md --output-dir ./pdfs
```

## macOS Environment Setup

If encountering library errors, set these environment variables first:

```bash
export DYLD_LIBRARY_PATH="/opt/homebrew/lib:$DYLD_LIBRARY_PATH"
export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH"
```

## Font Configuration

The scripts use these Chinese fonts (with fallbacks):

| Font Type | Primary | Fallbacks |
|-----------|---------|-----------|
| Body text | Songti SC | SimSun, STSong, Noto Serif CJK SC |
| Headings | Heiti SC | SimHei, STHeiti, Noto Sans CJK SC |

## Output Specifications

- **Page size**: A4
- **Margins**: 2.5cm top/bottom, 2cm left/right
- **Body font**: 12pt, 1.8 line height
- **Max file size**: Designed to stay under 2MB for form submissions

## Common Use Cases

1. **Legal documents**: Trademark filings, contracts, evidence lists
2. **Reports**: Business reports, technical documentation
3. **Formal letters**: Official correspondence requiring print format

## Troubleshooting

**Problem**: Chinese characters display as boxes
**Solution**: Ensure Songti SC or other Chinese fonts are installed on the system

**Problem**: `weasyprint` import error
**Solution**: Run with `uv run --with weasyprint --with markdown` to ensure dependencies

Overview

This skill converts Markdown into production-ready PDF files using WeasyPrint with robust Chinese font support. It targets formal, printable documents such as legal filings, reports, and official letters, producing A4 output tuned for print quality and size limits. The workflow is optimized for batch conversion and environments that require specific library or font configuration.

How this skill works

The skill renders Markdown to HTML, applies a CSS layout configured for A4 pages, margins, fonts, and line-height, then uses WeasyPrint to produce the final PDF. It detects and applies Chinese font fallbacks (Songti/Heiti families and Noto CJK) so characters render correctly across platforms. Environment variables and dependency flags are supported to resolve native library issues on systems like macOS.

When to use it

  • Converting Markdown documents into high-quality printable PDFs
  • Generating formal documents: contracts, trademark filings, evidence lists
  • Creating business or technical reports with Chinese typography
  • Batch conversion of many Markdown files into a PDF archive
  • When output must be A4 with tight file-size constraints (e.g., <2MB)

Best practices

  • Install recommended Chinese fonts on the system (Songti SC, Heiti SC, Noto Serif/Sans CJK) to avoid glyph fallbacks
  • Use the provided CSS-friendly Markdown structure for predictable headings and spacing
  • Run with dependency flags to include weasyprint and markdown bindings in the execution environment
  • Keep images optimized and sized to reduce final PDF file size
  • Test on the target printing environment to verify pagination and line breaks

Example use cases

  • Prepare a trademark application packet from Markdown notes and generate a print-ready PDF
  • Batch convert a folder of technical reports into A4 PDFs for distribution
  • Produce an official letter with Chinese and English content using proper fonts and layout
  • Convert a Markdown evidence list into a compact PDF under submission size limits
  • Generate formatted meeting minutes with headings, tables, and consistent typography

FAQ

Why do Chinese characters appear as boxes?

Install the recommended Chinese fonts (Songti SC, SimSun, Noto CJK) on your system so WeasyPrint can map glyphs. Font fallback is configured but requires available fonts.

How do I fix weasyprint import errors?

Run the conversion with the environment flags that include weasyprint and markdown dependencies, and set platform library paths on macOS (DYLD_LIBRARY_PATH and PKG_CONFIG_PATH) if native libs are missing.