1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    8
    Vote Rating
    0
    giggle16 is on a distinguished road

      0  

    Default Unanswered: problem with printing widget

    Unanswered: problem with printing widget


    i have searched online for printing gxt widget like grid or window and work fine with eclipse debug moded. but when it run in tomcat ,i do not work and print nothing.this is my code;
    print.java
    Code:
    import com.google.gwt.user.client.Element;
    import com.google.gwt.user.client.Window;
    import com.google.gwt.user.client.ui.UIObject;
    
    
    public class Print {
    
    
        public static native void it() /*-{                                                                                                            
            $wnd.print();                                                                                                                              
        }-*/;
    
    
    
    
        public static native void doit(String html) /*-{                                                                                               
    
    
            var frame = $doc.getElementById('__printingFrame');                                                                                        
            if (!frame) {                                                                                                                              
                $wnd.alert("Error: Can't find printing frame.");                                                                                       
                return;                                                                                                                                
            }                                                                                                                                          
            frame = frame.contentWindow;                                                                                                               
            var doc = frame.document;                                                                                                                  
            doc.open();                                                                                                                                
            doc.write(html);                                                                                                                           
            doc.close();                                                                                                                               
                                                                                                                                                                                                                                                                   
            frame.focus();                                                                                                                             
            frame.print();                                                                                                                             
        }-*/;
    
    
    
    
        public static void it(String html) {
            try { 
                doit(html);
            } catch (Throwable exc) {
                Window.alert(exc.getMessage());
    
    
            }    
        }
        public static void it(UIObject obj) {
            it("", obj.getElement().toString());
        }
    
    
        public static void it(Element element) {
            it("", element.toString());
        }
    
    
    
    
        public static void it(String style, String it) {
    
    
            it("<html><head>"+style+"</head>\n<body>"+it+"</body></html>"); 
        	 //it("<it><header>"+style+"</header><body>"+it+"</body></it>"); 
        }
         
        public static void it(String style, UIObject obj) {
            it(style, obj.getElement().toString());
        }
         
        public static void it(String style, Element element) {
            it(style, element.toString());
        }
    }
    then to use it
    Code:
    Print.it("<link type='text/css' rel='stylesheet' href='WebCheckGXT.css'>", view);
    view is a gxt grid. thanks for your reply!

  2. #2
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    We've run into this issue as well. I think the problem has to do with the brower's treatment of the way images are handled in GXT. IIRC, the images are rendered as background images and I think browsers don't print them. (Checkboxes in a selection grid also don't print).

    Our solution was to create our tabular data in a separate window not using GXT and then execute a print.

  3. #3
    Sencha - GXT Dev Team
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,717
    Answers
    109
    Vote Rating
    88
    Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light Colin Alworth is a glorious beacon of light

      0  

    Default


    This could also be related to the fact that you are picking up the html of the grid, but none of its styling, which is done via CSS on the html page.

    Please note that Element.toString() might not print anything useful:
    Code:
      /**
       * Makes a best-effort attempt to get a useful debugging string describing the
       * given JavaScriptObject. In Production Mode with assertions disabled, this
       * will either call and return the JSO's toString() if one exists, or just
       * return "[JavaScriptObject]". In Development Mode, or with assertions
       * enabled, some stronger effort is made to represent other types of JSOs,
       * including inspecting for document nodes' outerHTML and innerHTML, etc.
       */
      @Override
      public final String toString() {
        return JavaScriptObject.class.desiredAssertionStatus() ?
            toStringVerbose(this) : toStringSimple(this);
      }
    Instead, consider something like getOuterHTML(), or processing the data differently to make sure you get what you are after (like a template).

    Have you tried making that iframe visible and seeing what is displayed *without* printing? If that displays content, have you tried printing with the iframe visible instead of hidden?

    Printing a grid isn't always a great idea without some specific changes made, since the grid draws headers at the top and scrollbars - that doesn't look great on the printed page, which should probably get headers repeated each page and should flow instead of only printing what is visible on the user's screen. We usually suggest (like icfantv said) to render the content in a specific way that looks good on a printed page - black and white, or at least higher contrast than blue/black, and no scrollbars.

    Can you share a full example that doesn't work, including the Grid itself and the contents of the WebCheckGXT.css file? It is possible that there is something in your grid itself that is preventing this, but we'll never see it without being able to verify that code.

Thread Participants: 2