pdf-generation
Skill1 starsChanged 5 months agoMITView on GitHub
Generates PDFs using Typst templates, handles print layouts, and processes images with Sharp.
Files
PDF Generation Skill
Professional PDF generation patterns using Typst, Puppeteer, and Sharp.
When This Applies
- Creating or modifying PDF generation code
- Working with Typst templates
- Debugging PDF output issues (text overlap, image sizing, page breaks)
- Implementing print-ready HTML
- Processing images for print (Sharp, EXIF, DPI)
Quick Reference
See adjacent files:
reference.md- Typst syntax and patternstroubleshooting.md- Common issues and solutions
Core Patterns
1. Always Escape User Content
function escapeTypstString(str: string): string {
if (!str) return "";
return str
.replace(/\\/g, "\\\\") // Backslash first
.replace(/"/g, '\\"')
.replace(/\[/g, "\\[")
.replace(/\]/g, "\\]")
.replace(/#/g, "\\#")
.replace(/\$/g, "\\$")
.replace(/_/g, "\\_")
.replace(/\*/g, "\\*")
.replace(/@/g, "\\@")
.replace(/</g, "\\<")
.replace(/>/g, "\\>")
.replace(/`/g, "\\`")
.replace(/\n/g, " ") // Newlines break template
.replace(/\r/g, "")
.replace(/\t/g, " ");
}2. Constrain Image Dimensions
// Always specify both width AND height with fit: "contain"
#image("photo.jpg", width: 100%, height: 6in, fit: "contain")3. Add Page Break Hints
// Before potentially tall content
#pagebreak(weak: true)4. Use CSS Grid for Complex Layouts (HTML)
.page-one {
display: grid;
grid-template-columns: 1fr auto;
grid-template-rows: auto 1fr auto;
}5. Five-Tier PDF Fallback Chain
1. Typst WASM (primary - <100ms, professional)
2. Cloud PDF API (optional production fallback)
3. Puppeteer (dev only - system Chrome)
4. Print HTML (universal - works everywhere)
5. Emergency JSON (last resort - manual)Key Libraries
| Library | Purpose | Notes |
@myriaddreamin/typst.ts | Typst WASM compiler | Singleton pattern, dynamic imports |
sharp | Image processing | EXIF rotation, resize, color profiles |
puppeteer-core | PDF rendering from HTML | Dev only, needs Chrome |
Browser Tool Selection
| Use Case | Tool |
| PDF generation from HTML | Puppeteer (specialized PDF APIs) |
| Testing/verifying PDF output | agent-browser |
| General browser automation | agent-browser |
Note: Puppeteer is still preferred for PDF generation because of its specialized page.pdf() API with precise control over margins, headers, footers, and print media. Use agent-browser for testing and verification.
Photo Processing Pipeline
// 1. Validate: Check data URI format
// 2. Resize: Max 2400px (8" @ 300dpi)
// 3. Fix EXIF: Auto-rotate based on orientation
// 4. Convert: sRGB color profile for print
// 5. Compress: JPEG 90% quality
// 6. Embed: Base64 data URIDebugging Tips
- Enable verbose logging:
generateFieldReportPdf(report, photos, { verbose: true }) - Check Typst diagnostics:
generateFieldReportPdf(report, photos, { includeDiagnostics: true }) - Common failure patterns:
- Empty PDF buffer → Typst syntax error
- Text overlap → Unescaped special characters
- Image cutoff → Missing height constraint
- Sidebar drift → Absolute positioning instead of Grid
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- glebis/claude-skills★ 404same name
- JAVICHILEON/claude---Skills★ 0same name
- KISHOR403/claude-skills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository54 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/deep-recon/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- adversarial-researchSkill
- algorithmic-artSkill
- api-integrationSkill
- breakdownSkill
- c4-architectSkill
- canvas-designSkill
- coding-agentsSkill
- compound-engineeringSkill
- context-budgetSkill
- counterfactualSkill
- critiqueSkill
- d3js-visualizationSkill
- data-analyst-agentSkill
- database-migrationsSkill
- deep-reconSkill
- design-tasteSkill
- doc-coauthoringSkill
- e2b-sandboxSkill
- ecosystem-auditSkill
- excalidraw-diagramSkill
- executing-plansSkill
- frontend-designSkill
- fullstack-agentSkill
- grillSkill
- kickoffSkill
- mcp-builderSkill
- model-migrationSkill
- naming-the-machineSkill
- full-output-enforcementSkill
- package-researchSkill
- pp2pSkill
- pp3pSkill
- prompt-engineerSkill
- prompt-groundingSkill
- redesignSkill
- requesting-code-reviewSkill
- reverse-engineer-to-learnSkill
- review-changesSkill
- scratchpadSkill
- shipSkill
- slack-gif-creatorSkill
- sprint-architectSkill
- techdebtSkill
- test-and-fixSkill
- threat-modelSkill
- verification-before-completionSkill
- visual-verdictSkill
- webapp-testingSkill
- web-asset-generatorSkill
- whatdidimissSkill
- writing-plansSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

