0

I want to print one panel of page in GWT.

However someone said that you must use iframe because it has print method.

I tried this code but it does not work:

     HTML html=new HTML("<iframe id="myframe"></iframe>") ;....
    searchButton.setWidth("80px");
            searchButton.addClickHandler(new ClickHandler() {

                @Override
                public void onClick(ClickEvent event) {
                    MyNative.printIframeContent("myframe", "onlineMap");

                }
            });
    map = new SimplePanel();
    map.getElement().setId("onlineMap");
    map.add(mapView.getMapWidget());

mapView .is an instance of a class that returns a GWT MapWidget and in this manner I want to add GWT map to iframe then use print capability of iframe to print google map

MyNative is a class that use GWT JSNI to call the printPage javascript function

function printPage(idMap,idFrame) {
    var myElement = document.getElementById(idMap);
    var iframe = document.getElementById(idFrame);
    var body = iframe.getElementsByTagName('body');
    body.innerHTML = myElement;
    iframe.contentWindow.print();
}

but browser can not load body of iframe.

Cœur
  • 37,241
  • 25
  • 195
  • 267
user1738224
  • 23
  • 1
  • 9

1 Answers1

1

You can try this:

String html = myPanel.getElement().getInnerHTML();
print(html);


public static final native void print(String html) /*-{

    top.consoleRef=$wnd.open('','_blank', "");
    top.consoleRef.document.write(html);
    top.consoleRef.print();
    top.consoleRef.document.close()

}-*/;
Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • Thanks a lot, It works, but it only print map and not thing in the map,I mean I have some marker that show path of an object but don't print that path. – user1738224 Aug 25 '14 at 13:20