0

Im trying to print somehing(text or batch of text) in network printer with C#.

also im trying to find status of each print after i send it to network printer.

the problem is , i cant find what print is mine and also from my current document

print.

this my code :

private string strinstatus;

public IActionResult Index()
            {
                string s = "sometext";
                PrintDocument p = new PrintDocument();
                p.PrinterSettings.PrinterName = "\\\\10.10.1.1\\Canon MF210 Series";
                p.PrintPage += delegate (object sender1, PrintPageEventArgs e1)
                {
                    e1.Graphics.DrawString(s, new Font("Times New Roman", 12), new SolidBrush(Color.Black), new RectangleF(0, 0, p.DefaultPageSettings.PrintableArea.Width, p.DefaultPageSettings.PrintableArea.Height));

                };
                try
                {
                    p.Print();
                    PrintServer myPrintServer = new PrintServer(@"\\10.10.1.1");
            PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();
            try
            {
                foreach (PrintQueue pq in myPrintQueues)
                {
                    pq.Refresh();
                    PrintJobInfoCollection pCollection = pq.GetPrintJobInfoCollection();
                    foreach (PrintSystemJobInfo job in pCollection)
                    {

                        SpotTroubleUsingJobAttributes(job);
                    }

                }
            }
            catch (Exception ex)
            {
                //throw;
            }
                }
                catch (Exception ex)
                {
                    throw new Exception("Exception Occured While Printing", ex);
                }

                string a = strinstatus;
                return View();
            }

public void SpotTroubleUsingJobAttributes(PrintSystemJobInfo theJob)
                   {
                       if ((theJob.JobStatus & PrintJobStatus.Blocked) == PrintJobStatus.Blocked)
                       {
                           strinstatus += "The job is blocked.";
                       }
                       if (((theJob.JobStatus & PrintJobStatus.Completed) == PrintJobStatus.Completed)
                           ||
                           ((theJob.JobStatus & PrintJobStatus.Printed) == PrintJobStatus.Printed))
                       {
                           strinstatus += "The job has finished. Have user recheck all output bins and be sure the correct printer is being
       checked.";
                       }
                       if (((theJob.JobStatus & PrintJobStatus.Deleted) == PrintJobStatus.Deleted)
                           ||
                           ((theJob.JobStatus & PrintJobStatus.Deleting) == PrintJobStatus.Deleting))
                       {
                           strinstatus += "The user or someone with administration rights to the queue has deleted the job. It must be
       resubmitted.";
                       }
                       if ((theJob.JobStatus & PrintJobStatus.Error) == PrintJobStatus.Error)
                       {
                           strinstatus += "The job has errored.";
                       }
                       if ((theJob.JobStatus & PrintJobStatus.Offline) == PrintJobStatus.Offline)
                       {
                           strinstatus += "The printer is offline. Have user put it online with printer front panel.";
                       }
                       if ((theJob.JobStatus & PrintJobStatus.PaperOut) == PrintJobStatus.PaperOut)
                       {
                           strinstatus += "The printer is out of paper of the size required by the job. Have user add paper.";
                       }

                       //if (((theJob.JobStatus & PrintJobStatus.Paused) == PrintJobStatus.Paused)
                       //    ||
                       //    ((theJob.HostingPrintQueue.QueueStatus & PrintQueueStatus.Paused) == PrintQueueStatus.Paused))
                       //{
                       //    HandlePausedJob(theJob);
                       //    //HandlePausedJob is defined in the complete example.
                       //}

                       if ((theJob.JobStatus & PrintJobStatus.Printing) == PrintJobStatus.Printing)
                       {
                           strinstatus += "The job is printing now.";
                       }
                       if ((theJob.JobStatus & PrintJobStatus.Spooling) == PrintJobStatus.Spooling)
                       {
                           strinstatus += "The job is spooling now.";
                       }
                       if ((theJob.JobStatus & PrintJobStatus.UserIntervention) == PrintJobStatus.UserIntervention)
                       {
                           strinstatus += "The printer needs human intervention.";
                       }

                   }
Ahad Porkar
  • 1,666
  • 2
  • 33
  • 68

0 Answers0