feat(pdf): add from-images and to-images subcommands (MK-4) #23
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/pdf-from-to-images"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Add two new
pdfverbs that round-trip the image -> PDF -> image flow.monkey pdf from-images <INPUT...> <OUTPUT.pdf>bundles N images into one multi-page PDF usinglopdf+flate2. Each input becomes aDeviceRGBXObject with a one-page content stream sized to the page MediaBox. Resurrects theassemble_pdfpath removed by PR #17. Flags:--dpi <N>overrides input DPI metadata,--page-size <auto|letter|a4>picks between deriving the page size from pixel count + DPI vs. forcing a fixed page size. Clap'snum_args = 2..rejects "no inputs" at parse time.monkey pdf to-images <INPUT.pdf> <OUTPUT_DIR>rasterizes each page by shelling out topdftoppmfrompoppler-utils, mirroring howmonkey video convertdelegates toffmpeg. Flags:--format <png|jpeg|tiff>,--dpi <N>(default 300),--first-page/--last-page,--basename <STEM>(default: PDF stem). Output filenames are<basename>-<N>.<ext>with pdftoppm's natural zero-padding. Missingpdftoppmproduces an actionable error with the install hint, not a panic.read_dpiis extracted fromnoteshrinktosrc/dpi.rsso both modules share it.Runtime Dockerfile picks up
poppler-utilsalongsideffmpeg. CLAUDE.md notespdftoppmas a runtime dep.pdf extract-imagesis unchanged: it solves the different problem of pulling embedded XObject streams without rasterization.No new top-level Rust deps. 52 unit tests pass (added 8). Manual round-trip succeeds end-to-end.
#MK-4
Test plan
just check(fmt, clippy, build, tests, docker compile check)monkey pdf from-images a.png b.png c.png out.pdfproduces a 3-page PDFmonkey pdf to-images in.pdf out/writes<stem>-N.pngper page (pdftoppmpresent)monkey pdf to-images --format jpeg --dpi 150 in.pdf out/writes 150 DPI JPEGsmonkey pdf from-images out.pdf(no inputs) errors at clap parse with exit 2monkey pdf extract-imagesbehaviour unchangedfrom-images sample.png round.pdf && to-images round.pdf out/ && image diff sample.png out/round-1.png check.png --threshold 0.05succeedspdftoppmerror path (manual: requires unsetting PATH; left to follow-up smoke test)