Printing the contents of a WPF WebBrowser

后端 未结 3 1706
北恋
北恋 2020-12-17 07:19

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

3条回答
  •  感动是毒
    2020-12-17 07:56

    To avoid taking a dependency on MSHTML you can simply do:

    browser.InvokeScript("execScript", new object[] { "window.print();", "JavaScript" });
    

    I devised the above solution when I was having trouble with a WPF project that was migrated to .Net Core 3 and was using Tony's answer that involves MSHTML reference. Referencing MSHTML in .Net Core is not very straightforward (see this github issue)

提交回复
热议问题