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.2.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.2-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: split_pdf_by_toc-0.0.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5fb9980da71a11f2852312fea7462efadd0512ef4728ff7173e9ffe037247d84
MD5 64ba8fdcadc9cf996383cdcfd0f30b31
BLAKE2b-256 b74cfc76c3457c9a42c71e53c817d37ecfaec29cfa373f0301625ce02fc22d4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for split_pdf_by_toc-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4e7293a79807322f71ef9fe5806f72d9cc54fb3a99e3c3b44bac210de5b370ae
MD5 f1e95428cb83a7bfdf232fb3ccb83691
BLAKE2b-256 7eef35669cf01e65839ff76a395146e720fdc973e9a5f07e8bc00b3c8166bb12

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