Printing in a Liferay Vaadin portlet

Hi,

I’m having trouble in getting a Vaadin portlet to print some html to the printer. The following snippet works
fine when running the application as a servlet (from http://vaadin.com/book/-/page/advanced.printing.html):


Window printWindow = new Window("Print Window");
printWindow.addComponent(new Label(htmlOutputStream.toString("UTF-8"),  Label.CONTENT_XHTML));
application.addWindow(printWindow);
application.getMainWindow().open(new ExternalResource(printWindow.getURL()), "_blank", 
500, 200, Window.BORDER_NONE);
// Print automatically when the window opens.
// This call will block until the print dialog exits!
printWindow.executeJavaScript("print();");
//Close the window automatically after printing
printWindow.executeJavaScript("self.close();");

However in Liferay 5.2.3 portlet container printWindow.getUrl() returns null, so I’m unable open it as en ExternalResource this way. Is there some workaround for this or some other way alltogether to be able to print in a portlet environment?

Found a workaround. Putting the html inside a Vaadin CustomLayout and setting it visible only via css media type ‘print’. This way no new window needs to be opened for printing since the CustomLayout is included to the main window and is only visible for printing.

Hi,

could you post a short source-snippet and the css for this? We have the same problem here and your solution sounds better than opening a new window every time…

Regards
Andreas

Argh, I was too hesitant to rejoice my solution, after testing it more it broke down. In my current solution which I hacked together i I just open a dedicated print view and use css to hide undesired elements, it’s pretty messy to say the least. So an elegant solution is still required…