如何使用 shellexecute 将 HTML 文件打印到指定的打印机? [英] How can I print HTML files to a specified printer using shellexecute?

查看:146
本文介绍了如何使用 shellexecute 将 HTML 文件打印到指定的打印机?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,其中的记录可以有许多与之关联的附件,这些附件可能是 JPG、TIF、PDF 或 HTM 文件的集合(理论上这个列表是任意的,这些是最典型的类型).

I have an application that has records that can have a number of attachments associated to them, which may be a collection of JPG, TIF, PDF or HTM files (theoretically this list is arbitrary, and these are the most typical types).

我需要执行的操作之一是允许将这些批量打印到特定打印机.

One of the actions I need to be able to do is to allow these to be printed en mass to a specific printer.

对于大多数文件类型,我可以通过使用PrintTo"动词和使用 ShellExecute(通过 ProcessStartInfo);然而,我一直在挠头想知道为什么这对 HTM 文件不起作用 - 相反,它总是提示为每个文件选择一台打印机,即使注册表设置似乎已经存在.

For most file types, I can emulate the shell and perform the same action as had they dragged the file and dropped it onto a printer in explorer, by using the "PrintTo" verb, and using ShellExecute (via ProcessStartInfo); however, I've been scratching my head for a while wondering why this wasn't working for HTM files - instead it always prompts to select a printer for each file, even though the registry settings appear to be there for it.

这是当我回到第一原则,并检查 shell 的行为是否正确"时,当我发现它的行为方式相同时(因此,假设您将任何旧的 HTML 文件拖放到打印机中资源管理器,它总是提示打印,默认打印机为您的默认打印机,即使那不是您将文件拖放到的打印机)

It is when I went back to first principles, and checked to see if the shell behaves "properly" when I discovered that it behaves the same way (so, lets say you drag and drop any old HTML file onto a printer in explorer, it always prompts to print, defaulting the printer to be your default printer, even if that isn't the printer you dropped the file onto)

现在,它出现这种行为是在 IE7 中引入的(无论是有意还是无意,我都不确定);但是有没有办法让它按预期工作?

Now, it appears this behaviour was introduced in IE7 (whether intentionally, or not, I'm unsure); but is there any way of getting this to work as expected?

这是针对内部应用程序的,因此可以修复注册表如果可行.

This is for an internal application, so it would be permissible to fix up the registry if that would work.

推荐答案

您可以使用 webbrowser 控件并调用 .Print() 方法.我刚刚测试了它,它直接进入了我的默认打印机而没有提示我.我知道这可能不太理想,但我认为它应该可以完成工作.

You could use the webbrowser control and call the .Print() method. I just tested it and it went right to my default printer without prompting me. I know that might not be ideal, but I think it should get the job done.

这篇关于如何使用 shellexecute 将 HTML 文件打印到指定的打印机?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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