none
IE7's Shrink-to-fit is one size fits all?

    Question

  • Printing in a web app isn't easy.  I have an application that loads a page into an Iframe, and a button outside of the iframe that does the iframe.focus();iframe.print(); thing to print out the contents of the iframe.

    Whats inside of the iframe is meant to be print out on legal sized paper (8.5"x14"), which isn't the same as normal letter paper (8.5"x11").  In previous IE versions this worked like a charm.  IE7, however, decides that legel size is not appropriate and applies the shrink-to-fit to shrink my beautiful legal sized document into a letter sized box.

    When printing, the printer expects a legal sized document since that's whats defined in the printer settings, but only prints a letter-sized box of content since IE7 automatically shrinks the content down to letter sized paper.

    I need some way to either turn this feature off or tell this feature the page size when printing a frame through javascript.  Any ideas?

    Friday, October 27, 2006 8:44 PM

Answers

  • This is  a bug in the way Internet Explorer 7 prints the contents of an IFRAME.  It happens to every IFRAME no matter what the contents are.  Our work around was to have the user open the frame link in a new window.  When printing the same page from its own window this does not occur.
    Tuesday, November 07, 2006 5:12 PM

All replies

  • DMankad - I have a very similar issue - did you ever find a solution? Automatic shrink to fit is killing me!

    Cheers,
    Dave.

    Thursday, November 02, 2006 7:51 AM
  • Mr Biscuits-

    This is, after all, Internet Explorer.  We had to go for a workaround.

    In our case, we had a button to initiate the printing.  It doesn't really matter, it could be an anchor tag or whatever.  The behavior of the button remains the same if the browser is IE6, but for IE7 users we open the contents of the iframe in a new popup window.

    In this new popup, we have a small div that doesn't print.  This div contains another print button and IE7 print instructions.  The button calls window.print().  Therefore it turns into a "Printer-friendly version" approach.

    This is our solution until we start generating PDFs.

    If this doesn't work for you, I strongly suggest working towards a workaround.  I don't see this problem getting fixed.
    Thursday, November 02, 2006 1:36 PM
  • This is  a bug in the way Internet Explorer 7 prints the contents of an IFRAME.  It happens to every IFRAME no matter what the contents are.  Our work around was to have the user open the frame link in a new window.  When printing the same page from its own window this does not occur.
    Tuesday, November 07, 2006 5:12 PM
  • here is another workaround that worked for me... 

    <style>
     
    @media print
    {
    #main_area{display:none;}
    #print_area{display:block;}
    }

    @media screen
    {
    #main_area{display:block;}
    #print_area{display:none;}
    }
     
    </style>

     


    <div id="main_area">

    here goes your main page content... (it contains your iframe...)

    </div>

    <div id="print_area">


    </div> 


    ------------------ 

    in your iframe you wrap all the content in another div like this

    <div id="if_area">

    iframe content here...
     
    </div>

    and on the end of the iframe you put this js code

    <script language="javascript">

    parent.document.getElementById("print_area").innerHTML=document.getElementById("if_area").innerHTML;

    parent.focus();
    parent.print(); // you need to print your top frame, you don't have to do it this way, you can use some triger or something...

    </script>


    as I said it worked for me, hope it helps...


     

    Wednesday, November 22, 2006 7:09 PM
  • Hi D. Novak,

     I try to run your sample code, Just doesn't work, still shrink to fit. Any ideas?

    Thanks

    Will

     

     

    Monday, December 04, 2006 6:14 AM
  • it is just an example how it can be done, you can't just copy it... Basicly the main idea is to put the content you wan't to print in some hidden container (div) in the top window, and then print the top window... With css styles you set which parts of top window are visible to browser (to you) and which are visible to printer... this works because shrink-to-fit 'bug' happens only in an iframe.
    Wednesday, January 03, 2007 6:06 PM
  • I am having the same problem.

    The best solution I've come up with so far is to pop a window, print it, then close it.  But I think this will confuse our user.

    However, I keep thinking  that we should be able to modify the shrink to fit property programatically  - something like

    window.print("ourPageToPrint.asp" + "printsize = 100%"). 

    Please tell me there is a way?

    Tuesday, January 09, 2007 3:54 PM
  • hi all...

    i fixed the problem of printing in  IE6.0 , IE7.0  and all browser like firefox, mac etc...
    when the thing to print out the contents of the iframe.

    IE7 Printing problem in Iframe:  IE7 automatically shrinks the content down to letter sized paper.

    Now i have solution: this code using when you want to print a content in the iframe in broswer IE7 with without shirnks the content. 

     // an application that loads a page into an Iframe, and a button outside of the iframe

    first of all :

    step one: - wirte a print function:

    example:

    <script language="JavaScript">
    function printPage()
    {
    window.parent.inner.focus();                   //inner the  id of iframe.....
    window.print()
    }
    </script>

    calling this fucntion: <a href=printPage()">print page</a>

    step two: iframe code:

    <iframe src="test.htm" name="inner" scrolling="auto" width="638px" height="500px" frameborder="0" id="inner"  >
       
       </iframe>

    thi logic i used:

    i using the javascript, this script checking  the browser version :

    if the IE6<= THEN apply the css class of IE6. else if IE7>= THEN apply the CSS class of IE7

    this script check all browser like mac, firefox, etc...

    example of script:

    <SCRIPT LANGUAGE="JavaScript">
    <!--
    version=0
    if (navigator.appVersion.indexOf("MSIE")!=-1){
    temp=navigator.appVersion.split("MSIE")
    version=parseFloat(temp[1])
    }

    //using browser < 6 -----//
    if (version<=6.0)
    {

    //alert("browser 6")

    var cssNode = document.createElement('link');
    cssNode.setAttribute('rel', 'stylesheet');
    cssNode.setAttribute('type', 'text/css');
    cssNode.setAttribute('media', 'print');
    cssNode.setAttribute('href', 'css/print6.css');
    document.getElementsByTagName('head')[0].appendChild(cssNode);
    }

    ////NON IE browser will return 0
    //using browser 7

    else if(version>=7.0)
    {

    //alert("browser IE 7")

    var cssNode = document.createElement('link');
    cssNode.setAttribute('rel', 'stylesheet');
    cssNode.setAttribute('type', 'text/css');
    cssNode.setAttribute('media', 'print');
    cssNode.setAttribute('href', 'css/print7.css');
    document.getElementsByTagName('head')[0].appendChild(cssNode);

    }
     
    </script>

    Last step:

    you just write the css class print6, print7...

    and placed in css folder.

    this code working good you just copy and paste..

    if you need any help about this code , You can contact me ....

    plz reply..

     

     Regards

    Surjeet Singh
    (Web Developer)
    m. 9915436877

    C-136, Industrial Area, Phase 8, Mohali, Punjab
    Email: surjeets@sebiz.net
    Visit us at www.sebiz.net, www.netsmartz.net

    Friday, January 12, 2007 6:51 AM
  • Surejeet,

    I tried to use your code but could not figure it out - like where is should all go etc.

    However, I did come up with adding a different print style sheet (href="../CSS/MainprintStyle.css"  media="print") only when the page was displayed in IE7 in my frame.  Of course, IE7 still shrinks the style sheet, so I had to play with the fonts - making them bigger until they actually showed what I wanted. (A font of 13 in a non-frame became a font of 18 in my iframe).  However, when the users started testing they got reports with different size fonts - turns out that the skrink to fit feature also is related to screen resolution. 

    Do you have any other ideas?

     

    thanks!

    Tuesday, January 23, 2007 3:22 PM
  • What's the deal with this?  Have any new solutions been found per chance?  I'm creating the content dynamically inside this iframe and the user does not want popups.  I need a fix for this :( .
    Tuesday, February 27, 2007 7:03 PM
  • Well, I was forced to make my own little hack for this.  This will only work it there are no style sheets or style tags declared after this one in conditional comments (unless they are declared for other IE browsers e.g. [if IE 6]).

    I put this in the head tag for the iframe I am printing.  This of course requires javascript to be enabled.  It also assumes that the parent window will be the top-most window.  By taking the smallest possible resolution width (640) and calculating how much larger the screen is percentage-wise, we then use IE's zoom css feature and apply it.  You may want to add a onresize call to setFonts() to the parent window so that the zoom is reset when the browser window is resized.  This will not be visible on screen, it will only affect the printed document (if you want to see the resize chnag ethe @media print to @media screen).  There may be an extra blank page printed as well.  If you find a fix for this let me know.   So here is the code I added at the end of my <head> tag:

    <script type="text/javasript">

    function setFonts(){return;}  // This is for non-IE 7 browsers

    </script>

    <!--[if IE 7]> 
      <style>
      @media print
      {
       body
       {
        zoom:100%;
       }
      }
      </style>
      <script type="text/javascript">
       function setFonts()
       {
        var myRatio=parseInt((parseInt(parent.document.body.offsetWidth)/640)*100);
        myRatio=(myRatio > 100 ? myRatio : 100);
        document.styleSheets[document.styleSheets.length-1].rules[0].style.zoom=myRatio+"%";
       }
      </script>
      <![endif]-->

    In the body tag in the iframe, I added the following:

    <body onload="setFonts()">

    If you have any questions abou this code, email me.

    Shane L.

    i_m_fury<at>hotmail.com

     

    Wednesday, February 28, 2007 2:11 PM
  • Did you find any solution?
    Friday, March 23, 2007 6:23 PM
  • Yes please help! you may think this is a great new feature but it doesn't help! we need a way to turn it OFF!
    Tuesday, March 27, 2007 4:44 PM
  • This is a case where if there was an easy solution, there wouldn't be much of an issue.  Like I said in my first reply, opening up your document in a new window before printing it does the trick.  I know that this isn't an option for many people, so if you can't implement one of the more complex solutions mentioned above, you may need to re-evaluate your document delivery options.
    Wednesday, March 28, 2007 11:54 AM
  • opening it in a new window isn't an option and this isn't an email issue. we need a way to turn it OFF!
    Friday, April 13, 2007 12:07 AM
  • It is not only an issue with printing from an iFrame -- any web printout will try to shrink to fit by default. Moreover, on Vista, printing *anything* from IE7 produces text that is washed out and faint. I printed the same doc to the same printer from Windows XP/IE6 and it is the right size and the right darkness. When printed on Vista/IE7, it appears very faint.

     

    The other issue is that if I try to change the print preferences, it doesn't change them. Even if I create a new preference profile, click save, click apply, etc., these changes do not persist.

     

    Having used Microsoft OS's since the late 80's, I can say that they have tons of bugs and I wouldn't touch one of their OS's until at least two years after they are out. Vista users are still beta testers. Unfortunately, our customers who have bought new computers are using Vista and IE7, and it obviously has some bugs with printing. Even if you try to override "shrink to fit" it will not persist the change.

     

    The best solution I could find is that the user goes into the print preview mode, selects 100% from the drop down, and prints it out. They have to do it each time. The printout is still very faint compared to something printed from XP/IE6 to the same printer. One of our QA people said that other documents she has printed from Vista appear to be faint as well.

     

    There are multiple problems with the printing, and we have no choice but to inform our customers of a work around and hope that the printout is still legible with the faint printout.

     

    Any ideas on how to persist printing preferences (I'm not talking programatically, I know that cannot be done) within the IE7 browser? Any way to make it print so people can read it? Why are the printouts so faint on Vista? Is this just par for the course, and we have to wait one or two years for this issue to be fixed in a service pack?

    Thursday, May 03, 2007 8:50 PM
  • Dude, Microsoft can't even get the links on their websites to work right. Whenever I click on a link in hotmail or an ad for Microsoft on some other site, 50% of the time the link is bad. Having gone to many Microsoft conferences, there are many times when their demos do not work. I have never seen this sort of incompetance at Java One. We gave up on ASP and moved to J2EE seven years ago, specifically because their web technologies are so bad! Microsoft has a lot of difficulty getting their own technology to work, but since they have such a huge market share, people are forced to accept it, and they can drag their feet fixing problems that ruin people's web applications. Now that the non-constructive venting of the truth has been done, what do we do about it?

     

    Re-writing our complicated page as something that generates a .PDF will take me weeks. Then the user has to download Acrobat reader and deal with that. The best I can do in this situation is to inform our users of a workaround, because I am not using an iFrame, and our printouts are still being shrunk. Moreover, the only way this can be successfully configured in IE7 is through the print preview feature. Any other attempt to remove "shink to fit" or configure printing preferences DOES NOT PERSIST. This is a bug, pure and simple.

     

    Does this feature conform to W3C standards? Shouldn't a CSS-driven printout print the same on all browsers? These are practical questions that are reduced to rhetorical questions, because we can't solve these problems. At best, we can work around them.

     

    I think the best solution is what is initially presented on this thread -- detect IE7 and pop up a window with instructions -- go to the print preview mode, select 100%, click the print button. On Vista systems this printout will still appear faint and difficult to read. It makes me wonder if Microsoft does QAT...

     

    It is obvious the way this feature should have worked -- if a page needs to be shrunk, it should pop up a dialog box asking the user if this is desired. The fact that they assume this is what the user wants really hoses a lot of web developers who have developed specific printing based on CSS.

     

    This makes me so mad. As much as I try to get away from Microsoft and their buggyness, they pull me back in.

    Thursday, May 03, 2007 9:19 PM
  • Update:

     

        If you're printing from an Iframe and are still having this issue, try using document.execCommand('print',false,null).  This is only needed for IE7 and will not work in non-Microsoft browsers so make sure to put an IE-7 check in your print function.  It does not resize and break the wrapping.  Works just like IE-6.

     

    i_m_fury at hotmail dot com

    Shane

    Friday, May 18, 2007 3:31 PM
  • i combined some of the scripts above and came up with the following which u should be able to copy and paste into your code to fix the problem.

     

    <style> @media print { body { zoom:100%; } } </style>


    <script type="text/javascript">
    function ie7PrintScale() {
    // only do this for ie7
    if(navigator.appVersion.indexOf("MSIE 7") != -1) {
    var myRatio=parseInt((parseInt(parent.document.body.offsetWidth)/640)*100);
    myRatio=(myRatio > 100 ? myRatio : 100);
    document.styleSheets[document.styleSheets.length-1].rules[0].style.zoom=myRatio+"%";
    }
    }

    window.onload = ie7PrintScale;
    </script>

     

    Wednesday, May 23, 2007 3:22 AM
  • This does not work in all cases.  Documents that contain images will differ from those that do not.  Using document.('print',false,null) works in IE for all cases.  Using this method also ensures that if microsoft ever fixes the problem when using window.foocus(); window.print() method, the script will not over-zoom the document.
    Wednesday, May 23, 2007 2:38 PM
  • Thanks, I'm a little confused with your suggestion.  Can you update my code above to account for what you are talking about?  Thanks again.
    Wednesday, May 23, 2007 7:22 PM
  • Hi,

     

    this is nagesh i am working on .Net technologies in Hyderabad.

     

    i have the semilar problem but in reverse direction

     

     

    I want to set shrink to fit  using java script.

     

    so that any browser can print any width data which is in window.

    my java script should print data which is fit into a paper irrespective of browser that is ie 7 or 6 or anything.

     

    so I need some statement such as "shrink to fit =true" .

     

    is there any option like this.

     

    If you have any solution i request you send me as soon as possible.

    thanks

     

     

    regarding ,

    nagesh

    Friday, June 22, 2007 6:41 AM
  • I am getting some forms shrunk even though I am not using iframe.  I DO have an image in a <div>.  Will this technique still work?  What would the code look like to implement for ie7 only?

    Thanks,
    Randy
    Friday, July 20, 2007 7:34 PM
  • Here's a fix to default printing to 100% instead of "shrink to fit".  Only problem is that it requires users to apply this.

     

    users with ie7 need to install this hotfix

    http://support.microsoft.com/kb/931768/en-us

     

    the hotfix above contains several fixes, including

    http://support.microsoft.com/default.aspx/kb/932538/

     

    After applying the hotfix, u need to add the registry value.  u can copy and paste this in command prompt to update it

    reg add "HKLM\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_STF_Scale_Min" /v iexplore.exe /t REG_DWORD /d 100 /f

     

    restart the browser and no more shrink to fit, unless the user manually specifies it.  this is the way it should be by default in my opinion

     

     

    Saturday, July 21, 2007 10:51 PM
  •  

    Just something extra for you guys to chew on.  This problem is not limited to iframes.  It is also a problem with new windows in the landscape orientation.  I have a couple print windows in a web app that I have been building.  One is in a portrait orientation (which prints fine), while the other is in landscape and the shrink-to-fit is invoked.
    Friday, October 05, 2007 6:35 PM
  • I need to get rid of this problem "shrink to fit" too.  I hate it.  Please someone help us in an easy way.

    Thursday, October 11, 2007 11:53 PM
  • Hi,

    I have printing problem with IE7 as well.

    I actually found out that for IE7 to use the default printing preferences in Printer and Faxes panel, or for the printing preferences to persists, that printer has to be the default printer.

    Friday, January 11, 2008 11:20 AM
  • add the registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl \FEATURE_STF_Scale_Min


    Add DWORD to the key with value iexplore.exe


    Double-click Iexplore.exe and change the value to 100

     

    This causes the Shrink Amount to always be -NONE- unless teh user specifies otherwise through print preview.

    Monday, January 14, 2008 1:53 PM
  • "100" does not work = but Value "64" does work like a charm! Thanks for the head start.

     

    Wednesday, May 14, 2008 3:10 PM
  •  

    hi

     

    am i missing something, but when I implement the code, the page does increase in size, however when I do window.print() in my code it still prints shrink to fit size.

     

    <style> @media print { body { zoom:100%; } } </style>


    <script type="text/javascript">
    function ie7PrintScale() {
    // only do this for ie7
    if(navigator.appVersion.indexOf("MSIE 7") != -1) {
    var myRatio=parseInt((parseInt(parent.document.body.offsetWidth)/640)*100);
    myRatio=(myRatio > 100 ? myRatio : 100);
    document.styleSheets[document.styleSheets.length-1].rules[0].style.zoom=myRatio+"%";
    }
    }

    window.onload = ie7PrintScale;

     

    What am I missing?

     

    cheers

     

    Mike

    Tuesday, June 10, 2008 12:40 PM
  • From javascript it is posible to control this ie 7 feature:

    http://matthew.delmarters.com/weblog/controlling-the-ie7-shrink-to-fit-print-setting-using-javascript/

    using:

    document.execCommand('print', false, null);

    Instead of

    document.print();

    set second parameter to false if don't want to shrink to fit, true if you want to:

    Tuesday, August 05, 2008 8:34 PM
  • I like this solution with document.execCommand('print', false, null);

    but my problem now is how do i redirect ctrl-p to use this instead of the default print action?  I don't want to have a print button on every page for users to click on.  I can capture the ctrl-p action and call document.execCommand('print', false, null); but it seems to also call the default print action as well.  anyway to disable the default print action without clientside configuration of their browser?

    Friday, August 29, 2008 6:04 AM
  • I tried the registry solution on several computers but it didnt work! any other workarounds?

     

    Monday, September 01, 2008 9:24 AM
  • make sure u have this hotfix installed

    http://www.microsoft.com/downloads/details.aspx?familyid=7A778D93-9D85-4217-8CC0-5C494D954CA0&displaylang=en

    ensure u set the registry right, then restart ur browser

    Monday, September 01, 2008 10:01 AM
  •  

    Well i have windows vista on my machine, i found the same update but for vista and when trying to install it, it says your system is not supported!!. by the way i have the latest updates for windows as by windows update.
    Tuesday, September 02, 2008 10:48 AM
  • Tuesday, September 02, 2008 10:56 AM
  • Both of those gave the same error msg as i got before! i think my laptop has the latest updates thats why giving this error msg. any suggestions?

     

    Tuesday, September 02, 2008 11:06 AM
  • my only guess is that you typed something in wrong when entering the registry.  just copy and paste this in cmd or run to let it add the key instead of typing it by hand.  this is a one-liner

     

    reg add "HKLM\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_STF_Scale_Min" /v iexplore.exe /t REG_DWORD /d 100 /f

     

    then restart your computer, although i think restarting your browser is enough.  if that doesn't work, try a different computer cuz i know this works for me with vista and other computers with xp.  maybe you set something you shouldn't have on your computer within the browser so i recommend trying a different computer to verify that it does work then think back on what changes you made.  have no idea what else to try.

    Tuesday, September 02, 2008 11:15 AM
  • Thanks alot its working now, i found out that the value should be 64 not 100 as one of the posters said before. Again thanks for your kind help.

     

    Tuesday, September 02, 2008 11:43 AM
  • The value entered depends on whether you are entering it in hexadecimal or decimal, 64 in hex is equivalent to 100 in decimal
    Thursday, October 23, 2008 5:12 PM
  • Here's a clean simple solution. - (Tested on IE7, Firefox 3.0.4, Safari 3.1.2) 

    I hacked at this using some code from this forum and some from others
    (I'm a designer with a wanna-be programmer heart.)


    Unfortunately, you can't just use:  document.execCommand('print', false, null);  because it doesn't work in Mozilla based browsers. 

     

    To all in this forum...give it a whirl and let me know how it works for you - this hasn't been tested in older browsers or Chrome.

    You can keep the script together as shown below - or pop it in your head tag.  Just keep the <Form> tag line separate and put that somewhere between your <body> tags where you want a print button to display.  You could change the button to a link or an image tag if you'd like by substituting the <Form> line with an <a href>, and reference the function name with an "onclick", "onload", etc.

     

    I used mine inside a Greybox.  So if you do that, make sure not  to use the "onload" because it conflicts with the greybox code.


    I'm naming this one "Print Baby Print"   


    ______________________________________________________________


    <script type="text/javascript">
    function printBabyprint(){
    var browser=navigator.appName;
    if ((browser=="Microsoft Internet Explorer"))
      {
     document.execCommand('print', false, null);
      }
    else
      {
      window.print();
      }
    }
    </script>

            <form><input type="button" onclick="printBabyprint()" value="Print" /></form>


    ______________________________________________________________


    Friday, November 21, 2008 1:54 AM
  • Thank you!

     

    Also use Greybox and this code worked OK in IE to print without shrinking and also OK in Firefox and Safari.

     

    Added CSS "noPrint" to not print the button on the page.

     

    Place in page head:

     

      <style type="text/css">
        @media print {
          .noprint { display: none; }
        }
      </style>

     

    Then add to button style:

     

    class="noprint"

     

    CSS "noprint" works OK for text or image buttons.

     

    Again thank you for your work!

     

    Monday, December 08, 2008 3:38 PM
  • Wow, over two years on and I'm still trying to solve this problem. So fustrating.

    Okay, our iFrame runs in a HTA, and has always shrunk to fit on ie7 when printing. So far we've stuck with ie6 because I just dont have to time to recode a whole heap of our work printouts to PDF.

    Tried the reg fix:

    reg add "HKLM\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_STF_Scale_Min" /v iexplore.exe /t REG_DWORD /d 100 /f

    and updated all javascript print coding to:

    document.execCommand('print', false, null);

    The hilariously sad thing with this fix is the FIRST time you print, it shrinks to fit. The SECOND time you print, the hack starts working and it prints without shrinking. So every time you restart the application you'd have to do one dud print before the hack kicks in.

    Anyone got any further tricks for this yet? or any way to stop this first print run problem?

    Tried IE8 Beta 2 to see if it made any difference - nope. Whoever introduced this shrink-to-fit option at microsoft without an option to disable it should be shot in my opinion!!

    Cheers,
    Dave.



    Tuesday, December 23, 2008 2:37 AM
  • I have performed the same as Dave biscuits and I cannot go to IE8 yet, has anyone found a fix  - currently running XP SP3 with IE.7  The hotfix from Microsoft only work with XP SP2 - And I not going to uninstall sp3 on over 100 machines!
    Wednesday, July 08, 2009 7:42 AM