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:
- 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
Author by
Dzmitry Martavoi
Updated on June 04, 2022Comments
-
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 over 8 yearsThanks 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 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 over 8 yearsOh, 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 over 8 yearsI 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