Get a list of current print jobs (Views: 100)


Is there any way in Delphi to check for the printer queue or if a printer has received and printed a document correctly?


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.

{ ... }
  PJobInfoArray = ^TJobInfoArray;
  TJobInfoArray = array[0..0] of winspool.JOB_INFO_2;

procedure GetJobs(APrinter: string);
  Size, Needed, Returned, CNT: Cardinal;
  Res: LongBool;
  Prn: Cardinal;
  PrnName: Pchar;
  vJobs: PJobInfoArray;
  ReAllocMem(PrnName, Length(aPrinter) + 2);
  CopyMemory(PrnName, @aPrinter[1], Length(aPrinter));
  Res := OpenPrinter(PrnName, Prn, nil);
  ReAllocMem(PrnName, 0);
  if LongInt(Res) = 0 then
  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
    reAllocMem(vJobs, 0);
  ReAllocMem(VJobs, 0);

<< Back to main page