2

I have a C# application that use MySql database. I built a report using HTML.

I fill string attribute with tags and send the content to a WebBrowser control in a new form.

The report appear correctly, but when I call print preview dialog,

webBrowser1.ShowPrintPreviewDialog();

the header and footer appear in the report with values:

  • In header: # of pages.
  • In footer: Date and "about:blank".

This is a screenshot for the issue:

enter image description here

How could I remove the header and footer?

Minions
  • 5,104
  • 5
  • 50
  • 91
  • These are settings on the print dialog as far as I can remember, not sure you can turn them off via your code. – WraithNath Jun 25 '15 at 14:39
  • I checked it, nothing their related to them. – Minions Jun 25 '15 at 14:49
  • what browser are you using? Internet Explorer? – WraithNath Jun 25 '15 at 14:50
  • i'm not using browser!, i added WebBrowser object to a form. – Minions Jun 25 '15 at 14:51
  • See my new answer, it will most likely be internet explorer settings internally if its a microsoft webbrowser control. – WraithNath Jun 25 '15 at 14:55
  • Possible duplicate of [Suppress about:blank in Print Output of WinForms WebBrowser](http://stackoverflow.com/questions/8851626/suppress-aboutblank-in-print-output-of-winforms-webbrowser). I've flagged it just to connect these similar questions together so it's easier to find similar situations/solutions :) – Jeff B Oct 16 '15 at 20:26

1 Answers1

8

Looks like you may have to change registry settings before printing, then change them back again:

How To Programmatically Change Printer Settings for Internet Explorer and WebBrowser Control by Using Visual C# .NET

https://support.microsoft.com/en-us/kb/313723

using Microsoft.Win32;
//...............................

public  void IESetupFooter()
{

    string strKey  =  "Software\\Microsoft\\Internet Explorer\\PageSetup";
    bool bolWritable = true;
    string strName = "footer";
        object oValue = "Test Footer";
    RegistryKey oKey  = Registry.CurrentUser.OpenSubKey(strKey,bolWritable);
    Console.Write (strKey);
    oKey.SetValue(strName,oValue);
    oKey.Close();
}

enter image description here

WraithNath
  • 17,658
  • 10
  • 55
  • 82
  • Yeah, thaaat's it's :D .. Thanks Mr. Wraith – Minions Jun 25 '15 at 16:05
  • srry but do u have any idea about PrintPreview size (Width & hight) ? – Minions Jun 25 '15 at 16:08
  • i have had a look at the registry key and there is 2 attributes for header and footer. I cant work out exactly what the data value means, but im sure if you change the settings in the print dialog and look at the key again that is the value you need to set them to. I have just turned mine off, and it has cleared both variables so I think you need to set them to blank. Ill add a picture. – WraithNath Jun 26 '15 at 08:15
  • I found on my Win11 machine that the header/footer keys were missing by default. In that case it defaults to header "Page X of X" and footer "[URL] [DATE]". When I added in blank header/footer keys the header and footer went away. – J Higs Feb 21 '23 at 15:15