Strange problem with webBrowser1.Print();

M

Mi Me

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?
 
M

Mi Me

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".
[...]
Very strange, anyone around who can help me?

When it worked fine on Windows Vista, was that with IE9, or some other
version?

I have to admit, I am not sure but I think it was IE8 in a 32 bit
environment.
Not that I think anyone here will have a solution.  It's 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 doesn't even
print correctly directly from the browser, but in other cases you can
get a good printout but print preview is wrong.

I haven't seen the exact problem you're describing, but it wouldn't
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 didn't print or display correctly
never worked correctly, no matter how many times one would try.  Your
post isn't specific about reproducibility, but if for a given document
it always prints incorrectly, it's probably a similar bug or bugs in IE
to those that I've seen myself.

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.
Anyway, I realize none of that is helpful.

Pete, our thoughts are much appreciated!
 I suppose you might try
reinstalling printer drivers, looking for different ones, etc. on the
possibility that it's a driver issue.

That was one of my first guess. Therefore I have tried it with three
different printers (brother, dell, kyocera), all having this issue.
Not that I think anyone here will have a solution.  It's not really a C#
or even .NET question.

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 isn't 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.
 
M

Mi Me

On 11/24/11 12:21 PM, Mi Me wrote:
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".
[...]
Very strange, anyone around who can help me?

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
printed.

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 can't
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/commandlineprint2).
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
"normal" Firefox version.

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.

mi.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top