Getting TotalPages on JobAdded

Topics: Developer Forum
Nov 8, 2007 at 9:48 AM
Edited Nov 8, 2007 at 9:54 AM
Hi everyone.

i have this issue with the PrintQueueWatch component.
everything works great except for the TotalPages property of the job on the JobAdded event.

it always return 1 or 0.
usually (and for a strange reason i don't understand ....) i get 1 on the first attempt to print (after the service is started) and 0 on the next prints...

i have this service that is running and whenever a job is added i want to check the pages the user is printing.
i wanto to see if the user has enough money to print these pages, so i can cancel the job if the user doesn't have enough money.

please do help. i'm really having trouble with this.
Feb 26, 2008 at 12:26 PM

In the JobAdded event the printer does not yet know how many pages will be in the print job. A more accurate count can be found in the JobWritten event where PrintJob.Spooled = True because at this point all the pages have been sent for printing.
Feb 27, 2008 at 8:24 AM
Hi. Thank you so much for answering.
That's correct but i have a problem with that. i need to know if the user has enough money to print the total number of pages, before printing, so that i can cancel the print job.
on the job written i will not be able to cancel the printjob right?

i have even tryied pausing the printjob on jobadded, but it seems that on jobs as little as 1 or 2 pages the spooler does not have enough time to pause. when the pause order is given, the job has already been written.

can you please help? i can't seem to figure out a way to do this.

Thank You.
Feb 27, 2008 at 12:09 PM
There is a property - PauseAllNewJobs - you can set to automagically pause any new jobs as they are added.
( )
Feb 27, 2008 at 11:31 PM
Hello! You've been the greatest help.
Thank you so much.

if i can put another question, i noticed the total pages and copies only get updated by going through some jobset events.
is there anyway i can tell the job set events are over? as i told you i need to know all the pages and copies before unpausing the job. but those are not set at once. those are set in several jobset events, depending on the number of copies or pages....

again, thank you!
Feb 28, 2008 at 2:05 PM
When the .Spooled property of the PrintJob in a given JobWritten event is True it means the application has no more information to put in the spool file. At this point I would expect the number of pages and copies to be correct.

Feb 29, 2008 at 9:11 AM

i can't find a spooled property.

i can only find a spooling property for print jobs. is this normal??

Thank you.
Mar 2, 2008 at 3:50 PM
Sorry - my mistake. I meant when the .Spooling property becomes false then the job is spooled...
Mar 29, 2010 at 8:29 PM


I am in the same situation where i want to calculate pages against balance for students before the ptinjob is printed.

So i did try the PauseAllNewJobs and it works ok.

The printjob is paused and i can do the calculation.

The problem is when to release the printjob on the fly.

Some printjobs are never released(resumed) and a manually release of printjob is required.

See the sub below how i did.

Private Sub pPrinter_JobAdded(ByVal sender As Object, ByVal e As PrinterQueueWatch.PrintJobEventArgs) Handles pPrinter.JobAdded
e.printjob.paused = True
do calulation
e.printjob.paused = false
End sub

Anyone has an idea how to correct this?



Apr 6, 2010 at 8:43 PM

Ideally your calculation and unpausing the job should be done asynchronously by using another thread in order to exit the event as soon as possible.

Have a look at the .NET help for e.g. BeginInvoke