Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Batch plot application (PrintServer & PrintQueue issues)

I have a problem that I need help with. For my current project I need to make a Batch Plot application. This application will have around ~2000 AutoCAD drawings that it will need to print.

The application needs 5 printers, 1 for each format, going from A4 to A0. No problems yet so far.

Now we all understand that we can not queue 2000 drawings simultaneously without some kind of trouble. I've did my research online and found methods to look at the current printer Queue. Using PrintServer and PrintQueue.

Here is where the problems begin. Firstly I am not able to find the network printers that I need. The printers are located on this network address: 192.168.0.14 (\vps01w2k8).

Following the guide from MSDN:

    PrintServer m_PrintServer = new PrintServer(@"\\vps01w2k8");
    PrintQueueCollection m_PrintQueueCollection = m_PrintServer.GetPrintQueues();

    foreach (PrintQueue queue in m_PrintQueueCollection)
    {
         cbPrinters.Items.Add(queue.Name.ToString());
    }

This does not give me any printers. Trying LocalPrintServer (or just PrintServer without any parameters passed into it). Gives me my local printers (obviously) and not my network printers.

My next step was to find a method to find all my installed printers which got me into using System.Drawing.Printing; instead of using System.Printing;.

    foreach (String printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
    {
         cbPrinters.Items.Add(printer.ToString());
    }

This simple code gives me all the printers I have, including the networked ones. However, now I am stuck between .NET 2.0 and 3.0 (and onward). The classes PrinterSettings and PrintServer/PrintQueue have no connection.

Lastly I tried to get access to the printer queues using the WMI approach. Querying the Win32_PrintJob which gave me results. Unfortunately these came along with 10 second lock-ups to retrieve these results.

I'm out of ideas. I'm either looking for a fix for the PrintServer to properly return my networked printers or any suggestions to do similar techniques for batch plotting with the PrinterSettings class.

Thanks in advance,

Jordy

like image 371
Kaiwa Avatar asked Dec 13 '22 11:12

Kaiwa


1 Answers

Found it. When calling GetPrintQueues you have to pass in an array of EnumeratedPrintQueueTypes. It now returns both my local and network printers (all installed printers).

PrintServer m_PrintServer = new PrintServer();
PrintQueueCollection m_PrintQueueCollection = m_PrintServer.GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections });
like image 128
Kaiwa Avatar answered Jan 22 '23 09:01

Kaiwa