How to print in GWT?

1,058 views
Skip to first unread message

list...@gmail.com

unread,
Jan 4, 2008, 5:39:52 AM1/4/08
to Google Web Toolkit
Hi,

Is it possible to print using GWT application? Is there any API
available for printing on the client side?

~ Sundar ~

Robert Hanson

unread,
Jan 4, 2008, 9:13:04 AM1/4/08
to Google-We...@googlegroups.com
The only thing that JavaScript can do in the client is pop up the
print dialog. You can do this with a little JSNI.

/** Untested.
* @return true if dialog was displayed, false if browser not capable.
*/
public native boolean showPrintDialog () /*-{
if (window.print) {
window.print();
return true;
}
else {
return false;
}
}-*/;


Rob
http://roberthanson.name

Dave

unread,
Jan 4, 2008, 10:32:15 AM1/4/08
to Google Web Toolkit
The other option, if you have sophisticated printing requirements is
to integrate something like JasperReports or the iText PDF library to
produce a printable PDF file.

Dave

On Jan 4, 9:13 am, "Robert Hanson" <iamroberthan...@gmail.com> wrote:
> The only thing that JavaScript can do in the client is pop up the
> print dialog. You can do this with a little JSNI.
>
> /** Untested.
> * @return true if dialog was displayed, false if browser not capable.
> */
> public native boolean showPrintDialog () /*-{
> if (window.print) {
> window.print();
> return true;
> }
> else {
> return false;
> }
>
> }-*/;
>
> Robhttp://roberthanson.name

Fred Sauer

unread,
Jan 4, 2008, 10:40:07 AM1/4/08
to Google-We...@googlegroups.com
Not to start a long list of server side PDF generating solutions, but you may also find Apache FOP useful:
  http://xmlgraphics.apache.org/fop/

Fred

Jason Essington

unread,
Jan 4, 2008, 11:06:43 AM1/4/08
to Google-We...@googlegroups.com
hi Rob,

Did you perhaps mean ...

if ($wnd.print) {
$wnd.print();


return true;
} else {
return false;
}

-jason

Reply all
Reply to author
Forward
0 new messages