From 9af59c0d6d47e6c5716f25278dc60564c4dfe836 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Mon, 9 Dec 2019 21:39:01 -0800 Subject: [PATCH] docs: improvements for Windows --- docs/batch.rst | 22 ++++++++++++++-------- docs/index.rst | 4 +++- docs/languages.rst | 5 +++++ docs/optimizer.rst | 4 ++++ setup.py | 1 + 5 files changed, 27 insertions(+), 9 deletions(-) diff --git a/docs/batch.rst b/docs/batch.rst index e3fe9920..73d512bf 100644 --- a/docs/batch.rst +++ b/docs/batch.rst @@ -57,6 +57,12 @@ of ``ocrmypdf``, again updating files in place. find . -name '*.pdf' | parallel --tag -j 2 ocrmypdf '{}' '{}' +In a Windows batch file, use + +.. code-block:: bat + + for /r %%f in (*.pdf) do ocrmypdf %%f %%f + Sample script ------------- @@ -67,13 +73,15 @@ processing. #!/usr/bin/env python3 # Walk through directory tree, replacing all files with OCR'd version - # Contributed by DeliciousPickle@github + # Original version by DeliciousPickle@github; modified import logging import os import subprocess import sys + import ocrmypdf + script_dir = os.path.dirname(os.path.realpath(__file__)) print(script_dir + '/ocr-tree.py: Start') @@ -91,6 +99,8 @@ processing. level=logging.INFO, format='%(asctime)s %(message)s', filename=log_file, filemode='w') + ocrmypdf.configure_logging(ocrmypdf.Verbosity.default) + for dir_name, subdirs, file_list in os.walk(start_dir): logging.info('\n') logging.info(dir_name + '\n') @@ -100,14 +110,10 @@ processing. if file_ext == '.pdf': full_path = dir_name + '/' + filename print(full_path) - cmd = ["ocrmypdf", "--deskew", filename, filename] - logging.info(cmd) - proc = subprocess.run( - cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) - result = proc.stdout - if proc.returncode == 6: + result = ocrmypdf.ocr(filename, filename, deskew=True) + if result == ocrmypdf.ExitCode.already_done_ocr: print("Skipped document because it already contained text") - elif proc.returncode == 0: + elif result == ocrmypdf.ExitCode.ok: print("OCR complete") logging.info(result) diff --git a/docs/index.rst b/docs/index.rst index c3759efb..3f611f9d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -4,7 +4,9 @@ OCRmyPDF documentation OCRmyPDF adds an OCR text layer to scanned PDF files, allowing them to be searched. -PDF is the best format for storing and exchanging scanned documents. Unfortunately, PDFs can be difficult to modify. OCRmyPDF makes it easy to apply image processing and OCR to existing PDFs. +PDF is the best format for storing and exchanging scanned documents. +Unfortunately, PDFs can be difficult to modify. OCRmyPDF makes it easy to apply +image processing and OCR to existing PDFs. .. toctree:: :maxdepth: 1 diff --git a/docs/languages.rst b/docs/languages.rst index 2b26b6de..811dd06f 100644 --- a/docs/languages.rst +++ b/docs/languages.rst @@ -57,3 +57,8 @@ Docker users Users of the OCRmyPDF Docker image should install language packs into a derived Docker image as :ref:`described in that section `. + +Windows users +============= + +The Tesseract installer provided by Chocolatey already includes 100 languages. diff --git a/docs/optimizer.rst b/docs/optimizer.rst index f6336f77..02f0be21 100644 --- a/docs/optimizer.rst +++ b/docs/optimizer.rst @@ -14,6 +14,10 @@ optimization and ``3`` implements all options. ``1``, the default, performs only safe and lossless optimizations. (This is similar to GCC's optimization parameter.) The exact type of optimizations performed will vary over time. +PDF optimization requires third-party, optional tools for certain optimizations. +If these are not installed or cannot be found by OCRmyPDF, optimization will not +be as good. + Optimizations that always occurs ================================ diff --git a/setup.py b/setup.py index 7e0302eb..214bc62f 100644 --- a/setup.py +++ b/setup.py @@ -76,6 +76,7 @@ setup( "Intended Audience :: System Administrators", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: MacOS :: MacOS X", + "Operating System :: Microsoft :: Windows :: Windows 10", "Operating System :: POSIX", "Operating System :: POSIX :: BSD", "Operating System :: POSIX :: Linux",