A practical walkthrough of four approaches to printing and PDF generation in Vaadin Java web apps: (1) styling the live DOM with @media print CSS, including fixes for vaadin-app-layout quirks; (2) rendering a dedicated print-optimized view for components like virtualized Grids that can't be paginated; (3) generating PDFs server-side using Apache PDFBox with options for download links or a hidden-iframe print trigger; and (4) bypassing the OS print dialog entirely via Web Bluetooth for direct label printer access or server-side printing via WebSocket-connected devices like a Raspberry Pi. Each approach is illustrated with runnable code snippets and a decision table to help choose the right method based on use case.

11m read timeFrom blog.vaadin.com
Post cover image
Table of contents
1. Just print and style with CSS1.b Print and use JS hook for preparations2. Construct a print-optimized page3. Generate a PDF4. Skip the OS print dialog entirelyPicking an approach

Sort: