{******************************************************************}
{ GnuOcr.pas                                                       }
{                                                                  }
{ Author    : A.Nasir Senturk                                      }
{ Home Page : http://www.shenturk.com                              }
{ Email     : shenturk@gmail.com                                   }
{                                                                  }
{ Date      : 03.01.2007                                           }
{ Update    : 22.03.2007                                           }
{                                                                  }
{ Sizden iki şey rica edicem:                                      }
{ 1. Lutfen bu baslik kismini kaldirmayiniz.                       }
{ 2. Mumkunse bagis yapiniz.                                       }
{ *****************************************************************}

unit GnuOcr;

interface

uses Windows, SysUtils, Classes;

{ ExecuteTesseract }
function ExecuteTesseract(const InFile, OutFile: string): Integer;

implementation

uses ConstDef;

{ ExecuteTesseract }
function ExecuteTesseract(const InFile, OutFile: string): Integer;
var
  bOk: Boolean;
  strCmdLine, strCurrDir: string;
  dwCreateFlags: DWORD;
  pi: PROCESS_INFORMATION;
  si: STARTUPINFO;
begin
  Result := -1;
  strCmdLine := 'tesseract.exe ' + InFile + ' ' + OutFile + ' batch';
  strCurrDir := GetApplicationPath();
  dwCreateFlags := 0;
  FillChar(pi, SizeOf(PROCESS_INFORMATION), 0);
  FillChar(si, SizeOf(STARTUPINFO), 0);
  si.cb := SizeOf(si);
  si.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
  si.wShowWindow := SW_HIDE;
  si.hStdInput := STD_INPUT_HANDLE;
  si.hStdOutput := STD_OUTPUT_HANDLE;
  si.hStdError := STD_ERROR_HANDLE;
  bOk := CreateProcess( nil, PChar(strCmdLine), nil, nil, True,
    dwCreateFlags, nil, PChar(strCurrDir), si, pi );
  if bOk then
  begin
    CloseHandle( pi.hThread );
    if WaitForSingleObject( pi.hProcess, 1000 ) = WAIT_OBJECT_0 then
      Result := 0;
    CloseHandle( pi.hProcess );
  end;
end;

end.
