Skip to main content

Merge PDFs recursively from a folder tree into a single PDF with hierarchical bookmarks.

Project description

nestedpdfmerger

Merge PDFs recursively from a folder tree into a single PDF with automatic hierarchical bookmarks based on the directory structure.

Installation

pip install nestedpdfmerger

Quick start

nestedpdfmerger ./reports -o merged.pdf

Example input tree

reports/
├── intro.pdf
├── chapter1/
│   ├── part1.pdf
│   └── part2.pdf
└── appendix/
    └── appendixA.pdf

Resulting bookmarks in merged.pdf:

intro
chapter1
 ├─ part1
 └─ part2
appendix
 └─ appendixA

Usage

nestedpdfmerger INPUT_DIR -o OUTPUT.pdf [options]

Options

Flag Description
-o, --output PATH Output PDF path (default: <INPUT_DIR>.pdf)
--sort {natural,alpha,mtime} Sort mode (default: natural)
--reverse Reverse sort order
--exclude NAME [NAME ...] Directory names to skip
--exclude-hidden Skip hidden directories (starting with .)
--no-bookmarks Disable hierarchical bookmarks
--dry-run Preview merge order without writing output
--strict Stop on first PDF error instead of skipping
--verbose Show detailed progress
--quiet Suppress non-error output
--version Show version and exit

Examples

Preview what would be merged:

nestedpdfmerger ./reports --dry-run

Natural sort, exclude backup folders, verbose output:

nestedpdfmerger ./reports \
  --output merged.pdf \
  --sort natural \
  --exclude Backup Data \
  --verbose

Sort by modification time, newest last:

nestedpdfmerger ./reports -o merged.pdf --sort mtime --reverse

Python API

from nestedpdfmerger import merge_pdf_tree

merge_pdf_tree(
    input_dir="reports",
    output_file="merged.pdf",
    sort_mode="natural",
    exclude=["Backup", "Data"],
    bookmarks=True,
)

Sort modes

Mode Description
natural Human-friendly natural sort (1, 2, 10 not 1, 10, 2)
alpha Case-insensitive alphabetical
mtime File/directory modification time (oldest first)

Error handling

By default, corrupted, encrypted, or unreadable PDFs are warned and skipped. Use --strict to stop on the first error.

License

MIT

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

nestedpdfmerger-1.0.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

nestedpdfmerger-1.0.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nestedpdfmerger-1.0.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for nestedpdfmerger-1.0.0.tar.gz
Algorithm Hash digest
SHA256 51530f7384f565b347250df1429bd7e7b0134496fce4ff4f3b49eb44695fa8ba
MD5 dff87a260479bc0a6a516d34c63c1339
BLAKE2b-256 c0c870861a16e097288260d8387c2f72e445eed2ad9b45c1c20be6ca6eec63cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nestedpdfmerger-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 76e5f9c0f266f4fe658cf967171947f9ab97939b7d9c78c83804e9cba1f7f678
MD5 3a10faf8b02671effbd9c5138a00332e
BLAKE2b-256 3ebcc59c05f94c88e4e15f87098d40a8971e832c8b9a03ba73b0624d935b0508

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