问题
I want to know how to see get the printing details which any other application (Word, Excel, PDF readers) sent to the printer in a Java application. That means, the user send various types of documents to printers from one PC.
My Java application must count how many documents sent to printers.
How can I get these details in a Java SE application? Any resource, useful link, guidance highly appreciated.
回答1:
This cannot be directly done using Java but there is a workaround.
For each print job there are two spool files generated by the Windows spooler service.
One file with the .SHD
extension for job settings, and one with the .SPL
extension for the drawing commands.
These files could be stored in a user defined location on a per-printer basis. The default location for all spooler jobs is c:\windows\system32\spool\PRINTERS
.
To set location on a per-printer basis
Click Start, click Run, type
regedit
in the open box, and then click OK.Locate the following registry subkey, where
<printername>
is the name of your printer:HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\
In the right pane, right-click
SpoolDirectory
, and then click Modify.In the Value data box, type the location where you want the spool files to be stored. For example, type
c:\windows\system32\spool\printers
as the default location.Quit Registry Editor. Restart the Print Spooler service.
All new jobs will be of the form XXXXX.SPL
and XXXXX.SHD
and will be numbered consistently with their JobIDs.
Using Java you could monitor this folder for new jobs being sent to the printer service or to a particular printer.
来源:https://stackoverflow.com/questions/8913089/how-to-listen-to-printing-jobs-in-java