Can anyone tell me how to print gwt widget?
I gont through the folowing thread and tried .
http://groups.google.com/group/Google-Web-Tool开发者_如何学运维kit/browse_thread/thread/eea48bafbe8eed63
Still I cant do that.I can able to print the widget without any css style.I want to include the css styles(css files) also.Thanks for your valuable help.
I have faced similar situation using the same link you have used. It prints String, Widgets,Or Elements without any problem.
Solution I found is that you need some delay before you call Print.
So, There are few alternate solutions. 1. Write down a loop which causes delay of 2-3 seconds. 2. Use Time to get delay of 2-3 seconds 3. Use Window.Confirm to ask some question like 'Do you want to print ?'
Hope this will help to others
You can create your own class and on click of Print button in your application, by using native print method you can call Window.Print().
GWT UIObject can be used for this purpose and the method and it will be converted into string.
public class NTPrint {
/**
* If true, use a Timer instead to print the internal frame
*/
public static boolean USE_TIMER = true;
/**
* Time in seconds to wait before printing the internal frame when using Timer
*/
public static int TIMER_DELAY = 1;
public static native void it() /*-{
$wnd.print();
}-*/;
public static void it(String html) {
try{
buildFrame(html);
if (USE_TIMER) {
Timer timer = new Timer() {
public void run() {
printFrame();
}
};
timer.schedule(TIMER_DELAY * 1000);
} else {
printFrame();
}
}
catch (Throwable exc) {
CommonUtil.printStackTrace(exc);
Window.alert(exc.getMessage());
}
}
/**
* This method will be called when you pass Widget without style.
* @param uiObjects
*/
public static void it( UIObject...uiObjects) {
StringBuffer objString= new StringBuffer();
for(UIObject obj: uiObjects)
objString.append(obj.toString());
it("", objString.toString());
}
}
OnClick of Print button,
/**
* prints all forms
* @param documentInfo
*/
public static void printForms(List<FormTransaction> formTransactions, String documentInfo, List<CellTransaction> cellTransactionList, boolean isComment, Document document) {
String style = "<link rel='styleSheet' type='text/css' href='v4workflow/css/style.css'>"
+ "<link rel='styleSheet' type='text/css' href='v4workflow/css/gwtcontrols.css'>"
+ "<style type='text/css' media='print'>"
+ "@media print {"
+ ".footerText{font-size:13px; font-weight:normal;margin-top:0px;}"
+ ".break {page-break-after:always}"
+ "}" + "</style>";
List<UIObject> uiObjects = new ArrayList<UIObject>();
NTPrintLayout printLayout = new NTPrintLayout();
printLayout.setSelectedDocument(null);
uiObjects.add(createHeader());
NTPrint.it(style,uiObjects);
}
public static FlexTable createHeader(){
FlexTable flexTable = new FlexTable();
flexTable.setWidth("100%");
return flexTable;
}
精彩评论