none
How to move a print job from one queue to another

    Question

  • Hello!

    On the same machine i have 2 printers installed.

    How can i transfer all the jobs from one queue to the second queue of the machine?

    I am using System.Printing for this.

    With the code that I have I am able to list all the print queques on the print server and i can have acces to the all the jobs that are coming to the first queque.I can pause them,delete them etc.

    The only thing that i do not understand is how to use the AddJob() function to put the jobs from queue1 to queue2.

    Thank you!

     

    Wednesday, October 13, 2010 8:09 PM

Answers

  • OK! I found the solution!

    After reading this article

    http://www.codeproject.com/KB/printing/wpa.aspx

    i realized that i have to work before the spooler and to catch the data that the aplication who wants to print is sending.This data must be captured before the spooler ,because the spooler file contains specific instructions that are compatible only with the printer coresponding to that queue.

    To do that in C# demands a lot of work!

    So ,for all you out there who want to move print jobs from one queue to another queue you must use a third party application ( do not reinvent the wheel,it is allready invented) and adapt your application to work with this third party application.

    I found a tool that is called Print Multi,a very powerfull one,with a lot of options to configure,a very good documentaition and offcourse FREE!

    This tool is great,fast and very very powerfull if it is right configured.

    You can find it over here : http://www.lvbprint.de/  just use a translate web page if you do not understend german!

    Have fun!

    • Marked as answer by Mirku Thursday, October 21, 2010 9:18 AM
    Thursday, October 21, 2010 9:17 AM

All replies

  • Is there nobody that is using System.Printing to access the print queue?

    Just a little up!!

    Thursday, October 14, 2010 2:13 PM
  • Hi Mirku,

    Welcome to MSDN forums!

    PrintQueue.AddJob Method:

    Inserts a new (generically named) print job, whose content is a Byte array, into the queue.

    You can refer here: http://msdn.microsoft.com/en-us/library/ms552912.aspx.

    PrintQueue.Purge Method:

     

    Removes all the jobs in the print queue.

    http://msdn.microsoft.com/en-us/library/system.printing.printqueue.purge.aspx

     

    Hope these helps, if you have any problems, please feel free to let me know.

    Best Regards,
    Alan Chen
    ________________________________________
    Please remember to mark the replies as answers if they help and unmark them if they provide no help

    Friday, October 15, 2010 7:55 AM
  • Ok,thanks!

    After digging a littel bit i got the poit on how to transfer to another queque the jobs but now I have another problem.What i transfer is an empty byte.

          defaultPrintQueue = LocalPrintServer.GetDefaultPrintQueue(); //default print queue
          jobs = defaultPrintQueue.GetPrintJobInfoCollection(); //jobs on the queue
          transferQueue = pServer2.GetPrintQueue("CutePDF Writer"); //where to transfer
           foreach (PrintSystemJobInfo job in jobs)
            {
              if ((job.JobStatus & PrintJobStatus.Spooling) == PrintJobStatus.Spooling)
             {return;}  //let the spool finish the stream
              if ((job.JobStatus & PrintJobStatus.Printing) == PrintJobStatus.Printing)
              {  //if the spool has finished filling the stream I pause and get reference of the stream and transfer the content to another queque
                job.Pause();
                long dim = job.JobStream.Length;
                PrintData = new byte[job.JobStream.Length];
                PrintSystemJobInfo myPrintJob = transferQueue.AddJob();
                System.IO.Stream myStream = myPrintJob.JobStream;
                int ok = job.JobStream.Read(PrintData, 0, Convert.ToInt32(job.JobStream.Length));
                myStream.Write(PrintData, 0, PrintData.Length);
                myStream.Close();
              }
              job.Cancel();
    
              
    
    

    The problem is that i get a NULL reference of the stream from the default queue.When i debug the program the job.JobStream.Length has a NULL value and job.JobStream is also NULL.

    Any ideeas why?

    Saturday, October 16, 2010 9:45 AM
  • Hi,

    JobStream Gets a reference to the Stream of the print job.

    I think you can use :

    JobSize Get the size, in bytes, of the print job.

    Many print job properties, such as whether a job is completed, must be passed from the printer to the PrintSystemJobInfo object before your application reads the corresponding property (IsCompleted). The Refresh method provides this functionality.

    Similarly, when your application changes the value of the JobName property, the change must be written to the print queue utility on the computer. The Commitmethod provides this functionality.

    By the way, you can set breakpoints in your code, then press F5 to debug your application, your project will stop at the breakpoints, and you can watch whether job is a null object.

     


    Hope these helps, if you have any problems, please feel free to let me know.

    Best Regards,
    Alan Chen
    ________________________________________
    Please remember to mark the replies as answers if they help

    Monday, October 18, 2010 3:46 AM
  • ok,I get the size of the job using JobSize but i still do not understand how to move the print job.

    PrintQueue.AddJob Method:  Inserts a new (generically named) print job, whose content is a Byte array, into the queue.

    On the documentation they say that the AddJob() method uses a Byte array to fill the spooler.My problem is "How to get this byte array?"

    I have the size of this byte array using the JobSize but i have no content because JobStream has a NULL value.

    Thanks

    Wednesday, October 20, 2010 3:45 PM
  • OK! I found the solution!

    After reading this article

    http://www.codeproject.com/KB/printing/wpa.aspx

    i realized that i have to work before the spooler and to catch the data that the aplication who wants to print is sending.This data must be captured before the spooler ,because the spooler file contains specific instructions that are compatible only with the printer coresponding to that queue.

    To do that in C# demands a lot of work!

    So ,for all you out there who want to move print jobs from one queue to another queue you must use a third party application ( do not reinvent the wheel,it is allready invented) and adapt your application to work with this third party application.

    I found a tool that is called Print Multi,a very powerfull one,with a lot of options to configure,a very good documentaition and offcourse FREE!

    This tool is great,fast and very very powerfull if it is right configured.

    You can find it over here : http://www.lvbprint.de/  just use a translate web page if you do not understend german!

    Have fun!

    • Marked as answer by Mirku Thursday, October 21, 2010 9:18 AM
    Thursday, October 21, 2010 9:17 AM
  • Hi


    Me I want to do almost the samething, except I want to cancel the printjob from a printqueue (save it in memory) and after some validations send it  to the SAME printer.

    I don't want to pause it, because anybody could resume it very easily!

    Is there a way to do that without third party application ?

    This is my code:

     

              PrintQueue MyPrintQueue = OldPrintJob.HostingPrintQueue;
              long dim = OldPrintJob.JobSize;
              Byte[] anotherByteBuffer = new byte[dim];
              PrintSystemJobInfo NewPrintJob = MyPrintQueue.AddJob();
              System.IO.Stream myStream = NewPrintJob.JobStream;
              int ok = Travail.JobStream.Read(anotherByteBuffer, 0, Convert.ToInt32(dim));
              myStream.Write(anotherByteBuffer, 0, anotherByteBuffer.Length);
              myStream.Close();
    Thank you !
    Sunday, October 24, 2010 8:58 PM
  • I do not know if it is going to work but you can try the following:

    - create an PrintJob object and save the job

    -pause the current job

    -stop the spooler service by using "net stop spooler"

    - do your work with the application

    - restart the spooler service and resume your job

    Never tryed it ! But you can give it a shot! If it works you will lose the print jobs that are coming between the "stop spooler" and "start spooler" ,i think!

    Good luck

    Monday, October 25, 2010 10:00 AM