Automatic Index Builder
Build indexes from PDF or TXT files.
Casts a wide net but it gets everything. Could be a good option for any open-book with index test.
- qpdf
- pdftotext
- PyMuPDF
- Pillow
- numpy
- python-doctr
- torch
- torchvision
- pdfminer.six
- pypdf
- wordfreq
- nltk
- tqdm
sudo apt update
sudo apt install qpdf poppler-utilspython3 -m venv .venv
.venv/bin/python -m pip install -r requirements.txtqpdf --password='PASSWORD' --decrypt book_n.pdf decrypted_n.pdf.venv/bin/python extract_img_text.py decrypted_n.pdf processed_n.pdfThis is a time-consuming step that is not required for most PDFs. Even some PDF that look like they contain images are actually composed of text elements only.
pdftotext processed_n.pdf text_n.txtpdftotext generally gives slightly better results than extracting from the raw PDF. However, PDF layout is lost during conversion to text and multi-column elements may be reordered incorrectly.
.venv/bin/python build_index.py -v -o 2 -l 2 -L 50 -F 10 -z 4.0 -r '[a-zA-Z0-9 :.&_-]+' text_n.txt index_n.txtRecommended Settings:
-v
Verbose output (does not affect index content)-o 2
PDF page numbering starts on the second page-l 2
Minimum token length for items added to the index-L 50
Maximum token length for items added to the index-F 10
Exclude words appearing on more than 10 pages-z 4.0
Exclude words with a Zipf score > 4.0-r
Regex filter for accepted tokens
.venv/bin/python index_merge.py -o index.txt -F 10 index_1.txt index_2.txt index_n.txtRecommended Settings:
-F 10
Exclude words appearing on more than 10 pages total
Install the following tools and ensure they are available on your PATH:
- qpdf
- Poppler for Windows (provides
pdftotext)
Using Winget:
winget install QPDF.QPDF
winget install oschwartz10612.PopplerOr download manually:
- QPDF: https://qpdf.sourceforge.io/
- Poppler: https://github.com/oschwartz10612/poppler-windows/releases
python -m venv .venv
.\.venv\Scripts\python.exe -m pip install -r requirements.txtqpdf --password="PASSWORD" --decrypt book_n.pdf decrypted_n.pdf.\.venv\Scripts\python.exe extract_img_text.py decrypted_n.pdf processed_n.pdfThis is a time-consuming step that is not required for most PDFs. Even some PDFs that appear to contain images are actually composed entirely of searchable text.
pdftotext processed_n.pdf text_n.txtpdftotext generally produces slightly better results than extracting text directly from the PDF. However, PDF layout is lost during conversion and multi-column content may be reordered incorrectly.
.\.venv\Scripts\python.exe build_index.py -v -o 2 -l 2 -L 50 -F 10 -z 4.0 -r "[a-zA-Z0-9 :.&_-]+" text_n.txt index_n.txtRecommended Settings:
-
-v
Verbose output (does not affect index content) -
-o 2
PDF page numbering starts on the second page -
-l 2
Minimum token length for items added to the index -
-L 50
Maximum token length for items added to the index -
-F 10
Exclude words appearing on more than 10 pages -
-z 4.0
Exclude words with a Zipf score greater than 4.0 -
-r
Regex filter for accepted tokens
.\.venv\Scripts\python.exe index_merge.py -o index.txt -F 10 index_1.txt index_2.txt index_n.txtRecommended Settings:
-F 10
Exclude words appearing on more than 10 pages across all input indexes.
