1

I'm using a webbrowser control in c# to print an html file. When I open the html file with my current navigator (Firefox or chrome), my page is "great", and I have to print it exactlly how I see it. But when I use a webbrowser control in c#, it's like the webbrowser add a "margin-left" property, and my document isn't centred http://imgur.com/q7ovEA1 I also want to remove this "page 1 of 1" and the Title. I know that the webbrowser control in c# use Internet explorer, that's why I added this in my html file:

http-equiv="X-UA-Compatible" content="IE=edge

But this doesn't solve the problem.

Keenegan
  • 91
  • 6

2 Answers2

1

This MSKB article should help with headers/footers. Regarding the rendering issues, I would expect FEATURE_BROWSER_EMULATION to have solved those, but I've already suggested that in the comments to another question of yours. Have you verified that browser emulation actually works? If it does, the following should show CSS1Compact for compatMode, and 10 or 9 for documentMode (depending on your IE version). The document must have both <!DOCTYPE html> and <meta http-equiv="X-UA-Compatible" content="IE=edge"> declarations for this to work:

dynamic document = this.webBrowser.Document.DomDocument;
dynamic navigator = document.parentWindow.navigator;
var info =
    "\n navigator.userAgent: " + navigator.userAgent +
    "\n navigator.appName: " + navigator.appName +
    "\n document.documentMode: " + document.documentMode +
    "\n document.compatMode: " + document.compatMode;
MessageBox.Show(info);

[EDITED] To control printing layout beyond @media CSS, you could implement your own Internet Explorer Print Template. That would provide full control over headers, margins, columns, etc. This feature is flexible, but not trival to implement. Some relevant resources:

Community
  • 1
  • 1
noseratio
  • 57,966
  • 24
  • 188
  • 459
1

In fact the problem was with my Internet Explorer options. In fact, in the settings of the print preview, I had 50px of margin, I just had to remove it. I wasted so much time on this x/. I don't understand why I had those weirds settings, I never used IE on that computer. Well, thanks Noseratio.

Keenegan
  • 91
  • 6