Selectively OCRs pages. This preprocessor is useful when a PDF contains both embedded text and text images. Selectively OCRing the pages containing text images, rather than the entire document, improves performance. Examples of text images include handwriting and scanned text.

If the whole document is a scan or image file, you don't need to configure this preprocessor. In that case, Sensible automatically OCRs the whole document.

Parameters

keyvaluedescription
type (required)ocr
match (required unless you specify Page Lines Limit parameter)Match objectThe text relative to which you define the page number to OCR. For example, if you know that the page after the heading "Policy Addendums" is always a scanned image, then you specify:
"type": "ocr",
"match": "policy addendums",
"pageOffset": 1
If there are multiple text matches in the document, matches the first. To specify a second or later match, use a Match array.
To OCR a single page offset from the first page of the document, rather than offset from matched text, specify "match": { "type": "first" }.
matchAllbooleanIf true, OCRs all pages containing the line specified by the Match parameter.
pageLinesLimitintegerPerforms OCR on all pages containing the specified number of embedded text lines or fewer. Use this parameter to OCR pages for which no reliable text anchors exist. Sensible recommends specifying a small number relative to the typical number of page lines in the document type, since pages with a small number of embedded lines more likely contain text images. Sensible verifies the qualifying pages contain images before perform OCR, to avoid processing blank pages.
If you specify this in combination with a Match parameter, Sensible OCR all pages that meets any of the match criteria or the number of page lines criteria.
pageOffsetnumber. default: 0The zero-indexed number of the page to OCR, counting from the page number of the text matched by the Match parameter.
engineamazon,
google,
microsoft,
lazarus,
default: amazon
Specifies the OCR engine for this preprocessor. This preprocessor overrides the document type's OCR engine for this config.
- Amazon is the default engine for this preprocessor.
- Microsoft is suited to typewritten documents and large documents up to 50 MB in size. Microsoft is the default document type for document types.
- Lazarus is faster than Microsoft and produces similar output.
- Google is faster than Microsoft and suited to handwriting and short documents (25 pages or under). The Google engine doesn't merge words into lines automatically. Use the Merge Lines preprocessor in your configurations to do so.

Examples

The following config specifies to apply OCR processing to specific pages. The config then outputs all lines of the document ("id": "all_lines_in_doc"), to double check that OCR extracted the text on those pages.

{
  "preprocessors": [
    {
      /* OCR first page of document */
      "type": "ocr",
      "match": { "type": "first" },
    },
    {
      /* OCR fourth page of document */
      "type": "ocr",
      "match": { "type": "first" },
      "pageOffset": 3
    },
    {
      /* OCR all pages containing text 'additional riders'  */
      "type": "ocr",
      "match": "additional riders",
      "matchAll": true,
    },  
      
  ],
  "fields": [
     
    {
      /* check OCR output */
      "id": "all_lines_in_doc",
      "method": {
        "id": "documentRange",
        "includeAnchor": true
      },
      "anchor": {
        "match": {
          "type":"first"
        }
      }
    }
  ],
}