public static void InputLicense(string licenseeName, string licenseCode)
 {
     if (Is64BitProcess)
     {
         OcrDll64.com_asprise_ocr_input_license(licenseeName, licenseCode);
     }
 }
 private static void deleteC(IntPtr ptr, bool isArray)
 {
     if (Is64BitProcess)
     {
         OcrDll64.com_asprise_ocr_util_delete(ptr.ToInt64(), isArray);
     }
     else
     {
         OcrDll32.com_asprise_ocr_util_delete(ptr.ToInt64(), isArray);
     }
 }
 /// <summary>
 /// Performs one-time setup; does nothing if setup has already been done.
 /// </summary>
 public static void SetUp()
 {
     if (Is64BitProcess)
     {
         OcrDll64.com_asprise_ocr_setup(0);
     }
     else
     {
         OcrDll32.com_asprise_ocr_setup(0);
     }
 }
 /// <summary>
 /// Stops the OCR engine; does nothing if it has already been stopped.
 /// </summary>
 public void StopEngine()
 {
     if (!IsEngineRunning)
     {
         return;
     }
     if (Is64BitProcess)
     {
         OcrDll64.com_asprise_ocr_stop(_handle.ToInt64());
     }
     else
     {
         OcrDll32.com_asprise_ocr_stop(_handle.ToInt64());
     }
 }
        /// <summary>
        /// Starts the OCR engine; does nothing if the engine has already been started.
        /// </summary>
        /// <param name="lang">e.g., "eng"</param>
        /// <param name="speed">e.g., "fastest"</param>
        public void StartEngine(string lang, string speed)
        {
            if (IsEngineRunning)
            {
                return;
            }
            if (lang == null || speed == null || lang.Trim().Length == 0 || speed.Trim().Length == 0)
            {
                throw new Exception("Invalid arguments.");
            }

            _handle = Is64BitProcess ?
                      OcrDll64.com_asprise_ocr_start(lang, speed) :
                      OcrDll32.com_asprise_ocr_start(lang, speed);

            if (_handle.ToInt64() < 0)
            {
                _handle = new IntPtr(0);
                throw new Exception("Failed to start engine. Error code: " + _handle.ToInt64());
            }
        }
 /// <summary>
 /// The library version.
 /// </summary>
 /// <returns>The library version.</returns>
 public static string GetLibraryVersion()
 {
     return(Marshal.PtrToStringAnsi(Is64BitProcess ?
                                    OcrDll64.com_asprise_ocr_version() :
                                    OcrDll32.com_asprise_ocr_version()));
 }
        /// <summary>
        /// Performs OCR on the given input files.
        /// </summary>
        /// <param name="files">comma ',' separated image file path (JPEG, BMP, PNG, TIFF)</param>
        /// <param name="pageIndex">-1 for all pages or the specified page (first page is 1) for multi-page image format like TIFF</param>
        /// <param name="startX">-1 for whole page or the starting x coordinate of the specified region</param>
        /// <param name="startY">-1 for whole page or the starting y coordinate of the specified region</param>
        /// <param name="width">-1 for whole page or the width of the specified region</param>
        /// <param name="height">-1 for whole page or the height of the specified region</param>
        /// <param name="recognizeType">valid values: RECOGNIZE_TYPE_TEXT, RECOGNIZE_TYPE_BARCODE or RECOGNIZE_TYPE_ALL.</param>
        /// <param name="outputFormat">valid values: OUTPUT_FORMAT_PLAINTEXT or OUTPUT_FORMAT_XML.</param>
        /// <param name="additionalProperties">additional properties, can be a single Dictionary object or inline specification in pairs. Valid property names are defined in this class, e.g., PROP_INCLUDE_EMPTY_BLOCK, etc.</param>
        /// <returns>text (plain text, xml) recognized for OUTPUT_FORMAT_PLAINTEXT, OUTPUT_FORMAT_XML; empty for OUTPUT_FORMAT_PDF.</returns>
        public string Recognize(string files, int pageIndex, int startX, int startY, int width, int height, string recognizeType, string outputFormat, params object[] additionalProperties)
        {
            if (threadDoingOCR != null)
            {
                throw new Exception("Currently " + threadDoingOCR + " is using this OCR engine. Please create multiple OCR engine instances for multi-threading. ");
            }

            Dictionary <string, string> dict = new Dictionary <string, string>();

            if (additionalProperties != null && additionalProperties.Length > 0 &&
                (additionalProperties[0] as Dictionary <string, string> != null))
            {
                foreach (KeyValuePair <string, string> pair in (Dictionary <string, string>)additionalProperties[0])
                {
                    if (pair.Key != null)
                    {
                        dict.Add(pair.Key.ToString(), pair.Value == null ? null : pair.Value.ToString());
                    }
                }
            }
            else if (additionalProperties != null && additionalProperties.Length > 0)
            {
                if (additionalProperties.Length % 2 == 1)
                {
                    throw new Exception("You must specify additional properties in key/value pair. Current length: " + additionalProperties.Length);
                }
                for (var p = 0; p < additionalProperties.Length; p += 2)
                {
                    string key = (string)additionalProperties[p];
                    object val = additionalProperties[p + 1];
                    if (key != null)
                    {
                        dict.Add(key, val == null ? "" : val.ToString());
                    }
                }
            }

            // validation
            foreach (KeyValuePair <string, string> pair in dict)
            {
                if (pair.Key.Contains(CONFIG_PROP_KEY_VALUE_SEPARATOR))
                {
                    throw new Exception("Please change CONFIG_PROP_KEY_VALUE_SEPARATOR to a different value as \"" +
                                        pair.Key + "\" contains \"" + CONFIG_PROP_KEY_VALUE_SEPARATOR + "\"");
                }
                if (pair.Value.Contains(CONFIG_PROP_SEPARATOR))
                {
                    throw new Exception("Please change CONFIG_PROP_SEPARATOR to a different value as \"" +
                                        pair.Value + "\" contains \"" + CONFIG_PROP_SEPARATOR + "\"");
                }
            }

            if (outputFormat.Equals(OUTPUT_FORMAT_PDF))
            {
                string pdfOutputFile = dict.ContainsKey(PROP_PDF_OUTPUT_FILE) ? dict[PROP_PDF_OUTPUT_FILE] : null;
                if (pdfOutputFile == null)
                {
                    throw new Exception("You must specify PDF output through property named: " + PROP_PDF_OUTPUT_FILE);
                }
            }

            try
            {
                threadDoingOCR = Thread.CurrentThread;

                IntPtr ptr = (Is64BitProcess ?
                              OcrDll64.com_asprise_ocr_recognize(_handle.ToInt64(), files, pageIndex, startX, startY, width, height, recognizeType, outputFormat, dictsToString(dict), CONFIG_PROP_SEPARATOR, CONFIG_PROP_KEY_VALUE_SEPARATOR) :
                              OcrDll32.com_asprise_ocr_recognize(_handle.ToInt64(), files, pageIndex, startX, startY, width, height, recognizeType, outputFormat, dictsToString(dict), CONFIG_PROP_SEPARATOR, CONFIG_PROP_KEY_VALUE_SEPARATOR)
                              );

                string s = Marshal.PtrToStringAnsi(ptr);
                if (s != null && s.Length > 0 && ptr.ToInt64() > 0)
                {
                    // clean up
                    deleteC(ptr, true);
                }
                return(s);
            }
            finally
            {
                threadDoingOCR = null;
            }
        }