user3855323
user3855323

Reputation: 61

How to Print in Vaadin

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.

Upvotes: 1

Views: 1188

Answers (2)

Basil Bourque
Basil Bourque

Reputation: 339382

Straight out of the 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.

Upvotes: 1

downdrown
downdrown

Reputation: 361

There's no "built-in" API for printing in Vaadin. You have to use the browser's native printing API.

Upvotes: 0

Related Questions