PDF - what the file format ...
PDF files parsing and data extraction
Work in progress ...
pikepdf
- PDF manipulation and content editing
- https://pikepdf.readthedocs.io/en/latest/installation.html
PyMuPDF
- PDF processing, text/image extraction, rendering
- https://pymupdf.readthedocs.io/en/latest/installation.html
ocrmypdf
- OCR wrapper (uses Tesseract + Ghostscript)
- https://ocrmypdf.readthedocs.io/en/latest/installation.html
Tesseract OCR
- required by OCRmyPDF and PyMuPDF
- https://github.com/UB-Mannheim/tesseract
Ghostscript
- required by OCRmyPDF
- https://www.ghostscript.com/releases/gsdnld.html
unpaper
- required by OCRmyPDF with some params: --clean etc.
- https://github.com/unpaper/unpaper
pngquant
- required by OCRmyPDF with optimize > 0
- https://pngquant.org/
Prerequisites: Python 3.12+, Git
Open terminal/command line
- create the repo dir
- go to the dir
-
Clone the repo:
git clone https://github.com/filak/pdf-wtf
-
Install uv package manager and create the virtual environment:
pip install uv uv venv -
Activate the environment:
.venv\Scripts\activate -
Install dependecies:
uv sync -
Test - run:
pytest
uv add <package>==<version>
OCRmyPDF requires unpaper installed to be able to use --clean and --clean_final params
Install and start Docker Desktop
Build the Docker image - run:
docker build -t unpaper-alpine -f .Dockerfile-unpaper .
Test run:
docker run --rm unpaper-alpine --version
Create ENV vars:
setx PDFWTF_HOME_DIR d:\Decko\pdf-wtf
setx PDFWTF_TEMP_DIR %PDFWTF_HOME_DIR%\instance\temp
Add %PDFWTF_HOME_DIR% to PATH so OCRmyPDF can find the unpaper.cmd
Check:
echo %PDFWTF_HOME_DIR% %PDFWTF_TEMP_DIR%
unpaper.cmd --version
Patch for ocrmypdf to use unpaper on Windows using Docker
\.venv\Lib\site-packages\ocrmypdf\subprocess\_windows.py#180
def fix_windows_args():
...
# Patch for Windows - ".\\unpaper"
if sys.platform.startswith("win"):
if args[0].startswith(".\\unpaper."):
args[0] = args[0].lstrip(".\\")
If you reinstall the package - you MUST insert the patch again !