Metadata-Version: 2.4
Name: nestedpdfmerger
Version: 1.0.0
Summary: Merge PDFs recursively from a folder tree into a single PDF with hierarchical bookmarks.
License: MIT License
        
        Copyright (c) 2026 nested-pdf-merger contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/Lyutenant/nested-pdf-merger
Keywords: pdf,merge,bookmarks,cli
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pypdf>=4.0
Requires-Dist: natsort>=8.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: ruff>=0.1; extra == "dev"
Dynamic: license-file

# nestedpdfmerger

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

## Installation

```bash
pip install nestedpdfmerger
```

## Quick start

```bash
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:

```bash
nestedpdfmerger ./reports --dry-run
```

Natural sort, exclude backup folders, verbose output:

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

Sort by modification time, newest last:

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

## Python API

```python
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
