2013-08-23 15 views
7

मैं सी # में विंडोफॉर्म एप्लिकेशन विकसित कर रहा हूं।जांचें कि प्रिंट सफलतापूर्वक किया गया है

मेरे ऐप में, मैंने स्थानीय मशीन से सभी छवियां प्राप्त करने और इसे प्रिंट करने के लिए कोड नीचे लिखा है।

files = Directory.GetFiles(@"C:\temp", "*.jpeg"); 

     foreach (var i in files) 
     { 
      var objPrintDoc = new PrintDocument(); 
      objPrintDoc.PrintPage += (obj, eve) => 
      { 
       System.Drawing.Image img = System.Drawing.Image.FromFile(i); 
       Point loc = new Point(100, 100); 
       eve.Graphics.DrawImage(img, loc); 
      }; 
      objPrintDoc.Print(); 
     } 

अब मैं जाँच करने के लिए करता है, तो यह है कि प्रिंट सफलतापूर्वक या नहीं किया गया है चाहते हैं और फिर मैं मैं स्वयं बनाया है जो छवियों को स्टोर करने के अस्थायी फ़ोल्डर हटाना चाहते हैं।

मैंने कोड के नीचे कोशिश की है, लेकिन यह मेरे लिए काम नहीं करता है।

 PrintServer myPrintServer;      
     PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues(); 
     String printQueueNames = "My Print Queues:\n\n"; 
     foreach (PrintQueue pq in myPrintQueues) 
     { 
      printQueueNames += "\t" + pq.Name + "\n"; 
     } 

कृपया मुझे अपनी समस्या बताएं और आवश्यकतानुसार हमें बताएं।

धन्यवाद, प्रशांत

+1

_ लेकिन यह मेरे लिए काम नहीं करता है - यह कैसे काम नहीं करता है? –

+0

@AustinSalonen PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues(); – User5590

+0

_how_ से मेरा मतलब था कि आप क्या उम्मीद कर रहे हैं और आप क्या प्राप्त कर रहे हैं? –

उत्तर

3

यहाँ PrintSystemJobInfo.JobStatus

https://msdn.microsoft.com/en-us/library/system.printing.printsystemjobinfo.jobstatus(v=vs.110).aspx

के लिए एक MSDN वर्णन मैं निम्नलिखित कोड की कोशिश की और प्रिंट स्थिति को देखा है।

private void brnPrint_Click(object sender, EventArgs e) 
     { 
      var files = Directory.GetFiles(@"D:\Folder", "*.jpg"); 

      foreach (var i in files) 
      { 
       var objPrintDoc = new PrintDocument(); 
       objPrintDoc.PrintPage += (obj, eve) => 
        { 
         Image img = Image.FromFile(i); 
         Point loc = new Point(100, 100); 
         eve.Graphics.DrawImage(img, loc); 
        }; 

       objPrintDoc.Print(); 
       PrintServer myPrintServer = new PrintServer(@"\\ComputerName"); 
       PrintQueueCollection myPrintQueues = myPrintServer.GetPrintQueues();     
       try 
       { 
        foreach (PrintQueue pq in myPrintQueues) 
        { 
         pq.Refresh(); 
         PrintJobInfoCollection pCollection = pq.GetPrintJobInfoCollection(); 
         foreach (PrintSystemJobInfo job in pCollection) 
         { 
          listBox1.Items.Add(pq.Name); 
          SpotTroubleUsingJobAttributes(job); 
         } 

        } 
       } 
       catch (Exception) 
       { 
        //throw; 
       } 
      } 
     } 

     public void SpotTroubleUsingJobAttributes(PrintSystemJobInfo theJob) 
     { 
      if ((theJob.JobStatus & PrintJobStatus.Blocked) == PrintJobStatus.Blocked) 
      { 
       listBox1.Items.Add("The job is blocked."); 
      } 
      if (((theJob.JobStatus & PrintJobStatus.Completed) == PrintJobStatus.Completed) 
       || 
       ((theJob.JobStatus & PrintJobStatus.Printed) == PrintJobStatus.Printed)) 
      { 
       listBox1.Items.Add(
        "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)) 
      { 
       listBox1.Items.Add(
        "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) 
      { 
       listBox1.Items.Add("The job has errored."); 
      } 
      if ((theJob.JobStatus & PrintJobStatus.Offline) == PrintJobStatus.Offline) 
      { 
       listBox1.Items.Add("The printer is offline. Have user put it online with printer front panel."); 
      } 
      if ((theJob.JobStatus & PrintJobStatus.PaperOut) == PrintJobStatus.PaperOut) 
      { 
       listBox1.Items.Add("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) 
      { 
       listBox1.Items.Add("The job is printing now."); 
      } 
      if ((theJob.JobStatus & PrintJobStatus.Spooling) == PrintJobStatus.Spooling) 
      { 
       listBox1.Items.Add("The job is spooling now."); 
      } 
      if ((theJob.JobStatus & PrintJobStatus.UserIntervention) == PrintJobStatus.UserIntervention) 
      { 
       listBox1.Items.Add("The printer needs human intervention."); 
      } 

     } 
संबंधित मुद्दे