Need advice on removing header/footer during HTML printing

FalconDEW

Freshman
Joined
Sep 18, 2003
Messages
42
I have the IE web control in my app - and I'm using the EXECWB command to print the current page. However, I'm trying to remove the header / footer that is automatically placed on the page.

The only real way I've found to do this so far is by modifying the registry. I'm concerned that my method for doing this will restrict my program if being used by a person with restricted access to a machine (i.e. can't write to the registery).

Any thoughts on whether or not this method is a bad/sloppy way of doing this, or if there is a better/cleaner method? Let me know!

Code:
Dim IERegKey As RegistryKey
Dim header, footer As String

IERegKey = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", True)

footer = RegValue.GetValue("footer", 0)
header = RegValue.GetValue("header", 0)

IERegKey.SetValue("footer", "")
IERegKey.SetValue("header", "")

AxWebBrowser1.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DODEFAULT)

' Reset the values after printing is completed
'IERegKey.SetValue("footer", footer)
'IERegKey.SetValue("header", header)

-Falcon
 
From http://support.microsoft.com/default.aspx?scid=kb;EN-US;311280

Users can easily change Internet Explorer printer settings for the page margins, the header, and the footer through the Internet Explorer user interface. However, Internet Explorer and the WebBrowser control do not include methods to change these settings programmatically.

NOTE: You cannot use the ExecWB command to set the page margins, the header, or the footer. These values are stored in the registry.

Is your application ASP .Net? If not, you might consider using the PrintDialog instead? Not sure if this helps.
 
No - it is a regular Visual Basic .net application. The quote you posted from Microsoft actually answers my question - it appears that it's just not possible to do programmatically.

So that leaves me with the solution I previously settled on - modifying the registry myself and then changing it back after I'm finished printing.

I assume modifying the registry is going to retrict my program only to users who have access to the registry. Unless the "current user" segment of the registry can always be modified regarless of local machine access rights? I may have to research / experiement with that.

Thanks for the help!
 
Back
Top