Link to home
Start Free TrialLog in
Avatar of CSecurity
CSecurityFlag for Iran, Islamic Republic of

asked on

C++ hook printed documents and save

I want a piece of code which will hook printer jobs, if a document was going to be printed, I want to save that as an image. How it is possible? I can hook printer jobs, but I want to see and save also document itself. Is it possible? Please advice.

Thanks from now!
Avatar of mannujam
mannujam

If You can Hook WritePrinter Api and Textout Api's for All system Calls , you can easily get the data which is going to Print and you can save it in any desired form.
You have to hook Pinter Api  -- WritePrinter  for Spoolsv.exe
But If User is printing through  windows application it will call
ExttextOutA/W, TextOutA/W  functions directly to Printer DC

Once You get the data you can save in your desired format
Avatar of CSecurity

ASKER

How about if I have a shared printer and a person sent it via share and send document to my printer to be printed?

Or

I print it to a remote printer?

Hooking WritePrinter will intercept both of these 2 methods?
here's a good article, it may not be explicitly relevant but should help in guiding you

http://www.thedbcommunity.com/index.php?option=com_content&task=view&id=218&Itemid=56
Thanks but I wasn't able to find any method for hooking Printer or getting document data of currently printing jobs
ASKER CERTIFIED SOLUTION
Avatar of mannujam
mannujam

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also  If someone is Printing  from remote computer  to your Pc(On which Printer is installed), Your spoolsv will be getting the data to Print. and it will be directed to WritePrinter.

If Print is going from Your PC to a network Printer, you will be getting two or three prints for the same document in Spoolsv, that is because of windows trying to send it across the network , but You will get only one StartDocPrinter and EndDocPrinter for corresponding printer.
Do you know any piece of code for hooking printer?
I can't give you a code now, but you can use MadHOOK and carry on your working.
The MadDLL helps you to make a hooking chain of API's .
You will find it here
http://www.madshi.net/madCodeHookDescription.htm