WebBrowser print settings

12,520

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:

Share:
12,520
Dzmitry Martavoi
Author by

Dzmitry Martavoi

Updated on June 04, 2022

Comments

  • Dzmitry Martavoi
    Dzmitry Martavoi almost 2 years

    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?

  • c00000fd
    c00000fd over 8 years
    Thanks for this link: support.microsoft.com/en-us/kb/267240 You seem to know quite a lot about printing from IE. So do you know -- that link actually contradicts this one: support.microsoft.com/en-us/kb/236777 that basically says that there's no way to change footer/header in IE programmatically. So I'm curious, since the first page clearly shows how to do it, is there a way to also: A) Change page margins, and B) Specify printer when using OLECMDEXECOPT_DONTPROMPTUSER?
  • noseratio
    noseratio over 8 years
    @c00000fd, A and B are possible not so straightforward. You'd need to roll put your own print template - check the other links, particularly this.
  • c00000fd
    c00000fd over 8 years
    Oh, man, Delphi. People still use it? Any C/C++ (or at least C#) links in your arsenal? I'm basically looking to allow printing from WebControl to allow print customization from within the program (w/o user interface from IE.) And that stuff is so undocumented...
  • noseratio
    noseratio over 8 years
    I don't have any C++ code I could post here. To an extent, this stuff is documented: msdn.microsoft.com/en-us/library/aa753358(v=vs.85).aspx