printing full page which is in a Widget

179 views
Skip to first unread message

Manjunath

unread,
Dec 13, 2007, 4:12:38 PM12/13/07
to Google Web Toolkit, manjunat...@zustek.com
Hi All,


Anybody having idea to print the full page which having scroll, using
the GWT.

Please help me out.

Peter Blazejewicz

unread,
Dec 15, 2007, 8:40:52 PM12/15/07
to Google Web Toolkit
hi,

use: @media print
meta selector in your css to specify whcih containers are not printed
simply (mark them visible: none;)
for example you can hide yoru entire main DIV for printing and use
only some DIV which nicely flow your test and is visible,
http://webdesign.about.com/cs/css/a/aa042103a.htm

regards,
Peter

Andre Freller

unread,
Dec 17, 2007, 7:53:28 AM12/17/07
to Google-We...@googlegroups.com

Peter Blazejewicz

unread,
Dec 17, 2007, 3:16:08 PM12/17/07
to Google Web Toolkit
hi Andre,
your solution will work, but using CSS @screen/@print meta selectors
really simplifies everything and does not require additional code
(except of JSNI call to window.print()):

full example:

HTML:

<html>
<head>
<title>Wrapper HTML for PrintMeModule</title>
<meta name='gwt:module'
content='com.mycompany.project.PrintMeModule' />
<link type="text/css" rel='stylesheet' href='PrintMeModule.css' />
</head>
<body>
<!-- two types of content: screen and print -->
<!-- print tag -->
<div id="printContent">This will be printed</div>
<!-- cotnent area wont be printed-->
<div id="content"></div>
<script language="javascript"
src="com.mycompany.project.PrintMeModule.nocache.js"></script>
</body>
</html>


CSS:

@media print {
#content {
display: none;
}
}

@media screen {
#printContent {
display: none;
}
}

(NOTE: TWO DECLARATIONS!);

Java:

package com.mycompany.project.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.DeferredCommand;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.Widget;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class PrintMeModule implements EntryPoint {
private Button clickMeButton;

public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get("content");
clickMeButton = new Button();
rootPanel.add(clickMeButton);
clickMeButton.setText("Print me!");
clickMeButton.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
DeferredCommand.addCommand(new Command() {
/* @Override */
public native void execute()/*-{
window.print();
}-*/;

});
}
});
}
}


What will be printed?

"This will be printed"

(and everythin we add to "printContent" widget at runtime)

regards,
Peter

On Dec 17, 1:53 pm, "Andre Freller" <andre.frel...@gmail.com> wrote:
> Manjunath,
>
> See my last post on this thread:
>
> http://groups.google.com.my/group/Google-Web-Toolkit/browse_thread/th...
>
> Regards,
> Freller

Andre Freller

unread,
Dec 18, 2007, 7:52:16 AM12/18/07
to Google-We...@googlegroups.com
 
Hi Peter,
 
Indeed different approaches. My class can print any UI object. This way I can print any widget/panel layout I wish. It doesn't have to be prepared to be printed. You can also use an alternative CSS file for printing so you can maintain all print styles in a separate file. I think this is more object centric an easier to integrate so I use it in my codes and decided to share.
 
Regards,
Freller

Peter Blazejewicz

unread,
Dec 18, 2007, 4:22:24 PM12/18/07
to Google Web Toolkit
hi Andre,
> My class can print any UI object.
yes, but using
RootPanel.get("printContent").add(whateverSingleOrCompositeWidget)
doesn't do the same?
> It doesn't have to be prepared to be printed.
your code requires direct HTML page modification by adding iframe tag
manually and it could have issues accross browsers,
for example see: iframe/IExplore issues with print:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1102392&SiteID=1

regards,
Peter

On Dec 18, 1:52 pm, "Andre Freller" <andre.frel...@gmail.com> wrote:
> Hi Peter,
>
> Indeed different approaches. My class can print any UI object. This way I
> can print any widget/panel layout I wish. It doesn't have to be prepared to
> be printed. You can also use an alternative CSS file for printing so you can
> maintain all print styles in a separate file. I think this is more object
> centric an easier to integrate so I use it in my codes and decided to share.
>
> Regards,
> Freller
>

Peter Blazejewicz

unread,
Dec 18, 2007, 4:24:47 PM12/18/07
to Google Web Toolkit
On Dec 18, 10:22 pm, Peter Blazejewicz <peter.blazejew...@gmail.com>
wrote:
> hi Andre,> My class can print any UI object.
>
> yes, but using
> RootPanel.get("printContent").add(whateverSingleOrCompositeWidget)
> doesn't do the same?> It doesn't have to be prepared to be printed.
I meant:
DOM.setInnerHTML(RootPanel.get("printContent").getElement(),
widget.getElement.toString());
as well,

regards,
Peter
Reply all
Reply to author
Forward
0 new messages