WebBrowser control printouts graphically corrupt with IE9 installed

Unanswered WebBrowser control printouts graphically corrupt with IE9 installed

  • giovedì 17 marzo 2011 14:17
     
     

    I'm wondering if anyone else has experienced this issue, and if so what they might have done about it.  Having installed the IE9 update a couple of days ago, I'm left in the same boat that I found myself in when I tried the IE9 RC.  Namely, documents printed via .Print() from a WebBrowser control in .NET no longer print correctly.  What the user sees in screen is vastly different from what comes out of the printer.  There will be missing characters and whitespace discrepencies virtually every time.

    Here is an example:

     

    The top is what inevitably comes out of the printer when the bottom is what the user sees on screen (outside of the pixelized part of the name & address--that was me).

    If I uninstall IE9, the problem goes away.

Tutte le risposte

  • giovedì 17 marzo 2011 14:53
    Moderatore
     
     
    What font are you using there? I can't repro it here with IE9.
    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
  • giovedì 17 marzo 2011 16:07
     
     

    The main font is Tahoma with the barcode being CodabarLarge (http://fonts.webtoolhub.com/font-n15969-codabarlarge.aspx).  Missing letters effect both, so I don't think it is specific font related.

    Also worth note is that this only happens when printing from a WebBrowser control.  If the user loads the same page in standalone IE9 and prints it using the normal menus, the printout looks fine.

  • giovedì 17 marzo 2011 16:39
    Moderatore
     
     
    Best I can say is I can't make it happen. Have you only tried on 1 machine, or are you seeing this everywhere?
    Matt Kleinwaks - MSMVP MSDN Forums Moderator - www.zerosandtheone.com
  • giovedì 17 marzo 2011 19:27
     
     
    I've tried it on two systems and they both exhibit the same symptom.  It's also worth noting that I get the same output regardless of if I print to a real printer or a PDF print driver, so it seems to be happening earlier in the print chain rather than later.
  • lunedì 21 marzo 2011 10:32
    Moderatore
     
     

    Hi,

    Would you like to post your code about previewing webbrowse?  So that we can reproduce your issue.

    I look forwarding to hearing from  you soon.

    Best Regards,


    Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • lunedì 21 marzo 2011 16:13
     
     

    The key to reproducing it semi-reliably seems to be calling .Print() on many different browser controls at the same time (even though all calls are on one thread).  It doesn't always occur on every single printout, but it's a pretty good percentage of the time under these circumstances.  I don't know if system speed will make a difference for reproducing this issue, so it might be best to try it on a slower system.

    To test with, I've got six WebBrowser controls on a form each with one report in them.  If I then create a button that calls .Print() for each of them so as to print the contents of all the browsers, many of the printouts will contain missing characters.  The white space discrepency persists even when there aren't missing characters, however, but that one isn't as critical.

    http://downloads.pcrpg.org/misc/IE9_WebBrowser_Demonstration.zip 

    The archive above includes a sample project where this effect is demonstrated as well as six sample report pages that were real order report pages but reloaded with fake transaction IDs, order numbers, names, and addresses.

    Take note that there is a render directive (X-UA-Compatible) in there.  I've tried a lot of different values.  Some help (not solve) the white space problems, but the missing characters appear to be unrelated.

  • giovedì 24 marzo 2011 10:13
    Moderatore
     
     

    Hi again,

     

    I have downloaded your code and tested it. However the issue (miss white space) didn't happened on my side. So I assume that there are some unexcepted issue happened with your IE9. You can consider reinstalling your IE9, can try your code again.

    Regarding the X-UA-Compatible, I recommend read the following document:

    http://msdn.microsoft.com/en-us/library/cc288325(VS.85).aspx

    The X-UA-Compatible header is not case sensitive; however, it must appear in the header of the webpage (the HEAD section) before all other elements except for the title element and other meta elements.

    I look forward to hearing from you soon.


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • giovedì 24 marzo 2011 14:32
     
     
    Hello, and thanks for your response.

    Please note that there are two distinct issues in play here.  White space/layout problems I'm not concerned about.  My inclusion of "X-UA-Compatible" effects the compatibility mode IE uses to render the page, but even when there isn't any directive there the second issue persists.  It's the second issue that I am primarily concerned with.  I can fix spacing and layout by editing the HTML template, but the second issue I cannot since it isn't an HTML problem.

    The second issue (the one that is very important to me) is the one of random, missing letters.  Please note that I've tried this example on three different PCs now which all reliably produce this error.  I do not believe a bad install of IE9 can be the explanation for each case.  Each PC I've tested on has been Windows 7 SP1 x64 running the 32-bit version of IE9.  Also note that this problem does not happen when IE8 is installed instead of IE9.  Also please recall that this only happens when printing programmatically calling .Print() on multiple WebBrowser controls in a short period of time.  I'd think it was a thread safety issue, but I'm doing all calls on a single thread.
  • venerdì 25 marzo 2011 04:59
    Moderatore
     
     

    Three suggestions:

     

    1.  Microsoft has released IE9 RTM version several days ago. I would recommend you use this version intead of IE9 RC. You can download from here:

    http://windows.microsoft.com/en-us/internet-explorer/products/ie/home

    2. When you change the Encoding property, some letter will display in differenct ways. Please check the following illustration:

     

     

    So I would recommend you reset the Encoding property. Here are the steps:

    Right click in black area ->Encoding -> Select Unicode (UTF-8)

     

    3. For more issue about IE9, you can get better response at the following forum:

    http://social.msdn.microsoft.com/Forums/en/iewebdevelopment/threads

     

    I look forward to hearing from you soon.

     
    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • venerdì 25 marzo 2011 13:23
     
     

    I do not think encoding types explain this particular problem, though I do appreciate the attention.  Since this problem isn't consistent when testing with the same documents each time, it strikes more as a bug rather than an encoding problem.  Also note that regular characters are among those missing--not just special characters.

    I'll re-post in the other forum if you think that is best.

  • lunedì 28 marzo 2011 03:06
    Moderatore
     
     

    I’m not sure whether it’s a bug in IE9 RC version. You can contact some IE experts in my last reply’s link for some further research.

    In addition, have you try to fix the bug by installing IE9 RTM version?


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • lunedì 28 marzo 2011 06:44
     
     

    Calvin,

    I am currious, I see this more done. 

    Why don't you call the released version not simply the released version instead of the Ready To Market version.

    Just currious?

     


    Success
    Cor
  • martedì 29 marzo 2011 04:53
    Moderatore
     
     

    Hi Cor,

    Microsoft released the IE9 final version on March 15. However I call it RTM version as the following illustration:

     

    In additon, I think RTM stands for "Released to Manufacturing" :-)


    Best Regards, Calvin Gao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

  • martedì 29 marzo 2011 13:37
     
     

    Yes, I have tried RTM. I initially discovered this behavior in RC and was surprised when I saw it still present in RTM, which is what prompted me to finally post here.

    There seems to be some sort of race condition at play here.  I was able to get good results by forcing the calling thread to sleep for a few seconds between calls to .Print(), but this doesn't really fix the problem so much as step around it.  I really do think there's an issue here that should be looked into.

  • lunedì 4 aprile 2011 13:55
     
     
    @AMD Avenger, Have you solved this issue (other than the sleep method)? I am experiencing the same problem with my IE 9 install.
  • mercoledì 6 aprile 2011 17:37
     
     
    @AMD Avenger, Have you solved this issue (other than the sleep method)? I am experiencing the same problem with my IE 9 install.

    Not yet, unfortunately.  I haven't found a solution other than waiting between calls to Print().
  • martedì 27 marzo 2012 11:09
     
     

    I have the same exact problem with VB express 2010 Webbrowser control and IE9 combo

    Here's my post on this subject

    http://social.microsoft.com/Forums/en-US/whatforum/thread/90cfde17-e71b-4cff-ae64-46cb06b62e47/

    AMD avenger, you said you are waiting between calls

    How long are you waiting?

    What I ended up doing just to get by was to stop all my pages from printing in a loop and hit the print button one by one as each page finishes diaplying in the webbrowser control

    This is not a solution, but it seems to help

  • giovedì 26 aprile 2012 11:07
     
     

    Hi, I am also facing a very strange problem while printing report thru execwb method of SHDocVw.InternetExplorer interface, it was working
    fine untill i upgraded ie8 to ie9, but asa upgraded to ie9 it started print some junk character(A'A'A'A') in report, I tried many
    solution istead of execwb method tried with Webbrowser.Print method also but all are in vein, same issue resurfaced again and again,
    application is printing fine below ie9 verion but on ie9 its started printing some junk/garbase character.

    for execwb methos i took reference of Interop.SHDocvw.dll
    Development Environment - .Net 2.0,
    Deploy Environment: - ie9 with windows 7

     

    My Code is below

      SHDocVw.InternetExplorer ieApp = null;
             object objUnknown = new System.Runtime.InteropServices.UnknownWrapper(null);
                    ieApp = new SHDocVw.InternetExplorerClass();

                    object noValue1 = null;
                    object noValue2 = null;
                    object noValue3 = null;
                    object noValue4 = null;
                    object noValue5 = null;
                    object noValue6 = null;
                    object COMNothing = null;

                    COMNothing = new System.Runtime.InteropServices.UnknownWrapper(null);

                    noValue1 = COMNothing;
                    noValue2 = COMNothing;
                    noValue3 = COMNothing;
                    noValue4 = COMNothing;
                    noValue5 = COMNothing;
                    noValue6 = COMNothing;

                    ieApp.Navigate(URL, ref noValue1, ref noValue2, ref noValue3, ref noValue4);
                    while (ieApp.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
                    {
                        Application.DoEvents();
                        Thread.Sleep(50);
                    }
                       
                        OLECMDF status = ieApp.QueryStatusWB(OLECMDID.OLECMDID_PRINT);

                        ieApp.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER, ref noValue5,
    ref noValue6);
                        int count = 100;
                        while (count-- > 0)
                        {
                            Application.DoEvents();
                            Thread.Sleep(100);
                            Debug_Log.Log(4, "N", "CreateBrowser", "Sleep");
                        }


    Please can any buddy let me know about solution 

  • mercoledì 13 giugno 2012 16:47
     
     
    Anyone know if the issue will be resolved in IE10?
  • mercoledì 13 giugno 2012 17:17
     
     

    It hasn't even been fixed in IE9

    No one from MS has even acknowledged the problem

  • mercoledì 22 agosto 2012 06:43
     
     

    I've been doing some research on the missing characters issue.  It may be helpful to some of you: http://marc.durdin.net/2012/08/when-characters-go-astray-diagnosing.html

    Long story short: seems like a threading bug that can be resolved by serializing print jobs.  Slow but it works.  Long term: hopefully we can escalate with MS for a full solution.