-1

we have admin dashboard build in gwt and deployed on google app engine for java. On the dashboard there is a feature called "my card" where a blood donor can see his blood donor registration card with us.

Currently, we are creating and storing this card on google storage and when someone goes to "My Card" we render the card using iFrame in our dashboard.

We want to give the ability to print this card. Please tell how to do it?

just to add on i tried Print.it jar but seems like it is obsolete and does not play nice with gwt anymore

4

2 回答 2

3

Add this script to the iframe content page's tag

<script type="text/javascript">
function printPage() {focus();print(); }
</script>

Add this native method to your GWT class

public native void printIframeContent(String id)/*-{
    var iframe = $doc.getElementById(id);
    var ifWin = iframe.contentWindow || iframe;
    iframe.focus();
    ifWin.printPage();
    return false;
}-*/;

The action handler for print button's click event.

public void onClick(ClickEvent event) {
    printIframeContent("printiframe"); // Use the correct id for your iframe
}

Code is derived from this discussion

于 2012-07-25T11:34:34.913 回答
0

Here is a simple Printer class for GWT. It prints out the page.

import com.google.gwt.user.client.ui.UIObject;

import com.google.gwt.user.client.Element;

public class Printer {

public static native void it(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(UIObject obj) {
    it("", obj.getElement().toString());
}
public static void it(Element element) {
    it("", element.toString());
}
public static void it(String style, String it) {
    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());
}

}

于 2013-12-09T15:06:52.813 回答