Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I retrieve a list or number of jobs from a printer queue?

I'm looking for a way to get a list or number of jobs from a particular printer. In the best case I would want to have a "Job object" that represents one print job and its name in the print queue.

This is required because I need to monitor the state of a printer so I can refill the print queue with a new batch of documents without overflowing the print spooler

Thanks in advance!

Edit: added code fragment of solution

private int GetNumberOfPrintJobs()
{
    LocalPrintServer server = new LocalPrintServer();
    PrintQueueCollection queueCollection = server.GetPrintQueues();
    PrintQueue printQueue = null;

    foreach (PrintQueue pq in queueCollection)
    {
        if (pq.FullName == PrinterName)
            printQueue = pq;
    }

    int numberOfJobs = 0;
    if (printQueue != null)
        numberOfJobs = printQueue.NumberOfJobs;

    return numberOfJobs;
}
like image 467
Berry Ligtermoet Avatar asked Apr 08 '11 09:04

Berry Ligtermoet


People also ask

Where are queued print jobs stored?

In Windows, a built-in service called Print Spooler temporarily stores all print jobs until they're printed. These print jobs are stored by Windows as files in a folder associated with the Print Spooler service. Luckily, when a print job is stuck in the queue, you can manually remove it from the Print Spooler.

Is there a way to see print history Mac?

View information about completed print jobs After you print, you can view information about a document you printed, such as the time and date. On your Mac, choose Apple menu > System Preferences, then click Printers & Scanners . Select the printer you used in the list at the left, then click Open Print Queue.


1 Answers

You can use the .NET 3.0 PrintQueue class in the System.Printing namespace. Its NumberOfJobs property tells you how many jobs are queued, GetPrintJobInfoCollection() returns details on all the jobs. Beware that it doesn't have any events that tells you that the job collection changed, you need to poll with a timer. Once a second or so ought to be fine.

like image 149
Hans Passant Avatar answered Sep 17 '22 15:09

Hans Passant