Turn something into a small, clean PDF, such as an HTML deck or page, a Markdown file, images, or an oversized PDF, and compress it without hurting images, logos or text. Use when the user asks to export, print, save or convert to PDF, to make a PDF smaller, or mentions simple-pdf-export. To write the document itself, draft it first, then use this skill for the export.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Is that skill safe to install?
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
Are you the author of Simple Pdf Export?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/denniemok-simple-pdf-export)
---
name: simple-pdf-export
description: Turn something into a small, clean PDF, such as an HTML deck or page, a Markdown file, images, or an oversized PDF, and compress it without hurting images, logos or text. Use when the user asks to export, print, save or convert to PDF, to make a PDF smaller, or mentions simple-pdf-export. To write the document itself, draft it first, then use this skill for the export.
metadata:
author: denniemok
version: "1.0.1"
license: MIT
---
# Simple PDF Export
## In short
1. Render with headless Chromium (Playwright), print CSS, backgrounds on, fonts loaded
2. Look at what is heavy: list every image with its pixel size, effective dpi and bytes
3. Fix the heavy ones **at the source, in a print copy** (never the user's files): bake filtered or layered backgrounds into one JPEG, downscale art to about 220 dpi, leave logos alone
4. Re-render, then save with `garbage=4, deflate=True`
5. Verify: page count, no broken images, a pixel diff against the first render, and look at the cover, an image page and a zoomed logo yourself
Target: text stays vector and selectable, images look the same at 100 % and when projected, size drops a lot. A typical 16:9 deck lands at 1 - 3 MB.
## Tools
- `scripts/render.cjs`: HTML to PDF with Playwright. Reports broken images. Uses the page size from `@page` (`preferCSSPageSize`), or `--width` / `--height`
- `scripts/inspect.py`: lists images (size, dpi on the page, bytes, filter, has alpha), saves a cleaned copy, and diffs two PDFs page by page
- `<skill-dir>` is the folder this skill is installed in, such as `~/.claude/skills/simple-pdf-export`. Needs Node with `playwright` (the project's `node_modules`, or `npx playwright install chromium`) and Python with `pymupdf` and `Pillow`. Run Python with `-I`
```bash
node <skill-dir>/scripts/render.cjs <in.html> <out.pdf> [--width 1200px --height 675px]
python -I <skill-dir>/scripts/inspect.py list <file.pdf>
python -I <skill-dir>/scripts/inspect.py clean <in.pdf> <out.pdf>
python -I <skill-dir>/scripts/inspect.py diff <reference.pdf> <new.pdf> [<png-dir>]
```
## Per input
| Input | How |
|---|---|
| HTML deck or page | Check it has `@media print` (one slide per page, `@page{size:...;margin:0}`, animations off, nav hidden). Add it in the print copy if missing. Render with `render.cjs` |
| Markdown | Convert to a simple HTML page with print CSS, then as above |
| Images | Pillow: `Image.save(out, "PDF", save_all=True, append_images=..., resolution=...)` after downscaling photos to the page at about 220 dpi |
| Existing PDF | `inspect.py list` first. Usually only `clean` is safe. Recompress one image by hand only when the list shows it is the weight |
## Where the weight comes from, and the fix
- **CSS `filter`, `mix-blend-mode`, `backdrop-filter`, opacity layers over an image**: Chromium rasterises the whole layer at print scale, often 3 - 4× page width as lossless PNG (a 1600 px photo became 3752 px, 1.9 MB). Fix: screenshot that layer with the content hidden (`.slide>*{visibility:hidden}`, `deviceScaleFactor: 2`, JPEG q88), point the print copy's background at the JPEG and turn the filter and overlay off there
- **Plain JPEG drawn as is**: Chromium passes it through as DCT, no re-encode. Good, leave it
- **WebP or PNG art**: re-encoded lossless (Flate) at its full pixel size, with an alpha mask. Fix: downscale in the print copy so it is about 220 dpi at its drawn size (drawn width in pt / 72 × 220 px), save lossless. Keep alpha
- **Logos and small icons**: few bytes, high visibility. Never touch them
- **Fonts**: Chromium already subsets. CJK fonts still add some hundred KB, accept it
## Don'ts
- Don't run `pymupdf` `Document.rewrite_images()` on a Chromium PDF: it broke shared soft masks (the logo shrank to 128 px, other masks to 8 px) and lost pattern resources
- Don't JPEG anything with transparency or sharp edges (logos, art on transparent background, charts, screenshots of text)
- Don't downscale below about 200 dpi at drawn size, and don't go under JPEG q85 for photos
- Don't edit the user's source HTML or assets. Copy the page and its assets into a temp folder and change the copy
- Don't use an inline heredoc for a script with backslashes or regex. Write the file
## Verify before you hand it over
- `render.cjs` printed `broken images: []`
- `inspect.py diff` against the first, uncompressed render: text pages show 0 difference, image pages a mean under about 2 (of 255)
- Open the PNGs of the cover, one image page and a zoomed crop of the logo, and look
- Say in the reply: before and after size, what was changed and why, what was left alone (logo, text), and that the source files were not touched
## Where to put it
Next to the source, same base name, `.pdf` (for example `docs/x.html` → `docs/x.pdf`), unless the user says otherwise. The print copy, test renders and diff PNGs go in a temp folder, never next to the source. Send it with SendUserFile when that tool exists. Don't commit it unless asked.