Flatbed scan a book and process it into a PDF
A flatbed scanner is a commonly found piece of equipment that can be used to scan a book, essentially making a sequence of images from its pages. These scripts, written by Pedro Sá Couto do further work of processing the scans to produce a PDF with a selectable text layer.
brew (MAC) or apt-get (LINUX)
You’ll need the command-line tools for Xcode installed.
After, install homebrew:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Run the following command once you’re done to ensure homebrew is installed and working properly:
sudo apt-get install python3 python3-pip imagemagick poppler pdfunite
brew install python3 python3-pip imagemagick poppler pdfunite
Install all necessary packages with pip3:
sudo pip3 install pdf2image Pillow time logging opencv-python pytesseract
How to use the scripts
Your scans must look like this for the scripts to perform correctly.
RIGHT PAGE ————————————————————— | | |—————————— | | | | | | | | | | | | | | | | | 01 | | |—————————— | | | ————————————————————— LEFT PAGE RIGHT PAGE ————————————————————— ————————————————————— | | | | | ——————————| |—————————— | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 02 | | 03 | | | —————————— | |—————————— | | | | | ————————————————————— —————————————————————
Add your pictures from the book scanner to the folder "/scans"
Make all the files executable:
sudo chmod 777 merge_scans.sh workshop_stream.sh marge_files.sh
In case you want to skip any of the scripts just comment out in the shell code, workshop_stream.sh.
The workflow follows these scripts, in successive order:
Create 3 directories
mkdir split mkdir ocred mkdir cropped
Merge the files in the directory scans
All the scans will be appended to one pdf called out.pdf
Burst the pdf in scans
Burst this pdf, renaming all the files so they can be iterated later.
Cropping the bounding boxes
The pages are now in their original position, but they have a bounding box. This script iterates through them and crops the highest contrast area found.
OCR (Optical Character Recognition)
In this part we OCR the jpg, turning these into PDFs.
Merge all the files and create the pdf
The OCRed pages are now joined into their final PDF, your book is ready :)
The package is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).