Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser print settings

How ca i change my html document orientation(to Landscape) for printing using WebBrowser control.

var browser = new WebBrowser();
browser.DocumentCompleted += (sender, args) =>
    {
        var ws = sender as WebBrowser;
        //change paper size and orientation
        ws.Print();
    };
browser.Navigate(path);

I need to change paper size format to C5 and orientation to Landscape before printing. How can i do this without any dialogs?

like image 309
Dzmitry Martavoi Avatar asked Sep 30 '13 15:09

Dzmitry Martavoi


People also ask

How do I print from my Web browser?

2. Press Ctrl + A 3. Right click on the page and left click on “Print” 4. Press the “Print” button.

How do I print part of a web page?

Only Print Text You Highlight on a Page Now in your browser go to File > Print or simply use the Ctrl + P keyboard combination. The Print screen comes up. Select the Printer you want to use. Then under “Print Rage” check the Selection box and click OK.

How do I print a selected frame in edge?

Right-click the selected text and then select Print in the context menu. Choose the print options you want and then select Print.


1 Answers

To control HTML printing layout beyond @media CSS with WebBrowser (both WinForms and WPF), you would need to implement your own Internet Explorer Print Template. That would provide full control over headers, margins, columns, etc.

Specifically, you're after TemplatePrinter.orientation. It isn't properly documented, but it works. The source of the standard IE print template can be viewed when navigated to res://ieframe.dll/preview.dlg.

Some other relevant resources:

  • Beyond Print Preview: Print Customization for Internet Explorer 5.5
  • Print Preview 2: The Continuing Adventures of Internet Explorer 5.5 Print Customization
  • Print Templates, Part I
  • View templates for HTML source documents
  • Demystifying printing with the Microsoft WebBrowser control and ShowHTMLDialogEx
  • Add support to print & preview HTML in a dialog-based MFC app
  • IDM_PRINT
  • IDM_PRINTPREVIEW
  • MSKB: How to print custom headers and footers for a WebBrowser control in Internet Explorer
like image 182
noseratio Avatar answered Sep 30 '22 17:09

noseratio