How to listen to printing jobs in java

蓝咒 提交于 2019-12-23 02:59:15

问题


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

  1. Click Start, click Run, type regedit in the open box, and then click OK.

  2. 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.

  3. 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.

  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!