DMankad

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



Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

Dave Biscuits

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

Cheers,
Dave.





Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

DMankad

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.




Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

Jeff Osia

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.



Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

D. Novak

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


 





Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

will3129

Hi D. Novak,

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

Thanks

Will






Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

D. Novak

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.



Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

davsy

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





Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

Surjeet Thakur

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






Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

davsy

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!





Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

i_m_fury

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 :( .




Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

i_m_fury

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

 






Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

lana2007

Did you find any solution



Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

jb

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!



Re: Internet Explorer Web Development IE7's Shrink-to-fit is one size fits all?

DMankad

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.