1

So I have the following code to access the local printer and its current jobs in C#:

        PrintQueue pq = LocalPrintServer.GetDefaultPrintQueue();
        PrintJobInfoCollection pjic = pq.GetPrintJobInfoCollection();
        foreach( var printjob in pjic)
        {
            Console.WriteLine(printjob.Name);
        }
        Console.ReadLine();

What I want to do is send this PrintQueue object to another computer which is connected to a printer and add the jobs in this queue to jobs of that queue. So essentially, the idea is to print remotely over the networks. I have some network programming experience in Java but not enough to translate well into C#. So I was wondering if anyone can break it down for me. ( And I know there are tons of ways of configuring Windows/Mac OS to print from a remote printer but this application is a learning experience for me). Thanks !

oneCoderToRuleThemAll
  • 834
  • 2
  • 12
  • 33

1 Answers1

0

I don't know if this is working because I haven't tested it, but the idea is:

  1. Set the PrintServer to the computer you want
  2. Get the PrintQueue from the PrintServer
  3. Iterate over jobs and add each job to that PrintQueue

Unfortunately, I cannot find any way to add print job directly, what I found is by PrintQueue.AddJob() method that takes some arguments like job name, document path, etc.

// Step 1: Set the PrintServer to the computer you want
PrintServer printServer = new PrintServer("\\ANOTHER-COMPUTER-NAME");

// Step 2: Get the PrintQueue from the PrintServer
PrintQueue printQueue = printServer.GetPrintQueue("That Printer Name on Another Computer");

// Step 3: Iterate over jobs and add each job to that PrintQueue
foreach (var printjob in pjic)
{
    printQueue.AddJob(printjob.Name, "document path here", true, pq.DefaultPrintTicket.Clone());
}

// and then do, like passing the printQueue to the PrintDialog
PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = printQueue;

For getting the document path, you can refer to this answer.

Community
  • 1
  • 1
Rizki Pratama
  • 551
  • 4
  • 23