Skip to content
Swap Meet

Free

No. 038Free

pdf-generation: patterns for page breaks, images and print

Reusable Typst and HTML patterns so tables and images stay on the page: escape user text, set both image dimensions, and fall back in order.

by Lucas Cooper-Bey

About it

pdf-generation is a set of patterns for Typst and HTML so a PDF prints cleanly. Escape user text before it enters a Typst string. Give every image a width and a height with fit contain. Put a weak page break before tall content. The fallback order is Typst WASM, an optional cloud PDF API, Puppeteer in development, print HTML, then JSON. Sharp resizes photos to a max of 2400 pixels and fixes EXIF rotation. reference.md and troubleshooting.md sit beside the skill. Limits: These are patterns, not a one-click app. Puppeteer is the dev path and needs Chrome. User content has to be escaped or Typst breaks on newlines and special characters. An image without both dimensions can run off the page. The cloud PDF API is optional. The last resort is JSON you finish by hand. Door 40 of 100 Doors.