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.1.tar.gz (17.2 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.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for split_pdf_by_toc-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5fe5f57d4812753c99987554684a20caf91a2414ea3499d31cf585964799d138
MD5 35fb05e80150f8e41b3bafca15ca7a30
BLAKE2b-256 eca92c19c9b8c5d02fc048b218323226034ac23dfe7e9a6c771abe409677f1f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for split_pdf_by_toc-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 15dcc897b1870e54a3423e51e3f67d4b2cd82998f18d21c31bd20e3e3e4d52ad
MD5 c0ed4bc12ac102a782d94e10a2573cbc
BLAKE2b-256 094a03f7817253acb84b129ad38de6fc741f96c1521f000dd1ffe42014f664f6

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