1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| procedure PDF2TXT(input : AnsiString; output: AnsiString);
var ExitCode:integer;
instance: Pointer;
Arg: array of PAnsiChar;
begin
ExitCode := gsapi_new_instance(instance, nil);
if ExitCode < 0 then
raise Exception.Create('Impossible to open an instance of ghostscript. Error ExitCode: '+IntToStr(ExitCode));
try
SetLength(Arg, 5);
Arg[0] := PAnsiChar('-dBATCH');
Arg[1] := PAnsiChar('-dNOPAUSE');
Arg[2] := PAnsiChar('-sDEVICE=txtwrite');
Arg[3] := PAnsiChar('-sOutputFile='+ output + '.txt' );
Arg[4] := PAnsiChar(input);
// pê pas le code exact... mais l'idée y est !
msg:=nil;
esp:=' ';
for i:=0 to 4 do begin msg:=Strcat(msg, Arg[i]); msg:=Strcat(msg,esp); end;
ShowMessage(msg);
ExitCode := gsapi_init_with_args(instance, Length(Arg), @Arg[0]);
if ExitCode < 0 then raise Exception.Create('ERROR: init_args: '+IntToStr(ExitCode));
gsapi_exit(instance);
finally
gsapi_delete_instance(instance);
end;
end; |