Query regarding printing a widget

3 views
Skip to first unread message

abhiram

unread,
Nov 20, 2009, 12:32:11 PM11/20/09
to Google Web Toolkit
Hi All,

I just needed some help regarding a functionality where i need to
print the contents of a widget.

I am using the Print.it() function. I am able to print the HTML
string using the function Print.it("Just <b>Print.it()</b>!"). This
happens successfully, but am not able to print the contents of a
particular rootPanel. The rootPanel has a couple of buttons and a
textBox with some text. I have been using the following command for
this

Print.it(rootPanel.get("__printingFrame"));

I know I am missing something here. But am not sure how to proceed.
When i fire this command I just get the text " [object] " printed.
Can someone help me out at this point? What else do i need to do to
get the contents of the TextBox printed.

This was the entry that I made in html file.
<iframe id="__printingFrame" style="width:0;height:0;border:0"></
iframe>

I saw some previous codes where I got some info, but am looking out
for a very specific example where a textBox is passed as an argument
and I get only the contents of it printed.

Can someone please suggest what do I need to do?

regards,
Abhiram

abhiram wuntakal

unread,
Nov 21, 2009, 4:10:46 AM11/21/09
to Google Web Toolkit
Hi,

  Can someone please suggest a possible solution for this?

Regards,
Abhiram

Dan

unread,
Nov 21, 2009, 8:27:15 AM11/21/09
to Google Web Toolkit
You can do it with a class and a way to pass a string to it.

// ========= class code ===============
public class PrintWidgetClass2 {

native void printx(String s) /*-{

var win1 = window.open('', 'reportwindow');
win1.document.open();
win1.document.write("<head><title>Report</title>");
win1.document.write("<style> body,td {font-family:sans-serif;font-
size:10pt;}</style>");
win1.document.write("<script> \r\n")
win1.document.write("function Print(){window.print()}</script>")
win1.document.write("</head><body onload=\"Print()\">");
win1.document.write(s);
win1.document.write("</body></html>");
win1.document.close();
}-*/;

public void printIt(String html){
printx(html);
}

}
// ========== end of class code ============

Now for a way to call it. Say you have a widget (panel, whatever) that
you want to print. Use this code:

// ========= begin calling code ===========
StringBuffer sb = new StringBuffer();
sb.append(titlePanel.getElement().getString());
sb.append(header.getElement().getString());
sb.append(dataList.getElement().getString());
PrintWidgetClass2 cc = new PrintWidgetClass2();
cc.printIt(sb.toString());

// ========== end of calling code ==========

Notice that in this case the code puts together several widgets, not
just one, and prints the combined result

achilles hector

unread,
Nov 21, 2009, 5:12:58 AM11/21/09
to google-we...@googlegroups.com
Hi,
this print method is in Document or Window object if i am not wrong.
you can print the content using "jsni" using $doc.print or $wnd.print



--

You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.

Reply all
Reply to author
Forward
0 new messages