Click here to Skip to main content
15,895,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi .
I need a code to check the printer papers out.
for example i print a text document it will 3 page(s), now how can i fount this "3 page(s)" in a windows application?
tnx all.
Posted

You need to be able to inspect printers/queues etc at a low level

Here's some link's that "may" help you get started

http://support.microsoft.com/kb/202480[^]

http://support.microsoft.com/kb/228769/EN-US[^]

They may not be in vb.net sorry, but show you the sorts of things you may have to do
 
Share this answer
 
Comments
Rad.Application 3-Dec-12 11:29am    
my application does not print anything . print statement come from other programs . i need to enumeration the paper printed :)
As this is a System.Windows.Forms application, normally you need to use the class System.Drawing.Printing.PrintDocument: http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^].

Now, look at the small code sample at the end. It should how to print, and, in particular, how to print a page by adding a handler to the invocation list of the event System.Drawing.Printing.PrintDocument.PrintPage, see http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.aspx[^].

Add some counter in the implementation of the handler; and you are done:
C#
void PrintADocument(SomeData someData /* ... */) {
   // ...
   PrintDocument pd = new PrintDocument();
   uint pageCount = 0;
   pd.PrintPage += (sender, eventArgs) { // in lambda form, exact types of the parameters can be
                                         // inferred from the event type
      System.Drawing.Graphics graphics  = eventArgs.Graphics; // see the link above
      RenderThePageUsingTheInstanceOfGraphics(graphics, someData);
            // whatever you want to render on this page
      pageCount++;
   }; // pd.PrintPage handle
   pd.Print();
   // at this moment, you know how many pages are printed, read pageCount 
   // ...
} //PrintADocument


In this code, I also used an interesting feature, related to anonymous methods and the use of the stack variable pageCount, called closure. This is interesting enough to learn.
http://en.wikipedia.org/wiki/Closure_%28computer_science%29[^],
http://en.wikipedia.org/wiki/Anonymous_method[^],
http://en.wikipedia.org/wiki/Anonymous_method#C.23_lambda_expressions[^].

—SA
 
Share this answer
 
v2
Comments
Rad.Application 3-Dec-12 11:28am    
my application does not print anything . print statement come from other programs . i need to enumeration the paper printed
:)
Sergey Alexandrovich Kryukov 3-Dec-12 12:40pm    
Then the other program should do it; or, why not printing from your code? Isn't it logical? Whoever is printing, counts the pages. If you need something else, you need to share information on your design, and -- importantly -- motivate it, explain your ultimate goals. How about this route?
--SA
Garth J Lancaster 3-Dec-12 18:29pm    
you can still monitor print jobs/queues etc they are global to your machine - but as Sergey said, ideally whoever is doing printing should count the pages - and yes, you havnt given us enough real information
Rad.Application 3-Dec-12 21:22pm    
I wrote a coffee net manager last year . My customer has a shared printer on his network, now he want to know each client how many paper printed .
i have no idea , my English is not good too. my bad , sorry for this.
Sergey Alexandrovich Kryukov 3-Dec-12 21:53pm    
Listen to a good advise, do it in civilized way...
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900