A CLI tool for reordering PDF pages for section binding (bookbinding)
Project description
PDF Section Binding Tool
This tool reorders PDF pages for section binding (bookbinding), where pages are arranged in signatures (folded sheets) so that when printed and folded, they appear in the correct reading order.
Installation
From PyPI (Recommended)
pip install pdf-section-binding
From Source
- Clone the repository:
git clone https://github.com/yourusername/pdf-section-binding.git
cd pdf-section-binding
- Create and activate virtual environment:
python3 -m venv venv
source venv/bin/activate # On macOS/Linux
# or
venv\Scripts\activate # On Windows
- Install in development mode:
pip install -e .
Usage
After installation, use the pdf-section-binding command (or the shorter section-binding alias):
pdf-section-binding input.pdf [options]
Command Line Options
-o, --output: Output PDF file path (default:input_name_section_bound.pdf)-s, --signature-size: Pages per signature - must be multiple of 4 (default: 8)--dry-run: Preview analysis without creating output file-v, --verbose: Enable verbose output with progress tracking-q, --quiet: Suppress all output except errors--force: Overwrite output file if it exists--version: Show version information-h, --help: Show help message
Examples
# Basic usage with 8-page signatures (2 papers per signature)
pdf-section-binding book.pdf
# Specify output file and 4-page signatures (1 paper per signature)
pdf-section-binding book.pdf -o output.pdf -s 4
# Use 16-page signatures (4 papers per signature)
pdf-section-binding book.pdf -s 16
# Use 40-page signatures (10 papers per signature)
pdf-section-binding book.pdf -s 40
# Preview without creating file (dry run)
pdf-section-binding book.pdf --dry-run
# Verbose output with progress tracking
pdf-section-binding book.pdf -v
# Quiet mode (minimal output)
pdf-section-binding book.pdf -q
# Force overwrite existing output
pdf-section-binding book.pdf --force
Features
โจ Enhanced CLI Tool
- ๐จ Colorized output for better user experience
- ๐ Progress tracking for large documents
- ๐ Dry run mode to preview without creating files
- โก Fast processing with optimized algorithms
- ๐ก๏ธ Robust error handling with helpful suggestions
- ๐ Flexible signature sizes (any multiple of 4)
๐ง Advanced Options
- Verbose and quiet modes
- Force overwrite protection
- Input validation with helpful error messages
- Multiple command aliases (
pdf-section-bindingorsection-binding)
๐ฆ Library Usage
- Use as a Python library in your own projects
- Clean API with
SectionBindingProcessorclass - Comprehensive test suite included
CLI Features in Detail
Smart Error Messages
The tool provides helpful suggestions when you make mistakes:
$ pdf-section-binding book.pdf -s 15
Error: Signature size must be a multiple of 4 (each paper = 4 pages).
You specified 15. Try: 12 or 16
Progress Tracking
For large documents, see progress in real-time:
$ pdf-section-binding large-book.pdf -v
PDF Section Binding Tool v1.0.0
==================================================
[INFO] Reading PDF: large-book.pdf
[INFO] Total pages: 1500
[INFO] Signature size: 8
[INFO] Creating reordered PDF...
Creating PDF: [โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ] 100% (1500/1500)
[INFO] Writing output: large-book_section_bound.pdf
โ
Successfully created: large-book_section_bound.pdf
Dry Run Analysis
Preview the binding setup without creating files:
$ pdf-section-binding book.pdf --dry-run
๐ DRY RUN ANALYSIS:
Would process 701 pages
Would create 88 signatures
Would need 176 papers total
Would save to: book_section_bound.pdf
Section binding involves:
- Signature Creation: Pages are grouped into signatures (folded sheets)
- Page Reordering: Pages are rearranged so that when printed double-sided and folded, they appear in correct reading order
- Printing: Print the reordered PDF double-sided
- Folding: Fold each signature in half
- Binding: Stack signatures and bind along the fold
Signature Sizes
- 4 pages: Each signature uses 1 paper (2 pages front, 2 pages back)
- 8 pages: Each signature uses 2 papers (4 pages front, 4 pages back)
- 16 pages: Each signature uses 4 papers (8 pages front, 8 pages back)
- 32 pages: Each signature uses 8 papers (16 pages front, 16 pages back)
- 40 pages: Each signature uses 10 papers (20 pages front, 20 pages back)
- Custom sizes: Any multiple of 4 pages (e.g., 12=3 papers, 20=5 papers, 24=6 papers)
Paper Calculation
Formula: Papers per signature = Signature size รท 4
Examples:
- 10 papers = 40 pages per signature
- 6 papers = 24 pages per signature
- 3 papers = 12 pages per signature
Example Output
For a 4-page signature with pages 1, 2, 3, 4:
- The reordered sequence would be: [4, 1, 3, 2]
- When printed double-sided and folded, you get pages in order: 1, 2, 3, 4
Generated Files
This tool was used to process the book in data/book.pdf:
data/book_section_bound.pdf- Default 8-page signatures (2 papers each)data/book_40page_signature.pdf- 40-page signatures (10 papers each)
Publishing to PyPI
This package is ready for PyPI publication! Here's how to publish it:
Prerequisites
Build and Upload
-
Build the package:
python -m build
-
Test on TestPyPI first:
twine upload --repository testpypi dist/*
-
Upload to PyPI:
twine upload dist/*
Package Structure
The package follows modern Python packaging standards:
pdf-section-binding/
โโโ src/pdf_section_binding/ # Source code
โ โโโ __init__.py
โ โโโ cli.py # Enhanced CLI interface
โ โโโ core.py # Core processing logic
โ โโโ version.py # Version and metadata
โโโ tests/ # Comprehensive test suite
โโโ pyproject.toml # Modern packaging config
โโโ setup.py # Fallback setup config
โโโ LICENSE # MIT license
โโโ README.md # This file
โโโ requirements.txt # Dependencies
Development Setup
For development work:
# Clone and setup
git clone <your-repo-url>
cd pdf-section-binding
# Create virtual environment
python -m venv venv
source venv/bin/activate # or venv\Scripts\activate on Windows
# Install in development mode
pip install -e .[dev]
# Run tests
pytest
# Run with coverage
pytest --cov=pdf_section_binding
# Format code
black src/ tests/
# Lint code
pylint src/ tests/
# Type checking
mypy src/
Requirements
- Python 3.7+
- PyPDF2 library
Binding Instructions
After running the script:
- Print the output PDF double-sided (flip on long edge)
- Cut or separate the printed sheets by signature
- Fold each signature in half along the center
- Stack all signatures in order
- Bind along the folded edge using:
- Saddle stitching (stapling)
- Perfect binding (glue)
- Spiral binding
- Or other binding methods
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdf_section_binding-1.0.1.tar.gz.
File metadata
- Download URL: pdf_section_binding-1.0.1.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74c17876f2c4292ca1437f8988074ed1873d89aa65d1792c2a9bf4bcbdd2223d
|
|
| MD5 |
9c2a1ecde991c17fedbb9c642d3b6c66
|
|
| BLAKE2b-256 |
115561e646d520631e7172412c5a20a1eec3d87e6a27261efab2cd7c918030bc
|
File details
Details for the file pdf_section_binding-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pdf_section_binding-1.0.1-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0e00db6f9530ccf03ca66946691b94fafebb9651601478814bd77433ea99cd1
|
|
| MD5 |
5b6d8497a817ecc86fb79464a3de9100
|
|
| BLAKE2b-256 |
16d752f70ccf6c09f87b62b41df544b2eeb0f5a8bc5bb77e530bc27175411ef3
|