打印 WPF WebBrowser 的内容 [英] Printing the contents of a WPF WebBrowser

查看:29
本文介绍了打印 WPF WebBrowser 的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试打印 WPF WebBrowser 控件的内容,以便不显示打印对话框,但我没有运气.

I'm trying to print the contents of a WPF WebBrowser control so that no print dialog is shown, but am having no luck.

我已经尝试了以下方法并确信它确实有效:

I have tried the following and am sure it did work:

PrintDialog printDialog = new PrintDialog();
printDialog.PrintDocument(((IDocumentPaginatorSource)browser.Document).DocumentPaginator, "My App");

但由于某种原因,我现在收到以下异常:

but for some reason, I'm now getting the following exception:

无法将mshtml.HTMLDocumentClass"类型的 COM 对象转换为接口类型System.Windows.Documents.IDocumentPaginatorSource".此操作失败,因为 IID 为{2C0C27DF-282F-3225-ADCD-CEC68F890EEB}"的接口的 COM 组件上的 QueryInterface 调用因以下错误而失败:不支持此类接口(来自 HRESULT 的异常:0x80004002 (E_NOINTERFACE)).

我认为在我的 PC 上唯一改变的是自从我上次尝试之后我已经安装了 IE8,但这真的会破坏它吗?

The only thing I can think has changed on my PC is that I have installed IE8 since I last tried this, but would that really break it?

推荐答案

// Send the Print command to WebBrowser. For this code to work: add the Microsoft.mshtml .NET reference
mshtml.IHTMLDocument2 doc = WebBrowser1.Document as mshtml.IHTMLDocument2;
doc.execCommand("Print", true, null);

来源:http://social.msdn.microsoft.com/Forums/en/wpf/thread/63ae5345-b2ca-45a9-9113-0ddc43e9925b

这篇关于打印 WPF WebBrowser 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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