A tool for automatically paginating vertical-scroll PDFs (like tablet notes) into standard-sized pages.
- Automatic Title Detection: Detects titles using either text metadata (pdfplumber) or visual pixel analysis (PyMuPDF + NumPy)
- Interactive Web UI: Drag-and-drop PDF upload with visual cut point editing
- Smart Pagination: DP algorithm groups sections to minimize deviation from A4 size
- Dark Bar Removal: Automatically cleans annotation artifacts from PDFs
- Multiple Modes: Auto-detect, force text mode, or force visual mode
pip install -r requirements.txtRequirements:
- Python 3.7+
- flask
- pdfplumber
- pymupdf
- numpy
python3 app.pyThen open http://localhost:5000 in your browser.
- Drag and drop a PDF or click to browse
- Toggle "Auto cuts" for automatic cut point detection
- Click the PDF to add manual cut points
- Drag cut lines to reposition them
- Download the paginated PDF
# Automatic mode (detects best method)
python3 crop_pdf.py input.pdf
# Specify output name
python3 crop_pdf.py input.pdf -o output.pdf
# Force text mode
python3 crop_pdf.py input.pdf --mode text
# Force visual mode
python3 crop_pdf.py input.pdf --mode visual
# Debug colors (see what the tool detects)
python3 crop_pdf.py input.pdf --debug-colors--min-size: Minimum font size for title detection (default: 13.5)--max-x0: Maximum left margin for title alignment (default: 50.0 pt)--colors: Custom title colors as "r,g,b;r,g,b" (default: blue and red)
--zoom: Rasterization factor (default: 1.5)--min-band-h: Minimum colored band height (default: 14.0 pt)--max-band-h: Maximum colored band height (default: 50.0 pt)--min-ratio: Minimum width fraction with colored pixels (default: 0.08)--hue-blue: Blue hue range as "min,max" (default: "195,225")--hue-red: Red hue range as "wrap,max" (default: "330,15")
--padding: Space before each title in the cut (default: 14.0 pt)--merge-gap: Minimum gap between titles (default: 60.0 pt)--max-ratio: Maximum page height as multiple of A4 (default: 1.15)--min-last: Minimum height of last page before merging (default: 120.0 pt)
- Clean: Removes dark annotation bars from the PDF
- Detect Mode: Analyzes the PDF to choose text or visual mode
- Find Titles: Identifies title positions using color/size analysis
- Find Cut Points: Searches for optimal whitespace lines near titles
- Compute Pages: Uses DP to group sections into A4-sized pages
- Generate PDF: Creates the output PDF with proper page breaks
python3 -m pytest tests/ -v