https://github.com/vb64/pdftoc
Merging several pdf files and generate hierarchy TOC for the resulting pdf.
https://github.com/vb64/pdftoc
hierarchical-toc pdf pypdf2 python3
Last synced: 9 months ago
JSON representation
Merging several pdf files and generate hierarchy TOC for the resulting pdf.
- Host: GitHub
- URL: https://github.com/vb64/pdftoc
- Owner: vb64
- License: mit
- Created: 2021-06-25T13:21:17.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-07-15T10:25:35.000Z (almost 5 years ago)
- Last Synced: 2025-10-14T20:13:19.089Z (9 months ago)
- Topics: hierarchical-toc, pdf, pypdf2, python3
- Language: Python
- Homepage:
- Size: 59.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.txt
- License: LICENSE
Awesome Lists containing this project
README
# PdfTOC utility
[](https://github.com/vb64/pdftoc/actions?query=workflow%3A%22pdftoc+pep257%22)
[](https://github.com/vb64/pdftoc/actions?query=workflow%3A%22pdftoc+tests%22)
[](https://www.codacy.com/gh/vb64/pdftoc/dashboard?utm_source=github.com&utm_medium=referral&utm_content=vb64/pdftoc&utm_campaign=Badge_Grade)
[](https://www.codacy.com/gh/vb64/pdftoc/dashboard?utm_source=github.com&utm_medium=referral&utm_content=vb64/pdftoc&utm_campaign=Badge_Coverage)
Merging several pdf files and generate hierarchy TOC for the resulting pdf. TOC and set of source pdf files are defining in JSON file.
Usage:
```bash
pdftoc toc.json
```
For example, to produce resulting `build/output/Merged report.pdf` file from `fixtures/example.pdf` with hierarchical TOC:

Use the following `toc.json` file:
```json
{
"target": "build/output/Merged report.pdf",
"folder": "fixtures",
"toc": [
["Level 0", "", [
["Level 1", "{f}example.pdf", []],
["Level 1", "{f}example.pdf", [
["Level 2", "{f}example.pdf", []],
["Level 2", "{f}example.pdf", []]
]],
["Level 1", "{f}example.pdf", []]
]],
["Level 0", "{f}example.pdf", []]
]
}
```
Sequence "{f}" is optional placeholder. It will be replaced with the value of "folder" key ('fixtures' in the given example).
If you want to align sections borders in resulting pdf on an even number of pages (for example when printing hard copy), you can use `evenpages` key in json file.
```json
{
"target": "Merged_report.pdf",
"evenpages": 1,
```
You can download the ready [win64 binary executable](https://github.com/vb64/pdftoc/releases/download/v.1.2/pdftoc.exe) or create your version from sources.
Download and install:
- [Python 3](https://www.python.org/downloads/release/python-3810/)
- GNU [Unix Utils](http://unxutils.sourceforge.net/) for makefile operation
Then
```bash
git clone git@github.com:vb64/pdftoc.git
cd pdftoc
make setup PYTHON_BIN=/path/to/python3/executable
make tests
make exe
```
`pdftoc.exe` will be created in `dist` subfolder.