From 0089a84c9421ed839769ac3a855ad6ba449f73a3 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Tue, 13 Mar 2018 14:51:47 -0700 Subject: [PATCH] hocr: Make interword spaces default and non-optional for hocr Update documentation to match. --- docs/advanced.rst | 13 ------------- docs/introduction.rst | 4 ++-- docs/release_notes.rst | 8 -------- ocrmypdf/__main__.py | 9 +-------- ocrmypdf/pipeline.py | 4 ++-- 5 files changed, 5 insertions(+), 33 deletions(-) diff --git a/docs/advanced.rst b/docs/advanced.rst index 47a810e7..e86cfd3c 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -131,8 +131,6 @@ The ``hocr`` renderer The ``hocr`` renderer works with older versions of Tesseract. The image layer is copied from the original PDF page if possible, avoiding potentially lossy transcoding or loss of other PDF information. If preprocessing is specified, then the image layer is a new PDF. -When combined with an additional option ``--interword-spaces`, this renderer will append a space at the end of each recognized text element to help simpler viewers such as PDF.js correctly recognize words for search and copy and paste operations. - This works in all versions of Tesseract. The ``tesseract`` renderer @@ -143,14 +141,3 @@ The ``tesseract`` renderer creates a PDF with the image and text layers precompo If a PDF created with this renderer using Tesseract versions older than 3.05.00 is then passed through Ghostscript's pdfwrite feature, the OCR text *may* be corrupted. The ``--output-type=pdfa`` argument will produce a warning in this situation. *This renderer is deprecated and will be removed whenever support for older versions of Tesseract is dropped.* - -Adding Interword Spaces -------------------------- - -OCRmyPDF has an option ``--interword-spaces`` that appends a space at the end of each text element. Without the space, simpler PDF viewers such as PDF.js have difficulty detecting individuals words and maintaining white space between them. As a result, searching for multi-word phrases and selecting text for copy and paste are severely impacted. With this option set, these viewers are able to locate multi-word phrases while more advanced viewers remain unaffected. - -.. code-block:: bash - - ocrmypdf --output-type pdf --interword-spaces --pdf-renderer hocr input.pdf output.pdf - -This option defaults to ``False`` and must be combined with ``--pdf-renderer hocr`` or it will be ignored with a warning. This works in all versions of Tesseract. diff --git a/docs/introduction.rst b/docs/introduction.rst index 8264b001..1e36c5a2 100644 --- a/docs/introduction.rst +++ b/docs/introduction.rst @@ -82,8 +82,8 @@ OCRmyPDF is limited by the Tesseract OCR engine. As such it experiences these l OCRmyPDF is also limited by the PDF specification: -* PDF encodes the position of text glyphs but does not encode document structure. There is no markup that divides a document in sections, paragraphs, sentences, or even words (since blank spaces are not represented). As such all elements of document structure including the spaces between words must be derived heuristically. Some PDF viewers do a better job of this than others. -* Because some popular opensource PDF viewers have a particularly hard time with spaces betweem words, OCRmyPDF does provide an optional command option ``--interword-spaces`` that appends a space to each text element as a workaround, but discourages its use unless absolutely necessary as it mixes document structure with graphical information that ideally should be left to the PDF viewer to interpret. This option produces output similar to the aptly named ``-sloppy-text`` option of pdfsandwich mentioned in the Similar Programs section below. +* PDF encodes the position of text glyphs but does not encode document structure. There is no markup that divides a document in sections, paragraphs, sentences, or even words (since blank spaces are not represented). As such all elements of document structure including the spaces between words must be derived heuristically. Some PDF viewers do a better job of this than others. +* Because some popular open source PDF viewers have a particularly hard time with spaces betweem words, OCRmyPDF appends a space to each text element as a workaround. While this mixes document structure with graphical information that ideally should be left to the PDF viewer to interpret, it improves compatibility with some viewers and does not cause problems for better ones. Ghostscript also imposes some limitations: diff --git a/docs/release_notes.rst b/docs/release_notes.rst index fc3b0054..41bc1972 100644 --- a/docs/release_notes.rst +++ b/docs/release_notes.rst @@ -5,14 +5,6 @@ OCRmyPDF uses `semantic versioning `_ for its command line i The OCRmyPDF package itself does not contain a public API, although it is fairly stable and breaking changes are usually timed with a major release. A future release will clearly define the stable public API. -next ----- - -- Fix issue #219: change how the final output file is created to avoid triggering permission errors when the output is a special file such as ``/dev/null`` -- The "encrypted PDF" error message was different depending on the type of PDF encryption. Now a single clear message appears for all types of PDF encryption. -- ocrmypdf is now in Homebrew. Homebrew users are advised to the version of ocrmypdf in the official homebrew-core formulas rather than the private tap. -- Some linting - v5.6.0 ------ diff --git a/ocrmypdf/__main__.py b/ocrmypdf/__main__.py index 9e33e0c5..94412453 100755 --- a/ocrmypdf/__main__.py +++ b/ocrmypdf/__main__.py @@ -304,9 +304,6 @@ advanced.add_argument( advanced.add_argument( '--user-patterns', metavar='FILE', help="Specify the location of the Tesseract user patterns file.") -advanced.add_argument( - '--interword-spaces', action='store_true', - help="Add spaces between words with HOCR transformation.") debugging = parser.add_argument_group( "Debugging", @@ -466,11 +463,7 @@ def check_options_advanced(options, log): "--pdfa-image-compression argument has no effect when " "--output-type is not 'pdfa', 'pdfa-1', or 'pdfa-2'" ) - if options.interword_spaces and options.pdf_renderer != 'hocr': - log.warning( - "--interword-spaces argument has no effect when " - "--pdf-renderer is not 'hocr'" - ) + def check_options_metadata(options, log): import unicodedata diff --git a/ocrmypdf/pipeline.py b/ocrmypdf/pipeline.py index 60073312..36981729 100644 --- a/ocrmypdf/pipeline.py +++ b/ocrmypdf/pipeline.py @@ -641,7 +641,7 @@ def render_hocr_page( hocrtransform = HocrTransform(hocr, dpi) hocrtransform.to_pdf(output_file, imageFileName=None, showBoundingboxes=False, invisibleText=True, - interwordSpaces=options.interword_spaces) + interwordSpaces=True) def flatten_groups(groups): for obj in groups: @@ -666,7 +666,7 @@ def render_hocr_debug_page( hocrtransform = HocrTransform(hocr, dpi) hocrtransform.to_pdf(output_file, imageFileName=None, showBoundingboxes=True, invisibleText=False, - interwordSpaces=options.interword_spaces) + interwordSpaces=True) def combine_layers( infiles,