[CLOSED] [1.0] Print Window Contents

  1. #1

    [CLOSED] [1.0] Print Window Contents

    Hi,

    I have a printer-friendly aspx page that automatically where when called by itself, prints without a problem. When I displayed this page on a Ext.Window via autoload and mode=iframe, the print out is not correct. It only prints the size of the window, not the actual contents of the printer friendly page. Is there a way to correctly print the contents of the window?

    I tried the following but couldnt get it to work. Am I missing something here ? Perhaps an alternative solution? Any help would be greatly appreciated

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function printWindow() {
                Ext.getCmp('winEUA').iframe.print();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Slate">
            
        </ext:ResourceManager>
        
        <ext:Window Title="End User Agreement" runat="server" ID="winEUA" Width="400" Height="400">
            <BottomBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Button runat="server" ID="btnPrint" Text="Print" Icon="Printer">
                            <Listeners>
                                <Click Handler="printWindow();" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </BottomBar>
            <AutoLoad Url="http://msdnaa.oit.umass.edu/Neula.asp" Mode="IFrame"></AutoLoad>
        </ext:Window>
        </form>
    </body>
    </html>
    Thanks,
    Marcelo
    Last edited by geoffrey.mcgill; Jul 19, 2010 at 10:45 PM.
  2. #2
    Hi,

    I think the browser will throw a Permission Exception if trying to print an iframe document from another domain.

    I'll do some research and see if there's any way to work around this limitation.

    If the document was in the same domain, the following script should work.

    Example

    winEUA.getBody().print();
    Geoffrey McGill
    Founder
  3. #3
    Hi Geoffrey,

    Thanks for the response. I tried your solution on IE8 but the print out is still not correct, it only prints the actual size of the window, and the contents gets crop-out. Do you have any other suggestion/solution?

    Again, I appreciate your help on this.
  4. #4
    I did a few google searches for printing <iframe> content and read about a suggestion to call .focus() before .print().

    Example

    <script type="text/javascript">
        var printWindow = function () {
            Window1.getBody().focus();
            Window1.getBody().print();
        };
    </script>
    Hope this helps.
    Geoffrey McGill
    Founder
  5. #5

    Print()

    hi,
    i try to print window content using below sample codes. The print() method is not support, i got javascript error, object doesn't support method or property.. plz reply soon... how to print window content...



    <script type="text/javascript"> 
        var printWindow1 = function () 
         { 
            'winEUA'.getBody().focus(); 
            'winEUA'.getBody().print(); 
        }; 
     
    winEUA.getBody().print();
     
    Ext.getCmp('winEUA').iframe.print(); 
     
    
    </script>
  6. #6
    Last edited by Daniil; Sep 22, 2010 at 2:40 PM.
  7. #7

    sample code

    hi,
    i have post a sample code, plz take a look.. The Print() method is not working.. i got js error...



    <%@ Page Language="C#" %>
      
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head id="Head1" runat="server"> 
        <title></title> 
        <script type="text/javascript"> 
            function printWindow() 
            {       
           Ext.getCmp('winEUA').print();
            } 
        </script> 
    </head> 
    <body> 
        <form id="form1" runat="server"> 
        <ext:ScriptManager ID="ResourceManager1" runat="server" Theme="Slate"> 
              
        </ext:ScriptManager> 
          
        <ext:Window Title="End User Agreement" runat="server" ID="winEUA" Width="400" Height="400"> 
            <BottomBar> 
                <ext:Toolbar ID="Toolbar1" runat="server"> 
                    <Items> 
                        <ext:Button runat="server" ID="btnPrint" Text="<SPAN class=highlight>Print</SPAN>" Icon="Printer"> 
                            <Listeners> 
                                <Click Handler="printWindow();" /> 
                            </Listeners> 
                        </ext:Button> 
                    </Items> 
                </ext:Toolbar> 
            </BottomBar> 
            <AutoLoad Url="http://msdnaa.oit.umass.edu/Neula.asp" Mode="IFrame"></AutoLoad> 
        </ext:Window> 
        </form> 
    </body> 
    </html>
  8. #8
    Hi,

    There was a defect in the .getBody() function. Please SVN update.

    After update, you should call the following...

    Example

    winEUA.getBody().print();
    No need for the Ext.getCmp() call.

    The .getBody() function will return an instance of the child page, so then you can just call .print() on the child page/document.

    Hope this helps.
    Geoffrey McGill
    Founder
  9. #9
    Hi majestic,

    Geoffrey is absolutely right, now it's work fine.

    Here is a full working sample.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Window 
            ID="Window1" 
            runat="server" 
            Title="Window" 
            Width="400" 
            Height="400">
            <AutoLoad Url="somePage.aspx" Mode="IFrame" />
            <BottomBar>
                <ext:Toolbar runat="server">
                    <Items>
                        <ext:Button runat="server" Text="Print" Icon="Printer">
                            <Listeners>
                                <Click Handler="#{Window1}.getBody().print()" />
                            </Listeners>
                        </ext:Button>
                    </Items>
                </ext:Toolbar>
            </BottomBar>
        </ext:Window>
        </form>
    </body>
    </html>

Similar Threads

  1. [CLOSED] How I print ext:Window content?
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Feb 29, 2012, 4:00 PM
  2. Replies: 6
    Last Post: Feb 18, 2011, 2:12 PM
  3. [CLOSED] Print a Window
    By rthiney in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Jun 01, 2010, 10:30 PM
  4. Replies: 1
    Last Post: Mar 25, 2010, 5:59 PM
  5. [CLOSED] How to print contents of an iFrame tab?
    By iansriley in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 13, 2009, 12:40 PM

Tags for this Thread

Posting Permissions