Printing In Landscape mode from a WebBrowser control?

假如想象 提交于 2019-12-12 12:45:57

问题


System.Windows.Forms.WebBrowser wb = new System.Windows.Forms.WebBrowser();

wb.DocumentStream = new FileStream("C:\a.html", FileMode.Open, FileAccess.Read);
while (wb.ReadyState != WebBrowserReadyState.Complete)
{
    Application.DoEvents();
}
wb.Print();

I know how to set the page orientation from a PrinterDocument object, but not from a WebBrowser object. Any way to do this? Thanks!


回答1:


First, I recommend you to use async event model:

wb.DocumentCompleted += wb_DocumentCompleted;

private void wb_DocumentCompleted (object sender, WebBrowserDocumentCompletedEventArgs e)
{
    ((WebBrowser)sender).Print();
}

To print (add the reference to Microsoft.mshtml.dll):

mshtml.IHTMLDocument2 doc = wb.Document.DomDocument as mshtml.IHTMLDocument2;
doc.execCommand("print", showUI, templatePath);

See IHTMLDocument2.execCommand, MSDN forum question and follow links.



来源:https://stackoverflow.com/questions/4970377/printing-in-landscape-mode-from-a-webbrowser-control

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