LKChenLK / correct-pdf-filenames

Use OCR to extract title from pdf papers; rename file with related info

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

correct pdf filenames

This is a tool that helps rename the papers downlowded from the internet with correct filenames and relevant information (year published, authors). Currently the accuracy is still not high (3/5 are correct for the testing papers), but the whole pipeline is complete and can be easily modified or optimized.

Currently the code only works when you place all the papers you want to rename in a folder named "papers" (case sensitive!) under the same directory as the code. There are a couple of sample papers in the folder, which you can replace with your own papers to rename.

The program will generate a new folder under the same directory as You will be asked to name the subfolder during runtime. The directory tree is as shown:

This project
│   .env
│   requirements.txt
│   │   paper_to_rename_1.pdf
│   │   paper_to_rename_2.pdf
│   │   ...
│   │   
│───[where the renamed pdfs will be]
│   │   renamed_pdf_1.pdf
│   │   renamed_pdf_2.pdf
│   │   ...
│   └───  


Download and install before running the code

  • Tesseract
    • Mac: brew install tesseract
  • Poppler
    • Windows: download here, install, add to PATH
    • Mac: brew install poppler

Python dependencies

Please refer to requirements.txt, and run pip3 install -r requirements.txt in your terminal to install all packages at once. You may want to create a virtual environment first.

Troubleshooting for installing python packages

Click to expand

Here are some possible problems you may encounter if you're running the code with a Jupyter notebook:
Problem with importing cv2

  • check if juyter is installed in virtual env
  • check if
import sys

in both Jupyter and in the terminal report the same path

  • if error message is ImportError: cannot open shared object file: No such file or directory:
    do in terminal:
sudo apt update
sudo apt install libgl1-mesa-glx

source: conda-forge/pygridgen-feedstock#10

Google API key

If you want to run this code on your own computer, you will need to sign up for a google api key for yourself! For the code to read your API key, please save it as a .env file under the same directory as the file (refer to directory tree above) like so:

GOOGLE_API_KEY="your api key here"
SEARCH_ENGINE_ID="your search engine id here"

For more information on getting a Google API key:

Othe references:


Use OCR to extract title from pdf papers; rename file with related info


Language:Jupyter Notebook 65.9%Language:Python 34.1%