iframe and printing issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashindler
    New Member
    • Sep 2008
    • 9

    iframe and printing issues

    Hi,

    I have an excel spreadsheet that is displayed within an iframe.

    I print the sheet displayed by using the function:

    function printExcel(){

    window.excelFra me.focus();
    window.excelFra me.print();

    }

    This does the job BUT the sheet is printed out over 4 pages in a larger font than had I printed the page from excel itself. The original excel sheet is set up so that the contents of the sheet fit all onto one page.

    Is there anything I can do to control the print area of the contents of the iframe?
    Does anyone have any suggestions?

    Thanks in advance.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    If the Excel sheet is not contained within an iframe, does it print how you want it to?

    Comment

    • ashindler
      New Member
      • Sep 2008
      • 9

      #3
      Yes - when the excel is not in the iframe it prints just the one page. When I print it in the iframe it prints the contents of the sheet over 4 pages.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        What code are you using for displaying the Excel sheet? You may need to use a print stylesheet to control the printing.

        Comment

        • ashindler
          New Member
          • Sep 2008
          • 9

          #5
          I simply have an iframe called "excelFrame " and one button called Print. When the user clicks the button --> onClick="printE xcel()" -->

          function printExcel(){

          window.excelFra me.focus();
          window.excelFra me.print();

          }

          The excel sheet prints but it prints the sheet our over 4 pages. If I print directly from the original file using excel, the sheet prints out nicely on one page.

          How can I control the printing area etc. of the iframe using stylesheets?

          Comment

          • ashindler
            New Member
            • Sep 2008
            • 9

            #6
            By the way, here is all the code - obviously fileName is the address of the excel file on the local machine:

            [HTML]<% String fileName = request.getPara meter("fileName "); %>

            <script type='text/javascript'>

            function printExcel(){
            window.excelFra me.focus();
            window.excelFra me.print();
            }

            </script>

            <HTML>
            <BODY>
            <input type="button" id="print" onClick="printE xcel()" value="Print">
            <iframe id="excelFrame " src="<%=fileNam e%>" width="90%" height="80%"></iframe>
            </BODY>
            </HTML>[/HTML]
            Last edited by acoder; Sep 15 '08, 11:05 AM. Reason: Added [code] tags

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              See Going to Print. You can try setting the font size in the print stylesheet.

              Comment

              • ashindler
                New Member
                • Sep 2008
                • 9

                #8
                I tried this:

                [HTML]<link rel="stylesheet " href="print.css " type="text/css" media="print" />

                <div id="printDiv" name="printDiv" >
                <iframe class="tborder" id="excelFrame " src="<%=fileNam e%>" width="90%" height="80%" frameborder="0" ></iframe>
                </div>
                [/HTML]
                And then in my print.css file:

                Code:
                #printDiv {  font-size: 9pt; }
                But this does not seem to have any affect whatsoever.

                I'm not even sure why logically it would make sense to set the font-size. My excel spreadsheet contains all sorts of fonts and even images. So how would font-size affect those?
                If I had instead of an excel, an image loaded into the iframe would setting the font size in the iframe make a difference to the size of the image when it is printed from the iframe?
                Last edited by acoder; Sep 15 '08, 12:12 PM. Reason: Added [code] tags

                Comment

                • omerbutt
                  Contributor
                  • Nov 2006
                  • 638

                  #9
                  Originally posted by ashindler
                  I tried this:

                  <link rel="stylesheet " href="print.css " type="text/css" media="print" />

                  <div id="printDiv" name="printDiv" >
                  <iframe class="tborder" id="excelFrame " src="<%=fileNam e%>" width="90%" height="80%" frameborder="0" ></iframe>
                  </div>

                  And then in my print.css file:

                  #printDiv { font-size: 9pt; }

                  But this does not seem to have any affect whatsoever.

                  I'm not even sure why logically it would make sense to set the font-size. My excel spreadsheet contains all sorts of fonts and even images. So how would font-size affect those?
                  If I had instead of an excel, an image loaded into the iframe would setting the font size in the iframe make a difference to the size of the image when it is printed from the iframe?
                  when working with printing the document you have to keep these two things in mind
                  1. the pixel should be avoided
                  2.points should be preffered
                  WHY ? because there is not any such thing like PIXELS in the world of printing / printers they take up or read every thing in points
                  and similarly there is nothing like POINTS in the world of computer screen they read up every thing in pixels
                  regards,
                  Omer

                  Comment

                  • ashindler
                    New Member
                    • Sep 2008
                    • 9

                    #10
                    I'm confused - that is what I did - I set the font-size to 9 points...

                    Comment

                    • ashindler
                      New Member
                      • Sep 2008
                      • 9

                      #11
                      When I check out Print Preview in Excel of the document, I can see that it is scaled down 54% to be printable on one page. Is their something equivalent that I can do to the document when it is loaded into the iframe?

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by ashindler
                        I'm not even sure why logically it would make sense to set the font-size. My excel spreadsheet contains all sorts of fonts and even images. So how would font-size affect those?
                        The reason why I suggested font size was that you mentioned in your original post that the font size was larger in the print out from the iframe. The reason your code had no effect was that an iframe is a separate document, so the stylesheet would have to be inside the iframe. I guess it's not as simple as I had originally thought which I had assumed based on your original post.
                        Originally posted by ashindler
                        If I had instead of an excel, an image loaded into the iframe would setting the font size in the iframe make a difference to the size of the image when it is printed from the iframe?
                        No, it wouldn't. Do the images come out the right size when printed over 4 pages?

                        Comment

                        • acoder
                          Recognized Expert MVP
                          • Nov 2006
                          • 16032

                          #13
                          Originally posted by ashindler
                          When I check out Print Preview in Excel of the document, I can see that it is scaled down 54% to be printable on one page. Is their something equivalent that I can do to the document when it is loaded into the iframe?
                          Not with JavaScript, but if your target is only one specific browser for a controlled user base, you could consider using a browser-specific solution. If not, you would have to include the stylesheet within the iframe.

                          Comment

                          • ashindler
                            New Member
                            • Sep 2008
                            • 9

                            #14
                            I am only going to be using IE - what sort of possible browser-specific solution is there?

                            By the way I tried to include a stylesheet within the iframe but setting the font size didn't change the output in any way either. I thought I would have to set the dimensions if it were possible of the "content" somehow because I am assuming that the iframe treats the excel sheet like it would an image and just displays the true size of it.

                            Comment

                            • acoder
                              Recognized Expert MVP
                              • Nov 2006
                              • 16032

                              #15
                              You can use ActiveX. There's an ActiveX control called Meadroid that you may find useful.

                              If you go with the HTML/CSS route, you could point the src to an HTML page which contains the Excel sheet contained within a div of the right size. I haven't tried it, so wouldn't know if it works.

                              Comment

                              Working...