Smart-slice long screenshots into multi-page PDFs without cutting through text or images.
Uses Apple Vision OCR to find text-line bounding boxes, then picks page breaks that never bisect any line. Falls back to row-energy heuristics when OCR is unavailable.
# one-off
npx slice2pdf screenshot.png
# install globally
npm install -g slice2pdf
slice2pdf screenshot.pngProduces screenshot.pdf next to the input, paginated at A4 ratio with cuts in blank rows.
# single image -> single pdf
slice2pdf screenshot.png
# every image in a directory
slice2pdf ~/Desktop
# rename output pdf to the OCR'd first-page title
slice2pdf screenshot.png --rename
# keep the per-page PNG slices for inspection
slice2pdf screenshot.png --keep-pages
# pick interactively from cwd images
slice2pdf| Flag | Default | Description |
|---|---|---|
--out <path> |
<input>.pdf |
output pdf path |
--rename |
off | rename pdf to first-page title (Apple Vision OCR) |
--keep-pages |
off | keep <basename>-pages/ slice directory |
--help |
print usage | |
--version |
print version |
Subcommands:
| Command | What |
|---|---|
slice2pdf doctor |
check that swift, python3 (numpy + Pillow), and img2pdf are installed |
- Compute row energy (per-row pixel std-dev) for the input image.
- Tile the image vertically and run Apple Vision text recognition; merge bboxes back to global coordinates. Tile boundaries snap to blank rows so no text line is split at a seam.
- For each ideal A4 cut, search a window for the longest run of rows not covered by any text bbox. Cut at the row inside that run with the lowest content.
- Crop into PNGs and assemble with
img2pdf(lossless, no JPEG re-encoding).
Cuts are independently audited against the OCR bboxes; the algorithm is verified to produce zero text-bisecting page breaks on real-world long screenshots.
- macOS (uses Apple Vision via Swift)
- Node >= 20
swift(xcode-select --install)python3withnumpyandPillow(python3 -m pip install --user numpy Pillow)img2pdf(brew install img2pdf)
Run slice2pdf doctor to verify.
MIT