谁能告诉我如何打印gwt部件?打印gwt部件
我gont通过下面的线程和尝试。
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/eea48bafbe8eed63
不过我不能做that.I可以能够打印部件没有任何CSS style.I想包括CSS样式(CSS文件)also.Thanks您的宝贵帮助。
谁能告诉我如何打印gwt部件?打印gwt部件
我gont通过下面的线程和尝试。
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/eea48bafbe8eed63
不过我不能做that.I可以能够打印部件没有任何CSS style.I想包括CSS样式(CSS文件)also.Thanks您的宝贵帮助。
我遇到了类似的情况,使用您使用过的相同链接。 它打印字符串,小工具或元素没有任何问题。
我发现的解决方法是,在打印之前您需要一些延迟。
所以,有很少的替代解决方案。 1.写下导致延迟2-3秒的循环。 2.使用时间延迟2-3秒 3.使用Window.Confirm问一些问题,如'您想打印吗?'
希望这将有助于其他
您可以在应用程序中创建自己的类和打印按钮的点击,通过使用本机的打印方法,你可以调用Window.Print()。
GWT UIObject可用于此目的和方法,它将被转换为字符串。
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,
/**
* 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;
}
你为什么要这么做?也许有另一种方法来实现你所需要的。 – sinelaw 2011-01-14 07:43:51
@ sinelaw-我无法回答你的第一个问题。这取决于我的项目要求。更好的请发布你的替代方式来解决这个问题。 – DonX 2011-01-17 09:43:51
来自Google群组的例子非常好。如果你想打印图片,我建议你使用media =“print”。但不要忘记,许多浏览器默认都有禁用打印背景图像的选项(例如在Firefox中:文件>页面设置>选项>打印背景(颜色和图片))。有没有办法用一个棘手的CSS或其他任何东西来覆盖这个选项... – Naoj 2011-02-10 09:20:33