【发布时间】:2017-04-25 14:43:31
【问题描述】:
我需要在客户端打印一张图片。我使用this 作为模板。我的 PrintUI 如下所示:
@Override
protected void init(VaadinRequest request) {
Item item = ..get item ..
StreamResource imageStream = ... build image dynamically ...
Image image = new Image(item.getName(), imageStream);
image.setWidth("100%");
setContent(image);
setWidth("100%");
// Print automatically when the window opens
JavaScript.getCurrent().execute("setTimeout(function() {print(); self.close();}, 0);");
}
到目前为止,这在 IE 中有效,但在 chrome 中,它会打开显示空白页面的打印预览。问题是图像以某种方式加载,chrome 不会等待它并立即开始打印预览。
为了验证这一点,我尝试了:(设置 5 秒超时)
JavaScript.getCurrent().execute("setTimeout(function() {print(); self.close();}, 0);");
然后它可以在 IE 和 Chrome 中运行,但它当然是一个丑陋的 hack,如果连接速度低于 5 秒,那么它会再次失败。
在纯 JS 中它会像 this 一样工作,但我不确定如何在 cient-side js 中引用来自 vaadin 的元素。有任何想法吗?
【问题讨论】:
标签: spring-boot vaadin vaadin4spring