Skip to content

Latest commit

 

History

History
48 lines (32 loc) · 1.29 KB

File metadata and controls

48 lines (32 loc) · 1.29 KB

OCR: optical character recognition

OCR is the automated process of turning images into text.

This package contains open-source tools to help recreate searchable databases.

I use Poppler to convert PDFs to images, then I use Tesseract to convert images to text.

Setup

  1. Install Tesseract
  2. If using PDFs, install Poppler

Usage

If you're not using a PDF, skip to the section on images.

  1. Download the PDF you want to run OCR on

  2. Convert the PDF to a series of images (one per PDF page):

    pdftoppm -png input.pdf output_prefix

    This command does not print progress, see enhancements for a version of this command that does print progress

  3. Convert the images to a series of plaintext files:

    find /path/to/images -name "*.png" -exec sh -c 'tesseract "$1" "$1.out" && echo "Done: $1"' _ {} \;

Enhancements

For progress when converting the PDF to a series of images, consider a loop:

n=$(pdfinfo input.pdf | grep Pages | awk '{print $2}')
for i in $(seq 1 $n); do
  pdftoppm -png -f $i -l $i input.pdf page
  echo "Converted page $i of $n"
done