Search code examples
c#printingzpl

How to know when printing process with copy command to localhost printer finished successfully?


Currently I'm sending a zpl file to a printer using this way:

/C copy /B zplFile.zpl \\localhost\GX420d

In C# I use this code:

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = processName; //cmd
startInfo.Arguments = string.Format(processArgument, "tmp.txt");
process.StartInfo = startInfo;
process.Start();

Everything works great, the problem is that I dont have a handshake to know when the printing process finished successfully, for example, if I send a zpl file and the printer does not have labels, or is disconected, the system that executes the command assumes that the printing process finished successfully.

I need to know if the label was printed successfully.

NOTE1: The printer is a GX420d using a USB cable.

Any suggestions?

Editing:

If you see in the below image, there are pending jobs to print, well, maybe as a workaround I can search in this list using C#, is this possible?

List of pending jobs


Solution

  • Well, maybe this workarround will works.

    http://www.codeproject.com/Articles/51085/Monitor-jobs-in-a-printer-queue-NET

    If you guys have a better option to resolve this problem I will appreciate your comments.

    Just for the record, I search into the printer jobs, and count the pending jobs, if there is more than zero, I assume that it failed.

    The steps are: 1.- Send ZPL file to printer. 2.- Use the System.Threading.Thread.Sleep to wait a predetermined time. 3.- Search into printer pending jobs, if count > 0 then it will fail, because I assume that the label does not print successfully.