Package: pypdfocr
PyPDFOCR - Tesseract-OCR based PDF filingThis program will help manage your scanned PDFs by doing the following:Take a scanned PDF file and run OCR on it (using the Tesseract OCR
software from Google), generating a searchable PDFOptionally, watch a folder for incoming scanned PDFs and
automatically run OCR on themOptionally, file the scanned PDFs into directories based on simple
keyword matching that you specifyEvernote auto-upload and filing based on keyword searchEmail status when it files your PDFMore links:Blog @ virantha.comDocumentation @ gitpagesSource @ githubUsage:Single conversion:pypdfocr filename.pdf

--> filename_ocr.pdf will be generatedIf you have a language pack installed, then you can specify it with the-loption:pypdfocr -l spa filename.pdfFolder monitoring:pypdfocr -w watch_directory

--> Every time a pdf file is added to `watch_directory` it will be OCR'edAutomatic filing:To automatically move the OCR’ed pdf to a directory based on a keyword,
use the -f option and specify a configuration file (described below):pypdfocr filename.pdf -f -c config.yamlYou can also do this in folder monitoring mode:pypdfocr -w watch_directory -f -c config.yamlFiling based on filename match:If no keywords match the contents of the filename, you can optionally
allow it to fallback to trying to find keyword matches with the PDF
filename using the -n option. For example, you may have receipts always
named asreceipt_2013_12_2.pdfby your scanner, and you want to move
this to a folder called ‘receipts’. Assuming you have a keywordreceiptmatching to folderreceiptsin your configuration file
as described below, you can run the following and have this filed even
if the content of the pdf does not contain the text ‘receipt’:pypdfocr filename.pdf -f -c config.yaml -nConfiguration file for automatic PDF filingThe config.yaml file above is a simple folder to keyword matching text
file. It determines where your OCR’ed PDFs (and optionally, the original
scanned PDF) are placed after processing. An example is given below:target_folder: "docs/filed"
default_folder: "docs/filed/manual_sort"
original_move_folder: "docs/originals"

folders:
    finances:
        - american express
        - chase card
        - internal revenue service
    travel:
        - boarding pass
        - airlines
        - expedia
        - orbitz
    receipts:
        - receiptThetarget_folderis the root of your filing cabinet. Any PDF moving
will happen in sub-directories under this directory.Thefolderssection defines your filing directories and the keywords
associated with them. In this example, we have three filing directories
(finances, travl, receipts), and some associated keywords for each
filing directory. For example, if your OCR’ed PDF contains the phrase
“american express” (in any upper/lower case), it will be filed intodocs/filed/financesThedefault_folderis where the OCR’ed PDF is moved to if there is
no keyword match.Theoriginal_move_folderis optional (you can comment it out with#in front of that line), but if specified, the original scanned PDF
is moved into this directory after OCR is done. Otherwise, if this field
is not present or commented out, your original PDF will stay where it
was found.If there is any naming conflict during filing, the program will add an
underscore followed by a number to each filename, in order to avoid
overwriting files that may already be present.Evernote upload:Evernote authentication tokenTo enable Evernote support, you will need toget a developer token for
your Evernote
account.. You
should note that this script will never delete or modify existing notes
in your account, and limits itself to creating new Notebooks and Notes.
Once you get that token, you copy and paste it into your configuration
file as shown belowEvernote filing usageTo automatically upload the OCR’ed pdf to a folder based on a keyword,
use the-eoption instead of the-fauto filing option.pypdfocr filename.pdf -e -c config.yamlSimilarly, you can also do this in folder monitoring mode:pypdfocr -w watch_directory -e -c config.yamlEvernote filing configuration fileThe config file shown above only needs to change slightly. The folders
section is completely unchanged, but note thattarget_folderis the
name of your “Notebook stack” in Evernote, and thedefault_foldershould just be the default Evernote upload notebook name.target_folder: "evernote_stack"
default_folder: "default"
original_move_folder: "docs/originals"
evernote_developer_token: "YOUR_TOKEN"

folders:
    finances:
        - american express
        - chase card
        - internal revenue service
    travel:
        - boarding pass
        - airlines
        - expedia
        - orbitz
    receipts:
        - receiptAuto emailYou can have PyPDFOCR email you everytime it converts a file and files
it. You need to first specify the following lines in the configuration
file and then use the-moption when invokingpypdfocr:mail_smtp_server: "smtp.gmail.com:587"
mail_smtp_login: "virantha@gmail.com"
mail_smtp_password: "PASSWORD"
mail_from_addr: "virantha@gmail.com"
mail_to_list:
    - "virantha@gmail.com"
    - "person2@gmail.com"Advanced optionsFine-tuning Tesseract/Ghostscript/othersYou can specify Tesseract and Ghostscript executable locations manually, as
well as the number of concurrent processes allowed during preprocessing and
tesseract.  Use the following in your configuration file:tesseract:
    binary: "/usr/bin/tesseract"
    threads: 8

ghostscript:
    binary: "/usr/local/bin/gs"

preprocess:
    threads: 8Handling disk time-outsIf you need to increase the time interval (default 3 seconds) between new
document scans when pypdfocr is watching a directory, you can specify the following
option in the configuration file:watch:
    scan_interval: 6InstallationUsing pipPyPDFOCR is available in PyPI, so you can just run:pip install pypdfocrPlease note that some of the 3rd-party libraries required by PyPDFOCR wiill
require some build tools, especially on a default Ubuntu system.  If you run
into any issues using pip install, you may want to install the
following packages on Ubuntu and try again:gcclibjpeg-devzlib-binzlib1g-devpython-devFor those onWindows, because it’s such a pain to get all the PIL
and PDF dependencies installed, I’ve gone ahead and made an executable
calledpypdfocr.exeYou still need to install Tesseract, GhostScript, etc. as detailed below in
the external dependencies list.Manual installClone the source directly from github (you need to have git installed):git clone https://github.com/virantha/pypdfocr.gitThen, install the following third-party python libraries:Pillow (Python Imaging Library)https://pillow.readthedocs.org/en/3.1.x/ReportLab (PDF generation library)http://www.reportlab.com/opensource/Watchdog (Cross-platform fhlesystem events monitoring)https://pypi.python.org/pypi/watchdogPyPDF2 (Pure python pdf library)These can all be installed via pip:pip install Pillow
pip install reportlab
pip install watchdog
pip install pypdf2You will also need to install the external dependencies listed below.External DependenciesPyPDFOCR relies on the following (free) programs being installed and in
the path:Tesseract OCR softwarehttps://code.google.com/p/tesseract-ocr/GhostScripthttp://www.ghostscript.com/ImageMagickhttp://www.imagemagick.org/Popplerhttp://poppler.freedesktop.org/(Windows)Poppler is only required if you want pypdfocr to figure out the original PDF resolution
automatically; just make sure you havepdfimagesin your path.   Note that thexpdfprovidedpdfimagesdoes not work for this,
because it does not support the-listoption to list the table of images in a PDF file.On Mac OS X, you can install these using homebrew:brew install tesseract
brew install ghostscript
brew install poppler
brew install imagemagickOn Windows, please use the installers provided on their download pages.** Important ** Tesseract version 3.02.02 or newer required
(apparently 3.02.01-6 and possibly others do not work due to a hocr
output format change that I’m not planning to address). On Ubuntu, you
may need to compile and install it manually by followingthese
instructionsAlso note that if you want Tesseract to recognize rotated documents (upside down, or rotated 90 degrees)
then you need to find your tessdata directory and do the following:cd /usr/local/share/tessdata
cp eng.traineddata osd.traineddataosdstands for Orientation and Script Detection, so you need to copy the .traineddata
for whatever language you want to scan in asosd.traineddata.  If you don’t do this step,
then any landscape document will produce garbageDisclaimerWhile test coverage is at 84% right now, Sphinx docs generation is at an
early stage. The software is distributed on an “AS IS” BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.VersionDateChangesv0.9.110/11/16Fixes (#43, #41)v0.9.02/29/16Fixed rotated page text, Mac OS X invisible fonts, and pdf merge slowdownv0.8.52/21/16Better ctrl-c and cleanup behaviorv0.8.42/18/16Maintenance releasev0.8.32/18/16Bug fix for multiprocessing on windows, ctrl-c interrupt, and integer keywordsv0.8.212/8/14Fixed imagemagick invocation on windows.  Parallelized preprocessing and tesseract executionv0.8.112/5/14Added –skip-preprocess option, scan_interval option, and fixed too many open files bug during page overlayv0.8.010/27/14Added preprocessing to clean up prior to tesseract, bug fixes on file names with spaces/dotsv0.7.69/10/14Fixed issue 17 rotation bugv0.7.58/18/14Update for Tesseract 3.03 .hocr filename changev0.7.43/28/14Bug fix on pdf assemblyv0.7.33/27/14Modified internals to use single image per page (instead of multipage tiff). Also enabled orientation detectionv0.7.23/26/14Switched from Pil to Pillow. Now uses original images from PDF in output pdf (no dpi/color/quality changes!)v0.7.13/25/14OCR Language is now an optionv0.7.03/25/14Now honors original pdf resolutionv0.6.12/16/14Bug fix for pdfs with only numbers in the filenamev0.6.01/16/14Added filing based on filename match as fallback, added tesseract version checkv0.5.41/12/14Fixed bug with reordering of text pages on certain platforms(glob)v0.5.312/12/13Fix to evernote server specificationv0.5.212/08/13Fix to lowercase keywordsv0.5.111/02/13Fixed a bunch of windows critical path handling issuesv0.5.010/30/13Email status added, 90% test coveragev0.4.110/28/13Made HOCR parsing more robustv0.4.010/28/13Added early Evernote upload supportv0.3.110/24/13Path fix on windowsv0.3.010/23/13Added filing of converted pdfs using a configuration file to specify target directories based on keyword matches in the pdf textv0.2.210/22/13Added a console script to put the pypdfocr script into your binv0.2.110/22/13Fix to initial packaging problem.v0.2.010/21/13Initial release.Todo list#43 version check for tesseractOn windows, search for pdfimages and imagemagick instead of relying on pathSplit up into flow stepsRun more robustness tests for watching networked sharesAdd more docstringsAdd more option specifiers to tesseract and ghostscript