问题
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