2

I've written an Excel add-in in C#.NET. When ever the user opens and Excel workbook and give a print on a worksheet, the excel does the print. There is only one notification that is raised by the excel, that is the AppEvents.Workbbok_BeforePrint() event. After that there is no events generated for each page before the page is printed.

I've analysed ways to receive notification from excel side. But could not find one. Then i tried the option to receive notifications from the printer/print spooler. How can i get notification from the printer/print spooler, so that i receive notification for every page that is printed.

Please help me out in this.

Thanks and Regards, Sundareswaran Senthilvel

Danubian Sailor
  • 1
  • 38
  • 145
  • 223
Eshwar
  • 37
  • 1
  • 6

1 Answers1

0

This is difficult to do, especially if there aren't a lot of pages in the print job. It's probably more work than it's worth. :)

You can do it, however, using the WinAPI functions EnumJobs and GetJob.

Call OpenPrinter to get a printer handle.

Call GetPrinter with level 2 to find out the number of jobs.

Call EnumJobs. Examine the JOB_INFO_1, JOB_INFO_2, or JOB_INFO_3 (depending on what information you asked for - links on the other pages above to these structures and what they tell you) until you find the print job from Excel.

Call GetJob using that JobID to get information on the current status of the print operation.

Ken White
  • 123,280
  • 14
  • 225
  • 444
  • Hi Ken, Thanks for your reply. i have come across .NET PrintDocument class where we can set the handlers for the event. – Eshwar Jul 23 '11 at 18:19