Selectively OCRs pages. This preprocessor is useful when a PDF has some pages that contain embedded text, and other pages that contain images of text or handwriting. Selectively OCRing the pages containing text images, rather than the entire document, improves performance.

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 an array of Match objects.
To OCR a single page offset from the first page of the document, rather than offset from matched text, specify "match": { "type": "first" }.
pageOffset (required)numberThe zero-indexed number of the page to OCR, counting from the page number of the text matched by the Match parameter.
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.

Examples

The following config specifies to apply OCR processing:

  • to the first page of the document ("pageOffset": 0)
  • to the fourth page of the document ("pageOffset": 3)
  • to whichever page the text "additional riders" occurs on ("match": "additional riders")

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": [
    {
      "type": "ocr",
      "match": { "type": "first" },
      "pageOffset": 0
    },
    {
      "type": "ocr",
      "match": { "type": "first" },
      "pageOffset": 3
    },
    {
      "type": "ocr",
      "match": "additional riders",
      "pageOffset": 0
    },  
      
  ],
  "fields": [
     
    {
      "id": "all_lines_in_doc",
      "method": {
        "id": "documentRange",
        "includeAnchor": true
      },
      "anchor": {
        "match": {
          "type":"first"
        }
      }
    }
  ],
}