如何在java中监听打印作业 [英] How to listen to printing jobs in java

查看:1032
本文介绍了如何在java中监听打印作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何查看在Java应用程序中将任何其他应用程序(Word,Excel,PDF阅读器)发送到打印机的打印详细信息。这意味着,用户可以从一台PC向打印机发送各种类型的文档。



我的Java应用程序必须计算发送给打印机的文档数量。



如何在Java SE应用程序中获取这些详细信息?任何资源,有用的链接,指导高度赞赏。

解决方案

这不能直接使用Java完成,但有一种解决方法。



对于每个打印作业,Windows后台打印程序服务生成两个假脱机文件。



一个文件的作业设置的 .SHD 扩展名,以及的扩展名。 SPL 绘图命令的扩展名。



这些文件可以基于每台打印机存储在用户定义的位置。所有假脱机程序作业的默认位置是 c:\windows \ system32 \spool \ PRINTERS



基于每台打印机设置位置


  1. 单击开始,单击运行,键入 regedit 在打开的框中,然后单击
    确定。


  2. 找到以下注册表子项,其中< printername> 是打印机的
    名称:



    HKEY_LOCAL_MACHINE\SOFTWARE \\ \\ Microsoft \ Windows \\ n $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ code> SpoolDirectory ,然后单击修改。


  3. 在数值数据框中,键入要放置假脱机的位置要存储的文件。
    例如,键入 c:\windows \ system32 \spool \ printers 作为默认的
    位置。


  4. 退出注册表编辑器。重新启动后台打印程序服务。


所有新作业的格式为 XXXXX.SPL XXXXX.SHD 并且将与其JobID一致编号。



使用Java您可以监视此文件夹以查找发送到打印机服务或特定打印机的新作业。


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.

解决方案

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.

这篇关于如何在java中监听打印作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆