diff --git a/server/controllers/invoiceController.js b/server/controllers/invoiceController.js index c5d9d70..faf6d79 100644 --- a/server/controllers/invoiceController.js +++ b/server/controllers/invoiceController.js @@ -71,8 +71,35 @@ exports.getInvoicePrint = async (req, res) => { const mode = req.query.mode === 'thermal' ? 'thermal' : 'a4'; const { renderInvoiceHtml } = require('../services/invoicePrintHtml'); const html = renderInvoiceHtml(invoice, { mode }); + + // Small on-screen toolbar (hidden in print), so the print tab isn't a + // dead-end page. Reuses the token passed for this tab to link the PDF. + const token = req.tokenFromQuery || String((req.headers && req.headers.authorization) || '').replace(/^Bearer\s+/i, ''); + const pdfFormat = mode === 'thermal' ? 'thermal80' : 'a4'; + const pdfHref = `/api/v1/invoices/${req.params.id}/pdf?format=${pdfFormat}&download=1&token=${encodeURIComponent(token)}`; + const title = String(invoice.invoiceNumber || 'Invoice').replace(/[<>&"]/g, ''); + + const chrome = ` + +
+`; + res.setHeader('Content-Type', 'text/html; charset=utf-8'); - return res.send(html); + return res.send(html.replace('