How do I print from the wpf WebBrowser available in .net 3.5 SP1?

喜夏-厌秋 提交于 2019-12-24 00:37:25

问题


we are currently using a winforms WebBrowser control in our app in a WindowsFormsHost and printing by calling 'WebBrowser.ShowPrintDialog()' We have an issue with this in that the dialog does not appear to be modal and the parent window can be dismissed causing issues if a print is later attempted.

I was looking at the new wpf webbrowser control in the hope that they will have fixed this issue when doing a similar thing themselves, but can find no way to print from it..

I found someone online talking of doing this:

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

but this throws an exception as the WebBrowser.Document does not support the IDocumentPaginatorSource interface.

Is there any way I can print from the wpf web browser control?

thanks


回答1:


I am using this, and it works:

    mshtml.IHTMLDocument2 doc = webBrowser.Document as mshtml.IHTMLDocument2;
    doc.execCommand("Print", true, null);


来源:https://stackoverflow.com/questions/798494/how-do-i-print-from-the-wpf-webbrowser-available-in-net-3-5-sp1

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