-
13 Mar 2013 6:29 PM #1
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
then to use itCode: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()); } }
view is a gxt grid. thanks for your reply!Code:Print.it("<link type='text/css' rel='stylesheet' href='WebCheckGXT.css'>", view);
-
29 Mar 2013 2:55 PM #2
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.
-
30 Mar 2013 4:22 PM #3
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:
Instead, consider something like getOuterHTML(), or processing the data differently to make sure you get what you are after (like a template).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); }
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.



Reply With Quote