locked
Get Number of Pages and Number of Pages Printed(System.Printing) RRS feed

  • Question

  • Please i have this program which records the every printing made on a local computer.I am to record the number of pages of the document to be printed and the number of printed pages
    i have this code but i don't know

    the number of pages and number printed pages always return 0
    Please help me fix this thank you

      defaultPrintQueue2 = LocalPrintServer.GetDefaultPrintQueue()
        Dim jobs As PrintJobInfoCollection = defaultPrintQueue2.GetPrintJobInfoCollection
        For Each job As PrintSystemJobInfo In jobs
          If (Not ht2.Contains(job.JobIdentifier)) Then
            If (Not ht1.Contains(job.JobIdentifier)) Then
              ht1.Add(job.JobIdentifier, job.Name)
              If Me.lblRealName.Text = String.Empty Then
                job.Cancel()
                MessageBox.Show("Please you need to login into JsPrintMonitor before you can print", "Print Command Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
    
                'Cancel Submitted print command
                Exit Sub
              End If
              Dim printer As New PrinterSettings
              Dim ptName As String = printer.PrinterName
              printer.PrinterName = ptName
              If printer.IsValid Then
                PrinterName = ptName
              End If
              ' MessageBox.Show(job.JobIdentifier.ToString & job.Name & vbNewLine)
    'This is my class instantiation which contains a function called RecordPrintActivity
            'but the job.Numberofpages and Job.numberofpagesprinted returns 0 all the time  
     ClassInstance.RecordPrintActivity(job.Submitter, job.Name, DateTime.Now, job.NumberOfPages, job.NumberOfPagesPrinted, Me.lblRealName.Text, PrinterName.ToString, job.JobIdentifier)
              job.Pause()
            End If
          End If
        Next
    
    Wednesday, July 13, 2011 11:54 AM

Answers