diff --git a/components/printers/osprinters.pas b/components/printers/osprinters.pas index b702857796..da0c1c241c 100644 --- a/components/printers/osprinters.pas +++ b/components/printers/osprinters.pas @@ -28,7 +28,6 @@ unit OSPrinters; interface - {$IFDEF UNIX} {$IFDEF DARWIN} {$IFDEF LCLCarbon} diff --git a/components/printers/unix/cupsprinters.inc b/components/printers/unix/cupsprinters.inc index 4e9bb2171e..89cc81d957 100644 --- a/components/printers/unix/cupsprinters.inc +++ b/components/printers/unix/cupsprinters.inc @@ -467,7 +467,7 @@ begin end; {$ENDIF} -//Print the file aFileName with a selected printer an options +//Print the file aFileName with a selected printer and options function TCUPSPrinter.PrintFile(aFileName: String): longint; var aPrinterName : string; @@ -498,6 +498,11 @@ begin end; end; +function TCUPSPrinter.GetLastError: string; +begin + Result:=ippErrorString(cupsdyn.cupsLastError()); +end; + function TCUPSPrinter.IsOptionValueValid(AKeyword, AValue: pchar): boolean; var Option: pppd_option_t; @@ -896,6 +901,8 @@ end; //If not aborted, send PostScript file to printer. //After, delete this file. procedure TCUPSPrinter.DoEndDoc(aAborted: Boolean); +var + CupsResult: LongInt; begin inherited DoEndDoc(aAborted); dec(FBeginDocCount); @@ -922,13 +929,19 @@ begin {$IFDEF LogPrintoutFile} CopyFile(FOutputFileName, 'printjob'+ExtractFileExt(FOutputFileName)); {$ENDIF} - {$IFNDEF DoNotPrint} - if Filename<>'' then - CopyFile(FOutputFileName, FileName) - else - PrintFile(FOutputFileName); - {$ENDIF} - DeleteFileUTF8(FOutputFilename); + try + {$IFNDEF DoNotPrint} + if Filename<>'' then + CopyFile(FOutputFileName, FileName) + else begin + CupsResult:=PrintFile(FOutputFileName+'1'); + if CupsResult<=0 then + raise Exception.Create('CUPS printing: '+GetLastError); + end; + {$ENDIF} + finally + DeleteFileUTF8(FOutputFilename); + end; end; end; diff --git a/components/printers/unix/cupsprinters_h.inc b/components/printers/unix/cupsprinters_h.inc index 609c39f3fd..9c5f9e7d32 100644 --- a/components/printers/unix/cupsprinters_h.inc +++ b/components/printers/unix/cupsprinters_h.inc @@ -168,6 +168,7 @@ type --------------------------------------------------} procedure SetJobState(aJobId : LongInt; aOp : ipp_op_t); function PrintFile(aFileName: String): longint; + function GetLastError: string; procedure DebugOptions(AOPtions:Pcups_option_t=nil; n:Integer=0); function cupsGetOption(aKeyWord: string): String; function CopyOptions(out AOptions: Pcups_option_t): Integer;