ocr.page
Give the text of a PDF page with the box of each line and word: the text layer first, then OCR for a page with no text layer
CLI- Package
- @procedures/ocr · README
- Path
["ocr","page"]- CLI
mark ocr page --file <string>- As data
{"$proc":["ocr","page"],"input":{}}
Use it
In TypeScript
import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/ocr/register"; // registers its procedures
const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["ocr","page"], { file: "<file>" });
console.log(JSON.stringify(result));From the command line
$ mark ocr page --file <string>
As data, in a program
{ "$proc": ["ocr", "page"], "input": { "file": "<file>" } }Input
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
file | string | yes | The path of the PDF file | |
page | integer | no | The number of the page, from 1 (default: 1) | |
mode | "auto" | "text" | "ocr" | no | auto: the text layer, else OCR. text: only the text layer. ocr: always OCR (default: auto) | |
dpi | integer | no | The resolution of the image of the page for OCR, in dots per inch (default: 300) | |
language | string | no | The language of the text (default: eng) | |
psm | integer | no | The page segmentation mode of tesseract, from 0 to 13 | |
timeout | integer | no | The time limit of each program, in milliseconds (default: 120000) | |
upright | boolean | no | When true, OCR finds the orientation of the page first, and the boxes are in the frame of the upright page (default: false) |
Output
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
page | number | yes | The number of the page | |
source | "text-layer" | "ocr" | yes | Where the text comes from: the text layer, or OCR of an image of the page | |
engine | string | no | The OCR engine, when the source is ocr | |
orientation | object | no | The orientation that OCR found, when the input has upright and the source is ocr | |
unit | "px" | "pt" | yes | The unit of the boxes: px is a pixel of the image, pt is a point of the PDF page | |
width | number | yes | The width of the page or of the image | |
height | number | yes | The height of the page or of the image | |
text | string | yes | The text of the lines, with one line end between each two lines | |
confidence | number | yes | The mean confidence of all words, from 0 to 1 | |
lines | object[] | yes |
JSON Schemas
{
"input": {
"type": "object",
"properties": {
"file": {
"type": "string",
"minLength": 1,
"description": "The path of the PDF file"
},
"page": {
"description": "The number of the page, from 1 (default: 1)",
"type": "integer",
"minimum": 1,
"maximum": 9007199254740991
},
"mode": {
"description": "auto: the text layer, else OCR. text: only the text layer. ocr: always OCR (default: auto)",
"type": "string",
"enum": [
"auto",
"text",
"ocr"
]
},
"dpi": {
"description": "The resolution of the image of the page for OCR, in dots per inch (default: 300)",
"type": "integer",
"minimum": 72,
"maximum": 1200
},
"language": {
"description": "The language of the text (default: eng)",
"type": "string",
"pattern": "^[A-Za-z0-9_][A-Za-z0-9_/]*(\\+[A-Za-z0-9_][A-Za-z0-9_/]*)*$"
},
"psm": {
"description": "The page segmentation mode of tesseract, from 0 to 13",
"type": "integer",
"minimum": 0,
"maximum": 13
},
"timeout": {
"description": "The time limit of each program, in milliseconds (default: 120000)",
"type": "integer",
"exclusiveMinimum": 0,
"maximum": 9007199254740991
},
"upright": {
"description": "When true, OCR finds the orientation of the page first, and the boxes are in the frame of the upright page (default: false)",
"type": "boolean"
}
},
"required": [
"file"
]
},
"output": {
"type": "object",
"properties": {
"page": {
"type": "number",
"description": "The number of the page"
},
"source": {
"type": "string",
"enum": [
"text-layer",
"ocr"
],
"description": "Where the text comes from: the text layer, or OCR of an image of the page"
},
"engine": {
"description": "The OCR engine, when the source is ocr",
"type": "string"
},
"orientation": {
"description": "The orientation that OCR found, when the input has upright and the source is ocr",
"type": "object",
"properties": {
"turn": {
"anyOf": [
{
"type": "number",
"const": 0
},
{
"type": "number",
"const": 90
},
{
"type": "number",
"const": 180
},
{
"type": "number",
"const": 270
}
],
"description": "The turn in the clock direction that makes the page upright, in degrees"
},
"confidence": {
"type": "number",
"minimum": 0,
"description": "The confidence of the engine in the turn. For tesseract, a value below 2 is weak"
}
},
"required": [
"turn",
"confidence"
],
"additionalProperties": false
},
"unit": {
"type": "string",
"enum": [
"px",
"pt"
],
"description": "The unit of the boxes: px is a pixel of the image, pt is a point of the PDF page"
},
"width": {
"type": "number",
"description": "The width of the page or of the image"
},
"height": {
"type": "number",
"description": "The height of the page or of the image"
},
"text": {
"type": "string",
"description": "The text of the lines, with one line end between each two lines"
},
"confidence": {
"type": "number",
"minimum": 0,
"maximum": 1,
"description": "The mean confidence of all words, from 0 to 1"
},
"lines": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "The words of the line, with one space between each two words"
},
"confidence": {
"type": "number",
"minimum": 0,
"maximum": 1,
"description": "The mean confidence of the words, from 0 to 1"
},
"box": {
"type": "object",
"properties": {
"x": {
"type": "number",
"description": "The left side of the box"
},
"y": {
"type": "number",
"description": "The top side of the box (the y axis points down)"
},
"w": {
"type": "number",
"description": "The width of the box"
},
"h": {
"type": "number",
"description": "The height of the box"
}
},
"required": [
"x",
"y",
"w",
"h"
],
"additionalProperties": false
},
"words": {
"type": "array",
"items": {
"type": "object",
"properties": {
"text": {
"type": "string",
"description": "The text of the word"
},
"confidence": {
"type": "number",
"minimum": 0,
"maximum": 1,
"description": "The confidence, from 0 to 1"
},
"box": {
"type": "object",
"properties": {
"x": {
"type": "number",
"description": "The left side of the box"
},
"y": {
"type": "number",
"description": "The top side of the box (the y axis points down)"
},
"w": {
"type": "number",
"description": "The width of the box"
},
"h": {
"type": "number",
"description": "The height of the box"
}
},
"required": [
"x",
"y",
"w",
"h"
],
"additionalProperties": false
}
},
"required": [
"text",
"confidence",
"box"
],
"additionalProperties": false
}
}
},
"required": [
"text",
"confidence",
"box",
"words"
],
"additionalProperties": false
}
}
},
"required": [
"page",
"source",
"unit",
"width",
"height",
"text",
"confidence",
"lines"
],
"additionalProperties": false
}
}