Einzelnen Beitrag anzeigen

omata

Registriert seit: 26. Aug 2004
Ort: Nebel auf Amrum
3.154 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: GhostScript: PDF wird nicht erzeugt

  Alt 10. Feb 2010, 07:26
Also bei mir sieht das so aus...

Delphi-Quellcode:
function CreatePDF(Datei, GhostscriptDllPath:string;
                   StdOUT, StdERR:TStrings):boolean;
var hDLL: HINST;
    argv:array of PChar;
    code:integer;
    instance:Pointer;
    gsInit : TgsInit;
    gsapi_init_with_args : Tgsapi_init_with_args;
    gsapi_exit : Tgsapi_exit;
    gsapi_delete_instance : Tgsapi_delete_instance;
    gsapi_set_stdio : Tgsapi_set_stdio;
begin
  Result:=false;
  hDLL := LoadLibrary(PChar(GhostscriptDllPath+'bin\gsdll32.dll'));
  try
    if hDll > 0 then begin
      gsInit := GetProcAddress(hDLL, 'gsapi_new_instance');
      code:=gsInit(@instance, nil);
      if code <> 0 then begin
        if assigned(FStdERR) then
          FStdERR.Append(
            'Es kann keine Instanz von Ghostscript erzeugt werden ' +
            '(Fehler: '+IntToStr(code)+')'
          );
      end
      else begin
        gsapi_set_stdio:= GetProcAddress(hDLL, 'gsapi_set_stdio');
        code:=gsapi_set_stdio(instance, @gsstdin, @gsstdout, @gsstderr);
        if code < 0 then begin
          if assigned(FStdERR) then
            FStdERR.Append(
              'Es kann keine Callback-Routine eingerichtet werden ' +
              '(Fehler: '+IntToStr(code)+')'
            );
        end
        else begin
          gsapi_init_with_args:= GetProcAddress(hDLL, 'gsapi_init_with_args');
          gsapi_exit:= GetProcAddress(hDLL, 'gsapi_exit');
          gsapi_delete_instance:= GetProcAddress(hDLL, 'gsapi_delete_instance');

          setlength(argv, 11);
          argv[0] := '';
          argv[1] := '-dNOPAUSE';
          argv[2] := '-dBATCH';
          argv[3] := '-dSAFER';
          argv[4] := '-sDEVICE=pdfwrite';
          argv[5] := PChar(
            '-I'+GhostscriptDllPath+'lib;'+GhostscriptDllPath+'..\fonts'
          );
          argv[6] := PChar(
            '-sOutputFile='+ChangeFileExt(ExtractFileName(Datei), '.pdf')
          );
          argv[7] := '-c';
          argv[8] := '.setpdfwrite';
          argv[9] := '-f';
          argv[10] := PChar(Datei);
          try
            code := gsapi_init_with_args(instance, length(argv), argv);
            if code < 0 then
              if assigned(FStdERR) then
                FStdERR.Append('ERROR: init_args: '+IntToStr(code));
            setlength(argv, 0);
          finally
            gsapi_exit(instance);
            gsapi_delete_instance(instance);
            if code >= 0 then begin
              CopyFile(
                PChar(ChangeFileExt(ExtractFileName(Datei), '.pdf')),
                PChar(ChangeFileExt(Datei, '.pdf')), false
              );
            end;
          end;
          Result:=true;
        end;
      end;
    end
    else begin
      if assigned(FStdERR) then
        FStdERR.Append('gsdll32.dll nicht gefunden');
    end;
  finally
    FreeLibrary(hDLL);
  end;
end;
  Mit Zitat antworten Zitat