Get a list of current print jobs (Views: 710)
Problem/Question/Abstract: Is there any way in Delphi to check for the printer queue or if a printer has received and printed a document correctly? Answer: No there is not any bullet-proof way of determining that a document has been printed correctly. Nevertheless here is a routine to collect all the running jobs of a printer. Keep in mind that the only way to retrieve this information is by pooling it from the spooler in standard intervals. { ... } type PJobInfoArray = ^TJobInfoArray; TJobInfoArray = array[0..0] of winspool.JOB_INFO_2; procedure GetJobs(APrinter: string); var Size, Needed, Returned, CNT: Cardinal; Res: LongBool; Prn: Cardinal; PrnName: Pchar; vJobs: PJobInfoArray; begin ReAllocMem(PrnName, Length(aPrinter) + 2); CopyMemory(PrnName, @aPrinter[1], Length(aPrinter)); Res := OpenPrinter(PrnName, Prn, nil); ReAllocMem(PrnName, 0); if LongInt(Res) = 0 then RaiseLastOSError; Size := 0; Res := WinSpool.EnumJobs(Prn, 0, 999, 2, VJobs, 0, Needed, Returned); Size := Needed; reAllocMem(VJobs, Size); Res := EnumJobs(Prn, 0, 999, 2, vJobs, Size, Needed, Returned); if LongInt(Res) > 0 then begin reAllocMem(vJobs, 0); ClosePrinter(Prn); RaiseLastOSError; end; ReAllocMem(VJobs, 0); ClosePRinter(Prn); end; |