Skip to main content

Splits a PDF by its TOC.

Project description

split-pdf-by-toc

A small command-line tool that splits a PDF into multiple files based on its table of contents (TOC).

It reads the embedded TOC entries of a PDF and uses them as cut points to generate one PDF per section.

Status

Status: usable / evolving Audience: CLI users, developers Python: 3.12+

Features

  • Split PDFs using embedded TOC markers
  • Limit splitting by TOC depth
  • Filter TOC entries by name
  • Optional overlapping page ranges
  • Configurable output directory and filename prefix

Non-features

  • No OCR for scanned PDFs
  • No TOC generation or editing
  • No GUI

Installation

Clone the repository and install dependencies:

cd split-pdf-by-toc
pip install -r requirements.txt

Usage

usage: split-pdf-by-toc [-h] [-o OUTPUT_DIR] [--overlap] [-d DEPTH]
                        [-f FILTER] [-p PREFIX]
                        pdf_path

Splits a PDF by TOC markers.

positional arguments:
  pdf_path              Set the input PDF

options:
  -h, --help            show this help message and exit
  -o OUTPUT_DIR, --output-dir OUTPUT_DIR
                        Set the output directory
  --overlap             If provided, let output pages overlap with each other.
  -d DEPTH, --depth DEPTH
                        Set the maximum depth of TOC entries
  -f FILTER, --filter FILTER
                        Only select TOC entries matching a filter
  -p PREFIX, --prefix PREFIX
                        Set a prefix for the output files

Examples

  • Split a PDF by its top-level TOC entries:
    $ split-pdf-by-toc book.pdf
    
  • Only split up to depth 2 and write results to out/:
    split-pdf-by-toc -d 2 -o out book.pdf
    
  • Only split sections whose titles contain "Chapter":
    split-pdf-by-toc -f Chapter book.pdf
    

Contributing

Contributions are very welcome. Please use ruff to format and lint.

Small changes (bug fixes, small improvements): please open a pull request directly.

Larger changes (new features, refactors, behavior changes): please open an issue first to discuss the idea and avoid wasted work.

If you add new behavior, tests are appreciated but not mandatory.

License

This project is licensed under the AGPL (Affero General Public License). See the LICENSE file for details.

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

split_pdf_by_toc-0.0.3.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

split_pdf_by_toc-0.0.3-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file split_pdf_by_toc-0.0.3.tar.gz.

File metadata

  • Download URL: split_pdf_by_toc-0.0.3.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for split_pdf_by_toc-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ff914ce1464c029d9f24ea363a2de5502237b4f43ac4f6041401f5cb824907eb
MD5 01e83be2e7ac617a941b2d4ed0981420
BLAKE2b-256 9fbd9807e9b6f0696ce3ee79685de19dccc05af0786bf0a1c2404b2127b195d8

See more details on using hashes here.

File details

Details for the file split_pdf_by_toc-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for split_pdf_by_toc-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6167afa7779a38c5ea368e1369bf3387c6efb2b519f48fdd7ac6c4f966f9576e
MD5 f154ff58746409b9c820f11c8d790976
BLAKE2b-256 8bae67f43803718d7e32ef372e2e3f398e67cf925d2a8676bdac1a4090241ad9

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