hocr: Make interword spaces default and non-optional for hocr

Update documentation to match.
This commit is contained in:
James R. Barlow
2018-03-13 14:51:47 -07:00
parent 90676e1c6a
commit 0089a84c94
5 changed files with 5 additions and 33 deletions
-13
View File
@@ -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.
+2 -2
View File
@@ -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:
-8
View File
@@ -5,14 +5,6 @@ OCRmyPDF uses `semantic versioning <http://semver.org/>`_ 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
------
+1 -8
View File
@@ -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
+2 -2
View File
@@ -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,