gpt4 book ai didi

java - 如何在 Vaadin 中打印

转载 作者:行者123 更新时间:2023-11-30 06:50:14 25 4
gpt4 key购买 nike

我有一个 VerticalLayout,其中填充了 Vaadin 中的组件。请我按照 A4 纸的方式打印此布局。任何想法如何做到这一点,代码示例都会很棒。

最佳答案

直接出自Vaadin doc ...

Printing the Browser Window

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();");
}
});

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.

关于java - 如何在 Vaadin 中打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42963270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com