[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How do I get the total number of pages in a print job from Win32_PrintJob, including multiple copies?

Posted on 2005-05-03
15
Medium Priority
?
2,105 Views
Last Modified: 2007-12-19
I'm writing a Printer manager for my Internet cafe management software but unfortunately I've run into a brick wall.

Everything is working so far, my printer watch software written in Visual Basic happily picks up print jobs from the paused print queue. I can find the total number of pages of the document printed for everything I've tested so far. However, if I chose to print multiple copies of the same page, this seems to come up in the print job as only a single copy.

So for example if I type out a single line in notepad and print it, it will come out as 1 page on the print job and print out 1 page from the printer.

If I print out the same single line from notepad but set 'Copies' to 2, it still appears to be 1 page on the print job, but 2 pages will be printed out from the printer.

This is no good for me because I am still charging for only a single print when 2 copies have been printed!

My print watch software keeps the printer queue paused so I can't use 'PagesPrinted' even if it did provide the currect number of total pages printed.

Is there any way to find out how many copies were printed on a print job, as then I could just multiply 'TotalPages' by the number of copies to work out how many total pages there actually is.

The bit of code I'm using to look at print jobs is this:

Set colPrintJobs = objWMIService.ExecQuery ("Select * from Win32_PrintJob")
For Each objPrintJob in colPrintJobs
msgbox objPrintJob.TotalPages
Next objPrintJob

If I print out a single page document with copies set to 10, I want to know that 10 pages have been printed in total. Right now all I know is that a single page document has been printed but I can't see how many copies have been set.

None of the other columns on the Win32_PrintJob seem to show either the actual total number of pages or the number of copies - http://msdn.microsoft.com/library/en-us/wmisdk/wmi/win32_printjob.asp
0
Comment
Question by:HASujoy
  • 8
  • 3
  • 2
  • +2
15 Comments
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 13922522
0
 
LVL 4

Expert Comment

by:senthil_msv
ID: 13925330
0
 

Author Comment

by:HASujoy
ID: 13925720
Thanks for the links I'll try out the code in there. I hope that 'TotalPages' that these snippets provide is actually correct rather than the incorrect value I'm getting from Win32_PrintJob.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 2

Expert Comment

by:Merrion
ID: 13926589
The only way to get the true number of copies is to parse the print spool file.  This is bceasue some applications actually implement their own multi copy handling (especially MS Word) and therefore have to effectively lie to the print spooler...

I have written spool file parsing code for PCL, PostScript and EMF but they are part of a commercial product so I can't give you the code I'm afraid.
0
 

Author Comment

by:HASujoy
ID: 13927478
Is that Merrion from merrioncomputing.com? Because I read through the whole website when I was working out ways to capture printing information, a huge thankyou for all the effort you put in (if that's you!).

As for getting the true number of copies, I was crossing my fingers hoping it wasn't going to be a complex process. Life would be so much easier otherwise! Parsing the spool file would be over the top for my 'simple' program even if you could give me some pointers.

It's a bit of a shame because I've already written the print manager client and it works perfectly for reporting information back to my server, that then figures out who initiated the printing and triggers a question on their desktop asking how they want to pay - either from their credit or cash at the counter. It would save a huge amount of staff time at my Internet cafes. Without being able to accurately determine how many pages have been sent to print in a simple way it looks like I won't be able to automatically charge for printing.

If there is any other way you can think of to determine the number of pages being printed on a paused print queue It'd save my printer management module! I don't suppose 'PagesPrinted' on Win32_PrintJob is any different from 'TotalPages' - I noticed that it's 0 before printing has started, so I assume it just counts through as pages go to the Printer.
0
 

Author Comment

by:HASujoy
ID: 13927562
After I wrote that I just thought I'd rebrowse the merrioncomputing.com site. I found this page, will it work for finding the actual number of copies?

http://www.merrioncomputing.com/Download/PrintQueueWatch/PrinterQueueWatchPrintJobCopiestopic.htm
0
 

Author Comment

by:HASujoy
ID: 13927714
Ah I notice that it is a commercial product, however if it solves my problems that'd work for me.
0
 
LVL 2

Accepted Solution

by:
Merrion earned 2000 total points
ID: 13930858
(Yes - I am the developer behind the Merrion Computing products.)  

The print job copies returned in that topic is the same as you are getting but there is an asynchronous method "ParseSpoolfile" that parses the spoolfile and raises an "OnSpoolfileParsed" event that has the number of copies and pages etc.

This communicates with a service that runs on the print server and watches the spool file directory and takes a note of every new file that arrives.  It then parses the spool header file (*.shd) to find out what kind of data the spool file itself (*.spl) contains...the format of this header file is undocumented but I have reverse engineered it here: http://www.irishdev.com/blogs/merrion/archive/2005/01/29/447.aspx

Once you find out if it is a "RAW" file or an "EMF" file you need to parse it.  For RAW files you need to find out if they are PostScript, PCL, HPGL etc. as each is encoded differently.  For EMF files the format is simpler (but again undocumented).  I'll see if I have the formats to hand...

HTH,
  Duncan

0
 

Author Comment

by:HASujoy
ID: 13977449
Duncan I don't suppose you could confirm whether or not the PrintQueueWatch component on your website returns the accurate number of copies? I tried to email but the address from your website (from the licensing link) doesn't seem to be up-to-date!
0
 
LVL 29

Expert Comment

by:nffvrxqgrcfqvvc
ID: 13977536
HASujoy Doesn't the link I provide tell you how many pages are being printed. I have tested it and I believe it does.
0
 
LVL 2

Expert Comment

by:Merrion
ID: 13977625
I am putting together a trial version of the latest component which _does_ return the correct number of copies, when you call ParseSpoolfile for the job.  

There is a write up of the EMF spoolfile format that I have put up here: http://www.irishdev.com/blogs/merrion/archive/2005/05/05/701.aspx

0
 

Author Comment

by:HASujoy
ID: 13978888
Hi egl1044,

It's a bit lax of me but I didn't try that piece of code after reading Merrion's information. However to be thorough I'll try now and respond. Thanks.

Sujoy
0
 

Author Comment

by:HASujoy
ID: 13979221
Ok egl1044, I just tried that example and exactly the same thing happens as with the code I pasted above. The number of pages reported is always wrong when you have multiple copies. If I write a single line in notepad and print a hundred copies, it is reported as a single page printed. This is no use to me unfortunately and is the basis of my original question.

Did you have a different experience with the code on that Microsoft page? Try printing multiple copies of anything and see if the total number of pages reported is correct?
0
 

Author Comment

by:HASujoy
ID: 13979238
Merrion it sounds like the best thing for me to do is standby for your component. I'll check your blog updates for more info. If you release a component that can capture print jobs correctly I, and I'm sure many others, will be happy to pay a (small) license fee to use it!
0
 

Expert Comment

by:nbarasa
ID: 20418485
Dear HASujoy,

I have had the same problem for years now. My code counts pages and not copies. Unfortunately I don't seem to understand the accepted solution above. Kindly help me with the printing code so that I can have an accurate solution. I also have a cyber software and I still program in VB 6.

Your help will be really appreciated.

Regards

ABN
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month18 days, 23 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question