How can I print HTML files to a specified printer using shellexecute?

可紊 提交于 2019-12-11 07:32:15

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/5184262/how-can-i-print-html-files-to-a-specified-printer-using-shellexecute

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