sooprise
sooprise

Reputation: 23187

Printing In Landscape mode from a 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? Thanks!

Upvotes: 3

Views: 3786

Answers (1)

abatishchev
abatishchev

Reputation: 100348

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.

Upvotes: 4

Related Questions