如何将打印机驱动器转换为一个独立的控制台应用程序可生成包含字节被发送到打印机的打印机文件? [英] How to convert a printer driver to a stand-alone console application which can generate a printer file containing the bytes to be sent to the printer?

查看:577
本文介绍了如何将打印机驱动器转换为一个独立的控制台应用程序可生成包含字节被发送到打印机的打印机文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一种情况,其中的只有的方式来产生一定的数据文件是手动打印到文件:Windows下并将其保存在作进一步处理的文件

I have a situation where the only way to generate a certain datafile is to print it manually to FILE: under Windows and save it in a file for further processing.

我真的想有一个小的独立的程序中嵌入该二进制打印机驱动程序,这样我就可以从一个批处理文件运行它,并将它生成我的二进制文件,我们就可以完全自动化保存文件在Visio,打印,并把它上传到最终目的地并触发远程测试。

I would really like to have a small stand-alone program which embeds this binary printer driver so I can run it from a batch file and have it generate that binary file for me, as we can then fully automate the "save file in Visio, 'print' it and upload it to the final destination and trigger a remote test".

这可能与一个合适的Windows SDK?我是一个Java程序员,所以我不知道Visual Studio和MSDN与可能性 - 但! - 但我会很感激的指针

Is this possible with a suitable Windows SDK? I am a Java programmer, so I do not know Visual Studio and the possibilities with MSDN - yet! - but I'd appreciate pointers.

编辑:我已经为打印机驱动程序安装文件,32和64位。 。旧版本可能包含一个16位驱动程序

I have the installation files for that printer driver, both 32 and 64 bit. Older versions may include a 16 bit driver.

编辑:打印到文件功能建议正是通过文档。我打一点点与使用LPR协议,看看有什么可以做。我还是比较喜欢援引小二的方式。

The "print to FILE:" functionality is just what was recommended by the documentation. I have played a little bit with using the LPR-protocol to see what it can do. I'd still prefer the "invoke small binary" approach.

推荐答案

您制定是难以解决的普遍问题。晴打印机驱动程序由来自像打印监视器,打印处理器等一些知名的组件,这些组件的驱动程序开发工具包的 http://msdn.microsoft.com/en-us/library/ff560885%28v=VS.85%29.aspx 。几年前,我写了一个打印监视器。它工作多年的客户。所以我确切地知道我写。打印监视器无非是与有据可查的功能的DLL。同样是对大多数其它打印机组件。这些DLL将被加载,并从后台处理程序调用。如果你有一个现代化的打印机驱动程序,它具有在内核模式下运行的任何组件。因此,可以加载大多数的DLL从由每个打印机驱动程序并调用相应的功能

The general problem which you formulate is difficult to solve. Mostly a printer driver consists from some well known components like Print Monitor, Print Processor etc. which are well documented in Windows Driver Kit http://msdn.microsoft.com/en-us/library/ff560885%28v=VS.85%29.aspx. Some years ago I wrote a Print Monitor. It worked many years at a customer. So I know exactly what I writing about. A Print Monitor is nothing more as a DLL with well documented functions. The same is about most other printer components. Those DLLs will be loaded and called from Spooler. If you have a modern printer driver it has no components which run in kernel mode. So one can load most of DLLs from which consist every printer driver and call corresponding function.

您是使用有趣的一场音乐会打印机驱动程序即可。因此,第一个什么人应该做的是检查如何此驱动程序实现的。如果你发现哪个组件做您需要的工作,你很可能是能够加载在这个过程中DLL并生产出您需要的输出。您发布的URL在哪里可以下载此驱动程序有可能

You are interesting for using one concert printer driver. So the first what one should do is to examine how this driver is implemented. If you find out which component do the job which you need, you will be probably able to load this DLL in your process and produce output which you need. It is possible that you post an URL where I could download this driver?

更新时间::我虽然有点更多关于您的要求。在我看来,你可以与打印机驱动程序的开发者建议的方式去。如果驱动程序打印到本地端口文件,然后就可以在任何打印机端口打印。所以,你可以给从C端口监视器Server驱动程序的源:\WinDDK\7600.16385.1\src\print\monitors\localmon(见的 http://msdn.microsoft.com/en-us/library/ff556478%28v=VS.85%29.aspx http://msdn.microsoft.com/en-us /library/ff549405%28v=VS.85%29.aspx 并的 http://msdn.microsoft.com/en-us/library/ff563806%28v=VS.85%29.aspx )。 (我是一个Windows 32/64 DLL,而不是一个真正的驱动程序),使小的修改。相反结果保存到一个文件,你可以调度结果给应用程序。这将是100%的工作没有任何技巧。如果你将有一些问题了解的 localmon 我可以给你一些提示。这实在是不复杂的。你所要做的主要变化是修改 LcmStartDocPort LcmWritePort LcmReadPort LcmEndDocPort 功能从 localmon.c 。一些简单的事情这是一个典型的DLL区分端口DLL,那而不是出口的所有DLL的功能,它的指针出口只有一个 InitializePrintMonitor2 来的所有其他职能。

UPDATED: I though a little more about your requirements. It seems to me you can goes with the way suggested by developer of the printer driver. If the driver can print to a local port FILE, then it can print in any printer port. So you can give src of a Port Monitor Server driver from C:\WinDDK\7600.16385.1\src\print\monitors\localmon (see also http://msdn.microsoft.com/en-us/library/ff556478%28v=VS.85%29.aspx, http://msdn.microsoft.com/en-us/library/ff549405%28v=VS.85%29.aspx and http://msdn.microsoft.com/en-us/library/ff563806%28v=VS.85%29.aspx). (I is a windows 32/64 DLL, not a real driver) and makes small modification. Instead of saving results to a file you can dispatch the results to your application. It will be work with 100% without any tricks. If you will have some problem to understand localmon I can give you some tips. It is really not complex. The main changes which you have to do is to modify LcmStartDocPort LcmWritePort LcmReadPort LcmEndDocPort functions from localmon.c. Some easy thing which is distinguish Port DLL from a typical DLL, that instead of exporting all DLL's functions it export only one InitializePrintMonitor2 with pointers to all other functions.

更新2 :对于本地端口显示器的使用另外一个技巧。如果打印机配置的推移,然后选择添加端口...,选择本地端口,然后点击新端口...,你可以象任何文件名C:\temp\my.bin。然后,所有通过打印机打印的内容将在此文件进行打印,无需任何用户迭代。名称可以是的任何 Win32文件名(UNC名称或命名管道也是允许的)。随着这种方式可以实现一些方案,而不会DDK的编程

UPDATED 2: One more tip for usage of "Local Port" monitor. If goes in printer configuration, then choose "Add Port...", select "Local Port" and click "New Port..." you can type any file name like "C:\temp\my.bin". Then all what you print through a printer will be printed in this file without any user iteration. The name can be any win32 file name (UNC names or Named pipes are also allowed). With this way you can realize some scenarios without any programming with DDK.

更新1 :我看了一下从不同的侧面打印机驱动程序,并期待一个更多的时间在DDK中的API中。现在我想推荐你选择了最简单的方法,以及将来自驱动制造商完全支持的方式。我建议如下:

UPDATED 3: I looked at the printer driver from different sides and looked one more time in the API in DDK. Now I want recommend you to choose the easiest way, and the way which will be full supported from the driver manufacturer. I suggest following:

您安装一台打印机与您所需要的驱动程序,并选择作为输出端口的本地端口的一个固定的文件名(请参阅更新2)。我这里命名为目标文件名作为的 C:\TEMP\Output.afp 的。所以,您会收到完全相同的情况类似建议您驱动程序制造商。固定文件名为绝对一样的文件:端口。所以,如果你打印到打印机你的 Output.afp 的接收文件中的 C:\TEMP 的目录中。可以肯定的编写可以使用的最后 ReadDirectoryChangesW FindNextChangeNotification / FindFirstChangeNotification dwNotifyFilter 功能>等于 FILE_NOTIFY_CHANGE_LAST_WRITE FILECLOSE 和之后的缓存足够刷新手段。因此,文件的 Output.afp 的未锁定,你才能真正安全的读取结果。

You install a printer with the driver which you need and choose as the output port a Local Port with a fixed file name (see Update 2). I named here the destination filename as C:\TEMP\Output.afp. So you receive exactly the same situation like recommend you driver manufacturer. Fixed file name is absolutely the same as FILE: port. So if you print to the printer you receive in Output.afp file in the C:\TEMP directory. To be sure the end of writing you can use ReadDirectoryChangesW or FindNextChangeNotification / FindFirstChangeNotification functions with dwNotifyFilter equal to FILE_NOTIFY_CHANGE_LAST_WRITE. Then you receive notification after last write-time of the file. It means after the end of writing and after FileClose and after the cache is sufficiently flushed. So the file Output.afp is not locked and you can really safe read the results.

有关简单文档,您可以使用<印刷code> WritePrinter 功能(请参见的http:/ /msdn.microsoft.com/en-us/library/dd162959%28VS.85%29.aspx 以及备注的文档的 http://msdn.microsoft.com/en-us/library/dd145226%28VS.85%29.aspx )。与位图,颜色和不同的字体复杂的文件写你必须使用GDI典型API如同在Windows中之一时,此(见的 http://msdn.microsoft.com/en-us/library/dd162865%28v=VS.85%29.aspx )。

For printing of simple documents you can use WritePrinter function (see http://msdn.microsoft.com/en-us/library/dd162959%28VS.85%29.aspx and remark in the documentation http://msdn.microsoft.com/en-us/library/dd145226%28VS.85%29.aspx). Writing of complex files with bitmaps, color and different fonts you have to use typical GDI API like one this in Windows (see http://msdn.microsoft.com/en-us/library/dd162865%28v=VS.85%29.aspx).

这解决方案看起来不像写的打印机驱动程序组件或后台打印环境的打印机驱动程序模拟很壮观,但它会工作,将安全工作,将全面从驱动器制造商的支持。

This solution looks not very spectacular like writing a printer driver component or a simulation of spooler environment for printer driver, but it will work, will safe work and will be full supported from the driver manufacturer.

这篇关于如何将打印机驱动器转换为一个独立的控制台应用程序可生成包含字节被发送到打印机的打印机文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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