Printing with styles

3 posts, 0 answers
  1. Karl Wigart
    Karl Wigart avatar
    6 posts
    Member since:
    Feb 2006

    Posted 12 May 2009 Link to this post

    I have tried to get your example (http://www.telerik.com/help/aspnet-ajax/printingcontentwithstyles.html) to work in Firefox but it is not working.

    When I click the custom print button, the iframe is created and then nothing happens and the status of the browser is reporting "stopped" rather than done.

    It all works fine in IE 7.

    I'm using Telerik version 2009.1.402.35 and Firefox 3.0.10

    I have tried it on a different machine with the same version of Firefox.

    Any suggestions would be helpful.

    Karl
  2. Rumen
    Admin
    Rumen avatar
    12851 posts

    Posted 15 May 2009 Link to this post

    Hi Karl,

    I was able to print the content in FF3.0.10 by closing the print document after the print() method execution, e.g.

     <telerik:RadEditor runat="server" ID="RadEditor1"
       <Tools> 
           <telerik:EditorToolGroup > 
               <telerik:EditorTool Name="CustomPrint" /> 
           </telerik:EditorToolGroup> 
       </Tools>   
       <Content> 
        <span class="Test">sample test content</span> 
       </Content> 
    </telerik:RadEditor>  
     <script type="text/javascript"
    Telerik.Web.UI.Editor.CommandList["CustomPrint"] = function(commandName, editor, args) 
       var printIframe = document.createElement("IFRAME"); 
       document.body.appendChild(printIframe); 
       var printDocument = printIframe.contentWindow.document
       printDocument.designMode = "on"
       printDocument.open(); 
       var currentLocation = document.location.href; 
       currentLocation = currentLocation.substring(0, currentLocation.lastIndexOf("/") + 1); 
       printDocument.write( "<html><head></head><body>" + editor.get_html(true) + "</body></html>"); 
        
       try 
       { 
           if ($telerik.isIE) 
           { 
             var oLink = printDocument.createElement("link"); 
             oLink.setAttribute( "href", currentLocation + "PrintWithStyles.css", 0); 
             oLink.setAttribute( "type""text/css"); 
             oLink.setAttribute( "rel""stylesheet", 0); 
             printDocument.getElementsByTagName( "head")[0].appendChild(oLink); 
             printDocument.execCommand("Print"); 
           } 
           else if ($telerik.isFirefox) 
           { 
             printDocument.body.innerHTML = "<link rel='stylesheet' type='text/css' href='" + currentLocation + "PrintWithStyles.css'></link>" + printDocument.body.innerHTML
             printIframe.contentWindow.print(); 
           } 
           //Telerik changed: close here the print document 
           printDocument.close(); 
       } 
       catch(ex) 
       { 
       } 
       document.body.removeChild(printIframe); 
    }; 
    </script>  

    For your convenience I have attached my test page.

    Best regards,
    Rumen
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Karl Wigart
    Karl Wigart avatar
    6 posts
    Member since:
    Feb 2006

    Posted 15 May 2009 Link to this post

    Thanks Rumen,

    That works.

    Karl
Back to Top