Re: WebBrowser Control Print and Preview Headers and Footers



** repost without attachment **

The header and footer are stored in the registry and are used for all instances.

http://support.microsoft.com/kb/313723

So, you can read those values before printing and store them in a variable. Then set them to empty before the print happens. After printing, reset the values to what they were.

To access the events for printing, you will need to get a reference to the underlying COM object SHDocVw.WebBrowser. Include a reference to Microsoft Internet Controls for this.

You can then cast to SHDocVw.WebBrowser from the WebBrowser controls ActiveXObject property. That exposes two events, PrintTemplateInstantiation and PrintTemplateTeardown. That is where you can handle setting the values of the header and footer.

http://www.mufaka.com/WebBrowserTest.zip contains a working example.

Bruce wrote:
I am using the .Net 2.0 WebBrowser control in a C# WinForms application to display and print custom HTML reports.

Is there a way to turn off the IE Page Setup headers and footers using C# before using the WebBrowser control's ShowPrintPreviewDialog() or ShowPrintDialog() methods so that the report formatting isn't thrown off by the Print Setup header and footer settings?

I would just like to turn them off, do my preview and print, then restore them to their previous values after the print or preview is finished.

I know users can go in an empty these values in the Page Setup dialog, but I would like to be able to do this without user interaction, and without changing the user's default page settings.

Thanks,
Bruce


.



Relevant Pages

  • Page printing - margin problems
    ... there have been some printing problems related to the ... the header and footers have now moved out of the printable ... Changing the top and bottom margins does not have an efffect upon where the ... header and footer are located. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • Re: Oops again. Problem with page numbering.
    ... When Vanguard asked what application ....? ... will see in the middle the Header and footer information defaults. ... And the application from where you are printing would be? ...
    (microsoft.public.windowsxp.basics)
  • Re: Newbie: Printing
    ... printing which happens on the client side. ... > because I can't have my own Header & Footer. ...
    (microsoft.public.dotnet.framework)
  • Re: Oops again. Problem with page numbering.
    ... In the window that opens ... will see in the middle the Header and footer information defaults. ... And the application from where you are printing would be? ...
    (microsoft.public.windowsxp.basics)
  • Re: unlink Footer/Header in VBA
    ... AutoText it will bring the section break with it. ... Header, a footer and Bibliography all in one. ... Bibliography" and another for "Footer for Bibliography". ...
    (microsoft.public.word.vba.general)