打印gwt小部件
有人能告诉我如何打印gwt小部件吗 我穿过下面的线试了试打印gwt小部件,gwt,printing,Gwt,Printing,有人能告诉我如何打印gwt小部件吗 我穿过下面的线试了试 但是我还是做不到。我可以在没有任何css样式的情况下打印小部件。我还想包括css样式css文件。感谢您的宝贵帮助。我使用您使用的相同链接遇到过类似情况。 它可以毫无问题地打印字符串、小部件或元素 我找到的解决方案是,在调用Print之前需要一些延迟 因此,几乎没有替代解决方案。 1.写下一个导致延迟2-3秒的循环。 2.使用时间获得2-3秒的延迟 3.使用窗口。确认询问一些问题,如“是否要打印?” 希望这将对其他人有所帮助我使用了与您相同
但是我还是做不到。我可以在没有任何css样式的情况下打印小部件。我还想包括css样式css文件。感谢您的宝贵帮助。我使用您使用的相同链接遇到过类似情况。 它可以毫无问题地打印字符串、小部件或元素 我找到的解决方案是,在调用Print之前需要一些延迟 因此,几乎没有替代解决方案。 1.写下一个导致延迟2-3秒的循环。 2.使用时间获得2-3秒的延迟 3.使用窗口。确认询问一些问题,如“是否要打印?”
希望这将对其他人有所帮助我使用了与您相同的链接,遇到了类似的情况。 它可以毫无问题地打印字符串、小部件或元素 我找到的解决方案是,在调用Print之前需要一些延迟 因此,几乎没有替代解决方案。 1.写下一个导致延迟2-3秒的循环。 2.使用时间获得2-3秒的延迟 3.使用窗口。确认询问一些问题,如“是否要打印?”
希望这对其他人有所帮助您可以创建自己的类,并在应用程序中单击“打印”按钮,使用本机打印方法调用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());
}
}
单击打印按钮
您可以创建自己的类,然后单击应用程序中的“打印”按钮,使用本机打印方法调用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());
}
}
单击打印按钮
你为什么要这样做?也许有另一种方法可以实现你想要的need@sinelaw-我不能回答你的第一个问题。这取决于我的项目要求。最好请发布你的替代方法来解决这个问题。谷歌集团的例子真的很好。如果你想打印图片,我建议你使用media=print。但别忘了,默认情况下,许多浏览器都有一个选项可以禁用打印背景图像,例如在firefox中:文件>页面设置>选项>打印背景颜色和图片。没有办法用复杂的css或其他什么来覆盖这个选项…你为什么要这样做?也许有另一种方法可以实现你想要的need@sinelaw-我不能回答你的第一个问题。这取决于我的项目要求。最好请发布你的替代方法来解决这个问题。谷歌集团的例子真的很好。如果你想打印图片,我建议你使用media=print。但别忘了,默认情况下,许多浏览器都有一个选项可以禁用打印背景图像,例如在firefox中:文件>页面设置>选项>打印背景颜色和图片。没有办法用复杂的css或其他什么来覆盖这个选项。。。