Skip to content
zzzhizhiaPublic

About

Smart-slice long screenshots into multi-page PDFs without cutting through text or images (macOS, Apple Vision OCR)

Resources

Stars

4 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

slice2pdf

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.

Quick Start

# one-off
npx slice2pdf screenshot.png

# install globally
npm install -g slice2pdf
slice2pdf screenshot.png

Produces screenshot.pdf next to the input, paginated at A4 ratio with cuts in blank rows.

Usage

# 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

Options

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

How It Works

  1. Compute row energy (per-row pixel std-dev) for the input image.
  2. 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.
  3. 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.
  4. 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.

Requirements

  • macOS (uses Apple Vision via Swift)
  • Node >= 20
  • swift (xcode-select --install)
  • python3 with numpy and Pillow (python3 -m pip install --user numpy Pillow)
  • img2pdf (brew install img2pdf)

Run slice2pdf doctor to verify.

License

MIT

About

Smart-slice long screenshots into multi-page PDFs without cutting through text or images (macOS, Apple Vision OCR)

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages