如何使用 shellexecute 将 HTML 文件打印到指定打印机?

发布于 2024-10-20 04:28:57 字数 726 浏览 1 评论 0原文

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

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

对于大多数文件类型,我可以模拟 shell 并执行与将文件拖放到资源管理器中的打印机上相同的操作,方法是使用“PrintTo”动词并使用 ShellExecute(通过 ProcessStartInfo) >);但是,我有一段时间一直想知道为什么这对 HTM 文件不起作用 - 相反,它总是提示为每个文件选择打印机,即使注册表设置似乎在那里。

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

现在,似乎这种行为是在 IE7 中引入的(无论是有意还是无意,我不确定);但有什么方法可以让它按预期工作吗?

编辑:这是一个内部应用程序,因此可以修复注册表如果可以工作。

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.

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.

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)

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?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风尘浪孓 2024-10-27 04:28:57

您可以使用网络浏览器控件并调用 .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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文