ocr
Version:
Accusoft OCR Xpress
56 lines (51 loc) • 2.3 kB
JavaScript
// *******************************************************************'
// Copyright 1996-2018 Accusoft Corporation. All rights reserved. *'
// This sample code is provided to Accusoft licensees "as is" *'
// with no restrictions on use or modification. No warranty for *'
// use of this sample code is provided by Accusoft. *'
// *'
// SAMPLE PURPOSE *'
// *'
// This sample illustrates how to read in a text-based image and *'
// export that data to a searchable text file, using Accusoft's *'
// OCR Xpress. *'
//****************************************************************** *'
var ocrx = require('ocr');
require('ocr-lang-eng');
var fs = require('fs');
params = {};
params.format = 'text';
// Get command line input.
if (process.argv.length != 4) {
console.log('********************************************************************');
console.log('Usage: \t\t' + 'node basic.js <inputFile>, <outputFile>');
console.log('Example:\t\t' + 'node basic.js ../images/color.bmp ./out.txt');
console.log('Run Example by default:\t' + 'node basic.js ../images/color.bmp ./out.txt');
console.log('********************************************************************');
// Set default value.
params.input = '../images/color.bmp';
params.output = './out.txt';
}
else {
params.input = process.argv[2];
params.output = process.argv[3];
}
// Initialize any licensing that needs to be set.
// ocrx.setSolutionName('<Solution name goes here>')
// ocrx.setSolutionKey(0x01234567, 0x01234567, 0x01234567, 0x01234567)
// Recognize the input image and output result to a text file.
ocrx.recognize(params, function(err, document) {
if (err) {
console.error(err);
}
else {
console.log('\n === Print out the recognized result === ');
fs.readFile(params.output, 'utf8', function (err, data) {
if (err) {
console.log(err);
return;
}
console.log(data);
});
}
});