Ocr
This module can be used for detecting text in images.
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:
textis the extracted text of the complete documentconfidenceis the confidence level of the OCR resultpagesis an array ofOcrPageobjects, one for each page in the PDF, they’ll have the following properties:textis the extracted textconfidenceis the confidence level of the OCR result for the pagepageNumberis the page numbertextDirectionis the text direction of the pagepdfTextis the extracted text from the PDF if it is possible to directly extract itboundsis the bounding box of the text in the pagecontentAreais the content area of the pagebarcodesis an array ofOcrBarcodeobjects, one for each barcode in the page, each object will have the following properties:formatis the barcode formatnumberis the barcode number if availablevalueis the value of the barcodetextis the text of the barcodeboundsis the bounding box of the barcode
linesis an array ofOcrLineobjects, one for each line in the page, each object will have the following properties:textis the extracted text of the lineconfidenceis the confidence level of the OCR result for the lineboundsis the bounding box of the linetextDirectionis the text direction of the page
blocksis an array ofOcrBlockobjects, one for each text-block in the page, each object will have the following properties:textis the extracted text of the blockconfidenceis the confidence level of the OCR result for the blockboundsis the bounding box of the blocktextDirectionis the text direction of the blockblockTypeis the block type of the blockboundsis the bounding box of the blockblockNumberis the block number of the blocklinesis an array ofOcrLineobjects, one for each line in the block (same type as forlinesof the page)
paragraphsis an array ofOcrParagraphobjects, one for each paragraph in the page, each object will have the following properties:textis the extracted text of the paragraphconfidenceis the confidence level of the OCR result for the paragraphboundsis the bounding box of the paragraph
wordsis an array ofOcrWordobjects, one for each word in the page, each object will have the following properties:textis the extracted text of the wordconfidenceis the confidence level of the OCR result for the wordboundsis the bounding box of the wordtextDirectionis 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();