Ocr
This module can be used for detecting text in images.
Manatee v1.29
This module requires Manatee v1.29.
Extracting text from a PDF file
This functionality can be used to extract text from a PDF file where the regular Pdf
module can’t be used. This is normally the case for scanned PDF files and files generated without embedded character information.
javascript
var ocr = Module.load("Ocr", {version: "vX.Y.Z"});
var result = ocr.readPdf("/Users/robot/Desktop/test.pdf", {lang: "Danish"});
The result
is a OcrResult
JSON object with the following properties:
text
is the extracted text of the complete documentconfidence
is the confidence level of the OCR resultpages
is an array ofOcrPage
objects, one for each page in the PDF, they’ll have the following properties:text
is the extracted textconfidence
is the confidence level of the OCR result for the pagepageNumber
is the page numbertextDirection
is the text direction of the pagepdfText
is the extracted text from the PDF if it is possible to directly extract itbounds
is the bounding box of the text in the pagecontentArea
is the content area of the pagebarcodes
is an array ofOcrBarcode
objects, one for each barcode in the page, each object will have the following properties:format
is the barcode formatnumber
is the barcode number if availablevalue
is the value of the barcodetext
is the text of the barcodebounds
is the bounding box of the barcode
lines
is an array ofOcrLine
objects, one for each line in the page, each object will have the following properties:text
is the extracted text of the lineconfidence
is the confidence level of the OCR result for the linebounds
is the bounding box of the linetextDirection
is the text direction of the page
blocks
is an array ofOcrBlock
objects, one for each text-block in the page, each object will have the following properties:text
is the extracted text of the blockconfidence
is the confidence level of the OCR result for the blockbounds
is the bounding box of the blocktextDirection
is the text direction of the blockblockType
is the block type of the blockbounds
is the bounding box of the blockblockNumber
is the block number of the blocklines
is an array ofOcrLine
objects, one for each line in the block (same type as forlines
of the page)
paragraphs
is an array ofOcrParagraph
objects, one for each paragraph in the page, each object will have the following properties:text
is the extracted text of the paragraphconfidence
is the confidence level of the OCR result for the paragraphbounds
is the bounding box of the paragraph
words
is an array ofOcrWord
objects, one for each word in the page, each object will have the following properties:text
is the extracted text of the wordconfidence
is the confidence level of the OCR result for the wordbounds
is the bounding box of the wordtextDirection
is the text direction of the word
Find the location of a text in an image
The bounds
method can be used to find the location of a text in an image.
javascript
var ocr = Module.load("Ocr", {version: "vX.Y.Z"});
// Get the bounding box of the text
var bounds = ocr.bounds("<base64 encoded image>", {lang: "Danish"});
Construct a path for a field based on a text
If you e.g. have a screenshot and need a path to a specific field containing some word or text, you can use the fieldPath
method.
javascript
var ocr = Module.load("Ocr", {version: "vX.Y.Z"});
// We're looking for an OK button
var p = ocr.fieldPath("<base64 encoded image, e.g. a screenshot>", "OK", {lang: "Danish"});
// Lets click on the button
new Field(p).click();