Hi
I am using C# WPF webbrowser control to show html file in my local machine, I added a print feature to my application by executing print command of webbrowser control, but default behavior of Internet Explorer is to print file url in the bottom of the screen , can I turn header and footer printing for my control? Have WebBrowser control ability to print preview? Sometimes printed page is cut, can someone help to understand what is the problem.
Thanks a lot!!!
Asked
Active
Viewed 9,009 times
4

Arsen Mkrtchyan
- 49,896
- 32
- 148
- 184
-
I found a way around the cut offs: http://www.hackviking.com/2014/01/net-c-webbrowser-control-print-line-break/ – Kristofer Källsbo Jan 15 '14 at 23:08
1 Answers
16
I did it once (sorry, I don't have the application code now), and I did it playing with the register: check this MS article.
I advice you to store somewhere the current values of the keys and restore them after you're done printing.
EDIT
string keyName = @"Software\Microsoft\Internet Explorer\PageSetup";
using (RegistryKey key = Registry.CurrentUser.OpenSubKey(keyName, true)) {
if (key != null) {
string old_footer = key.GetValue("footer");
string old_header = key.GetValue("header");
key.SetValue("footer", "");
key.SetValue("header", "");
Print();
key.SetValue("footer", old_footer);
key.SetValue("header", old_header);
}
}
About pages being cut
I'm not sure if I understood correctly what the problem is... in the application I was talking about before, I had the problem of tables being cut in half, so I played with CSS break after property (see also break before) to force page breaks, specifying special styles for the printer media. Hope this helps...

Andrea Antonangeli
- 1,242
- 1
- 21
- 32

Paolo Tedesco
- 55,237
- 33
- 144
- 193
-
-
I added source that change registry values, may be someone will need it, thanks a lot your post is helpful, but the page is cut in some printers yet, can you help me with this? – Arsen Mkrtchyan Aug 24 '09 at 10:26
-
I modified your edit to restore the previous values as I had suggested :) What's the problem with the page being cut, exactly? – Paolo Tedesco Aug 24 '09 at 10:46
-
ok, thanks for modification, I don't know why printed text is cut, half of top and bottom lines are not shown in the printed page, when I print to tiff file the lines are cut, when xps file the page is printed normally, Thanks for help – Arsen Mkrtchyan Aug 24 '09 at 11:00
-
I for some reason get old_footer does not exist in the current context? – Trent Stewart Jan 13 '14 at 06:33
-
I had to take all the variables like old_footer and old_header and make them gloabl for some strange reason. Oh well seems to work. – Trent Stewart Jan 13 '14 at 06:34
-
@PaoloTedesco: This is a very bad solution. IE control prints asynchronously so by the type Print() function returns the printing may not be finished by the IE control, thus when you reset those global registry settings it may appear like nothing has been done. Unfortunately, I don't have a working solution (yet.) But this one is a bad one. Don't use it. – c00000fd Mar 07 '19 at 06:49