function TGhostscript.LoadDLL(PathDLL:
string): Boolean;
var
CurrentDLLPath:
string;
begin
if PathDLL = '
'
then
begin
CurrentDLLPath := IncludeTrailingPathDelimiter(ExtractFilePath(ParamStr(0))) + conDLLName;
end
else
begin
CurrentDLLPath := PathDLL;
end;
FDLLHandle := LoadLibrary(PChar(CurrentDLLPath));
if FDLLHandle > 0
then
begin
FGsInit := GetProcAddress(FDLLHandle, '
gsapi_new_instance');
Result := (FGsInit(@FGsInstance,
nil) = 0);
if Result
then
begin
FGsApiInitWithArgs := GetProcAddress(FDLLHandle, '
gsapi_init_with_args');
FGsApiExit := GetProcAddress(FDLLHandle, '
gsapi_exit');
FGsApiDeleteInstance := GetProcAddress(FDLLHandle, '
gsapi_delete_instance');
end
else
begin
FOnError(Self, '
Die Ghostscript Instanz konnte nicht erzeugt werden.');
Result := False;
end;
end
else
begin
FOnError(Self, Format('
Die Ghostscript DLL %s wurde nicht geladen.', [QuotedStr(CurrentDLLPath)]));
Result := False;
end;
end;
function TGhostscript.PDFShrink(FileName:
string): Boolean;
var
TargetFileName:
string;
begin
if FDLLHandle = 0
then
begin
LoadDLL(FDLLPath);
end;
try
TargetFileName := IncludeTrailingPathDelimiter(ExtractFilePath(FileName)) + conFileNameTempPDF;
SetLength(FParameters, 7);
FParameters[0] := '
';
FParameters[1] := '
-dNOPAUSE';
FParameters[2] := '
-dBATCH';
FParameters[3] := '
-dPDFSETTINGS=/ebook';
FParameters[4] := '
-sDEVICE=pdfwrite';
FParameters[5] := PAnsiChar(AnsiString('
-sOutputFile=' + TargetFileName));
FParameters[6] := PAnsiChar(AnsiString(FileName));
Result := (FGsApiInitWithArgs(FGsInstance, Length(FParameters), FParameters) = 0);
//(Zeile 118)
finally
FGsApiExit(FGsInstance);
//(Zeile 121)
end;
if Result
then
begin
if not TToolsIO.IsFileInUse(FileName)
then
begin
TFile.Delete(FileName);
RenameFile(TargetFileName, FileName);
end;
end
end;