pdf-flatten
Skill2 starsChanged 2 months agoMITView on GitHub
Use when flattening PDFs to page images or raster PDFs.
- Installs packages
In this repository58 other files it gives its agents.
- ad-hoc-script-verificationSkill
- architecture-diagramSkill
- blocked-page-recoverySkill
- cadquery-enclosure-designSkill
- canonical-thumbnailSkill
- circuit-designSkill
- competitor-news-monitorSkill
- component-alternativesSkill
- debugging-hermes-tui-commandsSkill
- docker-container-update-checkSkill
- document-to-action-itemsSkill
- docxSkill
- email-inbox-triageSkill
- embedded-porting-patternsSkill
- ephemeral-file-sharingSkill
- excalidrawSkill
- flash-game-researchSkill
- flutter-android-buildSkill
- flutter-content-renderingSkill
- github-code-reviewSkill
- githubSkill
- goatcounter-analyticsSkill
- google-oauth-file-pollSkill
- grounded-citationsSkill
- hermes-agent-skill-authoringSkill
- hermes-gateway-slash-commandSkill
- hermes-gateway-supervisionSkill
- jellyseerr-watch-suggestionsSkill
- maintained-fork-publishingSkill
- meeting-action-itemsSkill
- native-mcpSkill
- obsidian-mapsSkill
- pdfSkill
- pdf-surgical-editsSkill
- planSkill
- product-price-monitorSkill
- psp-developmentSkill
- psp-homebrew-testingSkill
- psp-prx-plugin-maintenanceSkill
- python-debugpySkill
- python-webapp-patternsSkill
- reddit-readingSkill
- retro-fansiteSkill
- reverse-proxy-websocket-debuggingSkill
- rss-feedsSkill
- simplify-codeSkill
- sketchSkill
- skit-thumbnailSkill
- spikeSkill
- subagent-driven-developmentSkill
- test-driven-developmentSkill
- usb-device-enumerationSkill
- weekly-review-planningSkill
- wiki-media-asset-pipelineSkill
- windows-c-build-toolchainSkill
- windows-crash-forensicsSkill
- writing-plansSkill
- yt-dlp-anti-botSkill
The file
Files
PDF Flatten
Overview
Flatten any PDF into a pixel-perfect raster form: either a set of per-page images (PNG/JPG) or a rebuilt PDF where every page is a high-DPI render. This kills the text layer intentionally — the result is exactly what a vision model or a human sees when they look at the page. Built for datasheet workflows, scanned-document archival, and feeding documents to image-based models.
Two scripts ship with this skill (in scripts/):
pdf_to_pages.py— render pages to images:--dpi(default 250),--out,--format png|jpg,--quality,--pages 1-5/3,5,7-10,--jsonfor machine-readable output.pdf_flatten.py— rebuild the whole PDF from rendered pages.
Both use PyMuPDF: pip install pymupdf.
When to Use
- A PDF must be consumed as images (vision models, screenshots in a container).
- Vector/text artifacts break downstream tooling and you need "what you see".
- Datasheets or scanned docs where the selectable-text layer is corrupt or missing.
- Don't use for: text extraction or search — this converts to pixels by design. Use extraction tooling instead when text matters.
Scanned PDF Detection (before flattening)
An image-only PDF has no text layer. Detect it cheaply with PyMuPDF — if all three return empty, it's scanned and rasterization is the only path:
page = doc[i]
text = page.get_text('text') # ''
blocks = page.get_text('blocks') # []
words = page.get_text('words') # []Usage
# Every page as PNG at 250 DPI
python3 scripts/pdf_to_pages.py input.pdf
# Custom DPI + output dir
python3 scripts/pdf_to_pages.py input.pdf --dpi 300 --out ./pages
# JPEG with quality control
python3 scripts/pdf_to_pages.py input.pdf --format jpg --quality 90
# Page range (big documents)
python3 scripts/pdf_to_pages.py input.pdf --pages 1-5
# Rebuild a flat, raster-only PDF
python3 scripts/pdf_flatten.py input.pdf -o flattened.pdf --dpi 250Batch / Pipeline Pattern
Chain both scripts for N documents in one pass: gather files, iterate, render each page, rebuild each PDF into a dated output folder. Keep the pipeline idempotent — skip already-rendered outputs.
Common Pitfalls
- Memory on large page counts — rendering 600+ pages at 300 DPI is
heavy; process page ranges (
--pages) or reduce--dpi. - The text layer is gone on purpose — do not "flatten then extract text"; flatten only when pixels are the deliverable.
- Output dates/timestamps — write outputs to a dated folder so reruns don't collide.
- Rebuilt PDF size — 250 DPI PNG inside PDF can be large; JPEG with
--quality 90is a good compressor for photo-like pages. - PyMuPDF version drift — pin
pymupdfin requirements; save/doc.savekeyword names changed across versions.
Verification Checklist
- Rendered page count equals source page count (or the requested range)
- Rebuilt PDF opens and every page is an image (no selectable text)
- Output dimensions match source aspect ratio
- Spot-check 1-2 pages visually before distribution
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.

