351 Print Preview

Print Preview

Two ways to preview the same document: an HTML paper view sized in real millimetres (what window.print() sends to your printer) and the PDF view generated on the server. Change any setting and both update.

Download PDF

Tip: the browser's print dialog also offers "Save as PDF" - a quick way to compare the HTML print with the server PDF.

Northwind Print Co., Ltd.
Northwind Print Co., Ltd.
88 Rama VI Road, Ratchathewi, Bangkok 10400
Tax ID 0105559999999
INVOICE
INV-202610-005
DRAFT
BILL TO
Green Valley International School
300 Moo 5, Nong Prue, Bang Lamung, Chon Buri 20150
Issue date21 Oct 2026
Due date20 Nov 2026
Amount due8,448.72
#DescriptionQtyUnit priceAmount
1Thermal Labels 50 x 30 mm (1,000) 12 250.00 3,000.00
2Price Tag Labels (10 rolls) 11 160.00 1,760.00
3Kraft Mailer Box S 6 12.00 72.00
4Price Tag Labels (10 rolls) 10 160.00 1,600.00
5Binder Clips Assorted (box) 11 120.00 1,320.00
6Kraft Mailer Box S 12 12.00 144.00
Subtotal7,896.00
VAT 7%552.72
Total (THB)8,448.72
QR
How it works
  • HTML paper view - the page is a <div> sized in real mm. CSS @page { size: 210mm 297mm; margin: 0 } sets the paper for the print dialog, and @media print in app.css hides the sidebar and buttons.
  • PDF view - the iframe loads /doc/view?key=invoice:5&preset=1... (HomeController.view). The response header Content-Disposition: inline makes the browser show it; attachment downloads it.
  • Print PDF calls iframe.contentWindow.print() - the browser's PDF viewer prints the server-made PDF.
return ResponseEntity.ok()
    .header(HttpHeaders.CONTENT_DISPOSITION, ContentDisposition.inline().filename(doc.fileName()).build().toString())
    .contentType(MediaType.APPLICATION_PDF)
    .body(doc.bytes());

Files: web/PrintSetupController.java, templates/preview.html, web/Downloads.java.