何时使用
用户需要创建、生成或导出 PDF 文档。代理处理从多个源(Markdown、HTML、JSON、模板)生成文档、格式化、样式和批量处理。
范围
此技能
仅 提供:
- PDF 生成的代码模式和实现指南
- 工具选择、打印 CSS 和文档结构的解释
- 常见文档类型的参考示例
此技能
永远不会 :
- 直接执行代码或生成文件
- 进行网络请求
- 访问用户工作目录外的文件
所有代码示例为用户实现的参考模式。
... (以下内容为原文未提供的翻译部分,请根据实际需要补充或保持原样)
When to Use
User needs to create, generate, or export PDF documents. Agent handles document generation from multiple sources (Markdown, HTML, JSON, templates), formatting, styling, and batch processing.
Scope
This skill ONLY:
- Provides code patterns and implementation guidance for PDF generation
- Explains tool selection, CSS for print, and document structure
- Shows reference examples for common document types
This skill NEVER:
- Executes code or generates files directly
- Makes network requests
- Accesses files outside user's working directory
All code examples are reference patterns for the user to implement.
Quick Reference
| Topic | File |
|---|
| Tool selection | tools.md |
| Document types | templates.md |
| Advanced operations | advanced.md |
Core Rules
1. Choose the Right Tool
| Source | Best Tool | Why |
|---|
| Markdown | pandoc | Native support, TOC, templates |
| HTML/CSS | weasyprint | Best CSS support, no LaTeX |
| Data/JSON | reportlab | Programmatic, precise control |
| Simple text | fpdf2 | Lightweight, fast |
Default recommendation: weasyprint for most HTML-based documents.
2. Structure Before Style
# CORRECT: semantic structure
html = """
"""# WRONG: style-first approach
html = "
Report Title
"
3. Handle Page Breaks Explicitly
/ Force page break before /
.new-page { page-break-before: always; }/ Keep together /
.keep-together { page-break-inside: avoid; }
/ Headers never orphaned /
h2, h3 { page-break-after: avoid; }
4. Always Set Metadata
# Example pattern for weasyprint
html = """
Document Title
...
"""
5. Use Print-Optimized CSS
@media print {
body {
font-family: 'Georgia', serif;
font-size: 11pt;
line-height: 1.5;
}
@page {
size: A4;
margin: 2cm;
}
.no-print { display: none; }
}
6. Validate Output
After generating any PDF:
- Check file size (0 bytes = failed)
- Open and verify page count
- Verify fonts render correctly
Common Traps
| Trap | Consequence | Fix |
|---|
| Missing fonts | Fallback to defaults | Use web-safe fonts |
| Absolute image paths | Images missing | Use relative paths |
| No page size | Unpredictable layout | Set @page { size: A4; } |
| Large images | Huge files | Compress before use |
Security & Privacy
This is a reference skill. It provides patterns and guidance only.
Data that stays local:
- All PDF generation happens on user's machine
- No data sent externally
This skill does NOT:
- Execute code or make files
- Make network requests
- Access system files
Feedback
- If useful:
clawhub star pdf-generator
- Stay updated:
clawhub sync