Printing in landscape mode using the WebBrowser control?

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? Thank!

+3
source share
1 answer

First, I recommend using an asynchronous event model:

wb.DocumentCompleted += wb_DocumentCompleted;

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

To print (add a link 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 the links.

+4
source

Source: https://habr.com/ru/post/1791509/


All Articles