OCRImageToFile Method

Description  

This function OCR the specified image file and saves the output text to the specified text file. If the output file already exists the function will overwrite the file.
The function handles the following file formats: DCX, DIB, CLP, GIF, PCX, TIFF, TGA, ColorFax, WMF, EMF, PNG, CALS, Image PDF, DICOM, JPEG

     

Syntax                 RetVal = [BIOCR.] OCRImageToFile  szImageFileName szOutputFileName bAppend szLanguage bDetectOrientation nEncoding

Returns               RetVal                          Integer          Returns with error status. OCR_OK (0) if successful. See other error codes in BiOCR.ocx specific error codes.

Remarks            

szImageFile                String              The image file name

szFileName     String              The output text file name

bAppend        Boolean           If TRUE the function will append the output text to the end of output file
If FALSE the function will overwrite the output file if the output file already exists

szLanguage    String              The code of the language used for OCR. If multiple languages are used the language codes must be separated by ‘+’ character. The available languages can be retrieved by the GetOCRLanguages function. See the languages codes in the OCR languages section

bDetectOrientation    Boolean           If TRUE the function will detect the text orientation automatically.
                                                            If FALSE the function will assume that the text in the DIB is not rotated. (this mode is faster)

nEncoding                  Integer             The used character encoding for the output file
If         0          OCR_ENC_ASCII                 use ASCII encoding
If         1          OCR_ENC_UTF8                  use UTF-8 encoding
If         2          OCR_ENC_UTF16                use UTF-16 encoding


 

BiOCR.ocx specific error codes

Error Code number

Error Code

Meaning

0

OCR_OK

Operation was successful.

1

OCR_DLLLOCATIONERROR

Cannot get the DLL location.

2

OCR_INITERROR

Cannot initialize the OCR engine.

3

OCR_DIBCONVERTERROR

Error during converting DIB.

4

OCR_FILEIOERROR

General I/O error in reading or writing.

5

OCR_NOTENOUGHMEMORY

Not enough memory to allocate block.

6

OCR_INVALIDPARMETER

Invalid parameter.

7

OCR_DLLLOADERROR

Cannot load external dll.

8

OCR_IMAGELOADERROR

Cannot load the image file.

 

Code example

// C# code

 

BIOCRLib.BiOCRClass ocrLib = new BIOCRLib.BiOCRClass();

int ret = 0;

 

// OCR image to file

ret = ocrLib.OCRImageToFile("c:\\Program Files\\Black Ice Software LLC\\Document Imaging SDK DEMO for Windows 32-bit\\Images\\TEST.TIF", "c:\\OCR_test.txt", 0, "eng", 1, (int)BIOCRLib.OCR_TEXT_ENCODING.OCR_ENC_UTF8);

 

// Check error

if (ret != (int)BIOCRLib.OCR_ERRORS.OCR_OK)

    return;