Skip to content

dull-bird/pdf_toc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A PDF TOC Generator

English | 中文版

Introduction

We often find some PDF files do not have a table of contents (TOC), which makes it inconvenient for us to read the file, especially for books. I build this tool to help you to generate one TOC. To do this, you need:

  1. a PDF file.
  2. a TOC file (.txt), containing the TOC information in such a format:
level title page

An example:

1 title 1 1
1.1 title 2 2
1.2 title 3 3
1.2.1 title 4 4
2 title 5 10

Note:

  • Any level titles are supported now.
  • PyMuPDF has some rules of TOC:
    • It will delete the previous TOC and create a new one.
    • level is a integer (> 0) which must be 1 for the first item and at most 1 larger than the previous one.
    • page can be set to -1 if there is no target, or the target is external.

Since sometimes the TOC file may not be fully correct (some typo when you copy the text from the pdf files), I implement a preview panel so you can preview and edit the level (can be done easily by clicking the "+1" and "-1" button), title, or the page number in the panel.

The tool supports a page offset which will be added to the pages in the TOC file (an positive or negative integer, default 0).

Features

  • An editing panel to adjust title, level and page
  • Support any level contents
  • Ignore empty lines in the TOC (.txt) file
  • Highlight (with red background) invalid (non-integer) page numbers and invalid levels (non-integer or smaller than 1), and stop adding the TOC if they are detected

Requirements

  • python 3 (>=3.8) (other versions may also work)
  • PyQt5 (>=5.9.2) and PyMuPDF (>=1.22.5) installed (other versions may also work)

Installation

  • Install Python
  • Install PyQt5:
pip install PyQt5

or

conda install -c anaconda pyqt
  • Install PyMuPDF:
python -m pip install --upgrade pymupdf

Usuage

  • First download the git repository (you can simply download the zip file and unzip it).
  • Go to the folder containing main.py, and run
python main.py

A window will show:

alt text

You can run test:

alt text

And the output file will be saved in the same folder with the original PDF file.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages