PDF Generator
Generate professional PDFs from Markdown, HTML, data, or code. Reports, invoices, contracts, and documents with best practices.
What this skill does
## 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
```python
# CORRECT: semantic structure
html = """
<article>
<header><h1>Report Title</h1></header>
<section>
<h2>Summary</h2>
<p>Content...</p>
</section>
</article>
"""
# WRONG: style-first approach
html = "<div style='font-size:24px'>Report Title</div>"
```
### 3. Handle Page Breaks Explicitly
```css
/* 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
```python
# Example pattern for weasyprint
html = """
<html>
<head>
<title>Document Title</title>
<meta name="author" content="Author Name">
</head>
...
"""
```
### 5. Use Print-Optimized CSS
```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:
1. Check file size (0 bytes = failed)
2. Open and verify page count
3. 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`
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.