DOKK / manpages / debian 12 / ocrmypdf / ocrmypdf.1.en
OCRMYPDF(1) User Commands OCRMYPDF(1)

ocrmypdf - add an OCR text layer to PDF files

usage: ocrmypdf [-h] [-l LANGUAGE] [--image-dpi DPI]

[--output-type {pdfa,pdf,pdfa-1,pdfa-2,pdfa-3}] [--sidecar [FILE]] [--version] [-j N] [-q] [-v [VERBOSE]] [--title TITLE] [--author AUTHOR] [--subject SUBJECT] [--keywords KEYWORDS] [-r] [--remove-background] [-d] [-c] [-i] [--oversample DPI] [--remove-vectors] [--mask-barcodes] [--threshold] [-f] [-s] [--redo-ocr] [--skip-big MPixels] [-O {0,1,2,3}] [--jpeg-quality Q] [--png-quality Q] [--jbig2-lossy] [--max-image-mpixels MPixels] [--tesseract-config CFG] [--tesseract-pagesegmode PSM] [--tesseract-oem MODE] [--pdf-renderer {auto,hocr,sandwich}] [--tesseract-timeout SECONDS] [--rotate-pages-threshold CONFIDENCE] [--pdfa-image-compression {auto,jpeg,lossless}] [--user-words FILE] [--user-patterns FILE] [-k] [--flowchart FLOWCHART] input_pdf_or_image output_pdf

Generates a searchable PDF or PDF/A from a regular PDF.

OCRmyPDF rasterizes each page of the input PDF, optionally corrects page rotation and performs image processing, runs the Tesseract OCR engine on the image, and then creates a PDF from the OCR information.

PDF file containing the images to be OCRed (or '-' to read from standard input)
Output searchable PDF file (or '-' to write to standard output). Existing files will be ovewritten. If same as input file, the input file will be updated only if processing is successful.

show this help message and exit
Language(s) of the file to be OCRed (see tesseract --list-langs for all language packs installed in your system). Use -l eng+deu for multiple languages.
For input image instead of PDF, use this DPI instead of file's.
Choose output type. 'pdfa' creates a PDF/A-2b compliant file for long term archiving (default, recommended) but may not suitable for users who want their file altered as little as possible. 'pdfa' also has problems with full Unicode text. 'pdf' attempts to preserve file contents as much as possible. 'pdf-a1' creates a PDF/A1-b file. 'pdf-a2' is equivalent to 'pdfa'. 'pdf-a3' creates a PDF/A3-b file.
Generate sidecar text files that contain the same text recognized by Tesseract. This may be useful for building a OCR text database. If FILE is omitted, the sidecar file be named {output_file}.txt If FILE is set to '-', the sidecar is written to stdout (a convenient way to preview OCR quality). The output file and sidecar may not both use stdout at the same time.
Print program version and exit

Use up to N CPU cores simultaneously (default: use all).
Suppress INFO messages
Print more verbose messages for each additional verbose level

Set output PDF/A metadata (default: copy input document's metadata)
Set document title (place multiple words in quotes)
Set document author
Set document subject description
Set document keywords

Options to improve the quality of the final PDF and OCR
Automatically rotate pages based on detected text orientation
Attempt to remove background from gray or color pages, setting it to white
Deskew each page before performing OCR
Clean pages from scanning artifacts before performing OCR, and send the cleaned page to OCR, but do not include the cleaned page in the output
Clean page as above, and incorporate the cleaned image in the final PDF. Might remove desired content.
Oversample images to at least the specified DPI, to improve OCR results slightly
EXPERIMENTAL. Mask out any vector objects in the PDF so that they will not be included in OCR. This can eliminate false characters.
EXPERIMENTAL. Mask out any barcodes that appear in the PDF so they are not considered during OCR. Barcodes can introduce false characters into OCR.
EXPERIMENTAL. Threshold image to 1bpp before sending it to Tesseract for OCR. Can improve OCR quality compared to Tesseract's thresholder.

Control how OCR is applied
Rasterize any text or vector objects on each page, apply OCR, and save the rastered output (this rewrites the PDF)
Skip OCR on any pages that already contain text, but include the page in final output; useful for PDFs that contain a mix of images, text pages, and/or previously OCRed pages
Attempt to detect and remove the hidden OCR layer from files that were previously OCRed with OCRmyPDF or another program. Apply OCR to text found in raster images. Existing visible text objects will not be changed. If there is no existing OCR, OCR will be added.
Skip OCR on pages larger than the specified amount of megapixels, but include skipped pages in final output

Control how the PDF is optimized after OCR
Control how PDF is optimized after processing:0 - do not optimize; 1 - do safe, lossless optimizations (default); 2 - do some lossy optimizations; 3 - do aggressive lossy optimizations (including lossy JBIG2)
Adjust JPEG quality level for JPEG optimization. 100 is best quality and largest output size; 1 is lowest quality and smallest output; 0 uses the default.
Adjust PNG quality level to use when quantizing PNGs. Values have same meaning as with --jpeg-quality
Enable JBIG2 lossy mode (better compression, not suitable for some use cases - see documentation).

Advanced options to control Tesseract's OCR behavior
Set maximum number of pixels to unpack before treating an image as a decompression bomb
Additional Tesseract configuration files -- see documentation
Set Tesseract page segmentation mode (see tesseract --help)
Set Tesseract 4.0 OCR engine mode: 0 - original Tesseract only; 1 - neural nets LSTM only; 2 - Tesseract + LSTM; 3 - default.
Choose OCR PDF renderer - the default option is to let OCRmyPDF choose. See documentation for discussion.
Give up on OCR after the timeout, but copy the preprocessed page into the final output
Only rotate pages when confidence is above this value (arbitrary units reported by tesseract)
Specify how to compress images in the output PDF/A. 'auto' lets OCRmyPDF decide. 'jpeg' changes all grayscale and color images to JPEG compression. 'lossless' uses PNG-style lossless compression for all images. Monochrome images are always compressed using a lossless codec. Compression settings are applied to all pages, including those for which OCR was skipped. Not supported for --output-type=pdf ; that setting preserves the original compression of all images.
Specify the location of the Tesseract user words file. This is a list of words Tesseract should consider while performing OCR in addition to its standard language dictionaries. This can improve OCR quality especially for specialized and technical documents.
Specify the location of the Tesseract user patterns file.

Arguments to help with troubleshooting and debugging
Keep temporary files (helpful for debugging)
Generate the pipeline execution flowchart

OCRmyPDF attempts to keep the output file at about the same size. If a file contains losslessly compressed images, and output file will be losslessly compressed as well.

PDF is a page description file that attempts to preserve a layout exactly. A PDF can contain vector objects (such as text or lines) and raster objects (images). A page might have multiple images. OCRmyPDF is prepared to deal with the wide variety of PDFs that exist in the wild.

When a PDF page contains text, OCRmyPDF assumes that the page has already been OCRed or is a "born digital" page that should not be OCRed. The default behavior is to exit in this case without producing a file. You can use the option --skip-text to ignore pages with text, or --force-ocr to rasterize all objects on the page and produce an image-only PDF as output.

ocrmypdf --skip-text file_with_some_text_pages.pdf output.pdf
ocrmypdf --force-ocr word_document.pdf output.pdf

If you are concerned about long-term archiving of PDFs, use the default option --output-type pdfa which converts the PDF to a standardized PDF/A-2b. This converts images to sRGB colorspace, removes some features from the PDF such as Javascript or forms. If you want to minimize the number of changes made to your PDF, use --output-type pdf.

If OCRmyPDF is given an image file as input, it will attempt to convert the image to a PDF before processing. For more control over the conversion of images to PDF, use img2pdf, or other image to PDF software.

For example, this command uses img2pdf to convert all .png files beginning with the 'page' prefix to a PDF, fitting each image on A4-sized paper, and sending the result to OCRmyPDF through a pipe.

img2pdf --pagesize A4 page*.png | ocrmypdf - myfile.pdf

/usr/share/doc/ocrmypdf/html/index.html

after installing the ocrmypdf-doc package.

January 2019 ocrmypdf 8.0.0+dfsg