如何在Vaadin中打印 [英] How to Print in Vaadin
问题描述
我有一个用Vaadin填充组件的VerticalLayout.请我将完全按照A4纸张打印此布局.任何想法如何做到这一点,代码示例都会很棒.
I have a VerticalLayout filled with components in Vaadin. PLease i will to print this layout exactly as it is to an A4 paper. Any Idea how to do this, Code Sample will be great.
推荐答案
直接从 Vaadin文档…
打印浏览器窗口
Printing the Browser Window
Vaadin不支持在浏览器中启动打印,但是您可以轻松地使用JavaScript print()方法打开浏览器的打印窗口.
Vaadin does not have special support for launching the printing in browser, but you can easily use the JavaScript print() method that opens the print window of the browser.
Button print = new Button("Print This Page");
print.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
// Print the current page
JavaScript.getCurrent().execute("print();");
}
});
上面示例中的按钮将打印当前页面,包括按钮本身.您可以在CSS中隐藏此类元素,也可以为页面设置样式以进行打印.用于打印的样式定义是在CSS的@media print {}块中定义的.
The button in the above example would print the current page, including the button itself. You can hide such elements in CSS, as well as otherwise style the page for printing. Style definitions for printing are defined inside a @media print {} block in CSS.
这篇关于如何在Vaadin中打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!