Skip to main content

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

  1. Clone the repository:
git clone https://github.com/yourusername/pdf-section-binding.git
cd pdf-section-binding
  1. Create and activate virtual environment:
python3 -m venv venv
source venv/bin/activate  # On macOS/Linux
# or
venv\Scripts\activate  # On Windows
  1. 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-binding or section-binding)

๐Ÿ“ฆ Library Usage

  • Use as a Python library in your own projects
  • Clean API with SectionBindingProcessor class
  • 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:

  1. Signature Creation: Pages are grouped into signatures (folded sheets)
  2. Page Reordering: Pages are rearranged so that when printed double-sided and folded, they appear in correct reading order
  3. Printing: Print the reordered PDF double-sided
  4. Folding: Fold each signature in half
  5. 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

  1. Create accounts on PyPI and TestPyPI
  2. Install build tools:
    pip install build twine
    

Build and Upload

  1. Build the package:

    python -m build
    
  2. Test on TestPyPI first:

    twine upload --repository testpypi dist/*
    
  3. 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:

  1. Print the output PDF double-sided (flip on long edge)
  2. Cut or separate the printed sheets by signature
  3. Fold each signature in half along the center
  4. Stack all signatures in order
  5. Bind along the folded edge using:
    • Saddle stitching (stapling)
    • Perfect binding (glue)
    • Spiral binding
    • Or other binding methods

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdf_section_binding-1.0.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdf_section_binding-1.0.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file pdf_section_binding-1.0.0.tar.gz.

File metadata

  • Download URL: pdf_section_binding-1.0.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for pdf_section_binding-1.0.0.tar.gz
Algorithm Hash digest
SHA256 459df7d72d911d17a1b657cd59719f7916e12044fccab026fda48dcdc4a5e6e7
MD5 aea80db53d10fa5c1ad933574ba7ff63
BLAKE2b-256 26b1cd85ed41843d5d4e251aa64bfba5554f2db5fd0057fe2403dffc437f45a8

See more details on using hashes here.

File details

Details for the file pdf_section_binding-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pdf_section_binding-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 14ba544dcf73f8cda112be5cc0ba7006455595fe5f69ac76f30373a04baf69ee
MD5 041da4fc0174dafc7d9d593a8039a414
BLAKE2b-256 edae3c2cefbf581780d3852115afe6efe2aba6460c2317810900d8d3d41b23eb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page