.NET Framework - Strange problem with webBrowser1.Print();

Asked By Mi Me on 24-Nov-11 03:21 PM
My application navigates to multiple pages in our intranet printing
the content. I do this with a simple webBrowser1.Print() after
webBrowser1_DocumentComplete event. This works fine in almost all
cases. But on some print-outs (about 10 %) there are missing
characters on the paper. E.g. "some or more words" become "so e or mo
e wo ds".

This strange issue seems to happen without any specific pattern.
Sometimes in every line are missing chars, sometime only a few words
are affeced on one paper, but as I said, in 90 % of the print-outs all
is fine.

I have tried three different printers. With all this strange problem
exist. For testing I have saved the html content
(webBrowser1.Document.Body.Parent.OuterHtml) to file and there are no
missing characters, all files look fine. If I print the pages directly
in IE 9 it works fine in all cases.

Furthermore, before updating to Windows 7 my application including the
printing works fine on Windows Vista.

Details about my environment:
target framework 2.0
windows application
running on Windows 7 64 bit
IE 9

Very strange, anyone around who can help me?

Peter Duniho replied to Mi Me on 24-Nov-11 04:39 PM
When it worked fine on Windows Vista, was that with IE9, or some other

Not that I think anyone here will have a solution.  it is not really a C#
or even .NET question.

However, I can confirm that even since the IE8 beta, IE has had trouble
printing things correctly.  In the worst cases, the page does not even
print correctly directly from the browser, but in other cases you can
get a good printout but print preview is wrong.

I have not seen the exact problem you are describing, but it would not
surprise me to find that printing via automation uses a different code
path than printing straight from the browser, and that there are bugs in
that code path.

Note that at least in my own experience, the problems were 100%
reproducible.  That is, scenarios that did not print or display correctly
never worked correctly, no matter how many times one would try.  Your
post is not specific about reproducibility, but if for a given document
it always prints incorrectly, it is probably a similar bug or bugs in IE
to those that I have seen myself.

Anyway, I realize none of that is helpful.  I suppose you might try
reinstalling printer drivers, looking for different ones, etc. on the
possibility that it is a driver issue.  But other than that, I do not have
much to offer in the way of help.  Just commiserating.  :)

Mi Me replied to Peter Duniho on 25-Nov-11 04:43 AM
I have to admit, I am not sure but I think it was IE8 in a 32 bit


Unfortunately it is not 100% reproducible. If I print 30 pages in a
loop resulting in 27 good and 3 bad papers, then print this 30 pages
the result is different. Maybe only two papers with errors and those
two are not the same as in the first printing loop.

Pete, our thoughts are much appreciated!

That was one of my first guess. Therefore I have tried it with three
different printers (brother, dell, kyocera), all having this issue.

I not sure about that. First I thought it maybe a driver or memory
issue of the printer. Since I have tested different printer I think
this is not the issue.

I fear that this issue is based on a bug / memory leek in the
webbrowser.Print() implementation. I am running out of idea what to
check/test :-/

Mi Me replied to Mi Me on 25-Nov-11 08:18 PM
Solution in short: replaced  WebBrowser control by WebKit

Longer: More than three days (and nights) I was trying fixing this
strange printing issue occurring with WebBrowser control in a Windows
7 64 bit environment with IE9. It seems there is no change to get rid
of this issue with the WebBrowser control. I guess there is a memory
leak in the component eating some of my chars before they get

I came across two solutions which work for me. First I thought to get
easily around this problem calling my browser from command line with a
print silent switch. Wondering, it seems no browser has (a good)
implementation of a simple -print switch for command line use. I cannot
believe, but it is reality.

After searching a while a found a solution with Firefox and the
Command Line Print add-on (see http://sites.google.com/site/torisugari/comm=
Replacing the WebBrowser calls with a single line of

Process.Start("firefox.exe", "-print " + url);

does the trick. Printing works fine. This would be a very great
solution ... if it will work with the latest version of Firefox. But
no change. The Command Line Print add-on does not work with Firefox 7
or 8. I got it working with Firefox 3.6. I thought I can have
installed the latest version of Firefox using for browsing the web and
3.6 only for using with my application. But it does not work since the
Command Line Print add-on was deactivated as soon as I started the

So I switch to the solution mentioned above with WebKit. It works, but
with some negative elements. The rendering is not as good as with
WebBrowser. So some print-outs does not look as good as with IE. If I
set the webkitbrowser visible property to false, it throws me some
exceptions. For the time being I can live with that. But if anyone has
a solution for the original issue with WebBrowser control, I would
love if you contact me.

Hope that someone who is reading that will save a lot of time hunting
for a solution for a similar issue.