From 36d34201253a5be1d28157b924adf81a34b67c2d Mon Sep 17 00:00:00 2001 From: isUnknown Date: Mon, 8 Dec 2025 14:02:41 +0100 Subject: [PATCH] fix: inline all styles when printing PagedJS content MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Collect all CSS (inline styles and stylesheet rules) and embed them directly in the print document. This ensures styles are available even when printed from a new window. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/App.vue | 66 ++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 16 deletions(-) diff --git a/src/App.vue b/src/App.vue index 38a69d1..f51be59 100644 --- a/src/App.vue +++ b/src/App.vue @@ -275,32 +275,66 @@ watch( ); // Handle Cmd+P / Ctrl+P to print the iframe content -const handlePrint = (event) => { +const handlePrint = async (event) => { if ((event.metaKey || event.ctrlKey) && event.key === 'p') { event.preventDefault(); const frame = activeFrame.value; if (frame && frame.contentDocument) { - // Get the full HTML content of the iframe - const content = frame.contentDocument.documentElement.outerHTML; + const doc = frame.contentDocument; - // Open a new window with the content + // Collect all styles (inline and from stylesheets) + let allStyles = ''; + + // Get inline + + ${bodyContent} + + `; + + // Open print window const printWindow = window.open('', '_blank'); - printWindow.document.write(content); + printWindow.document.write(printContent); printWindow.document.close(); - // Wait for content to load then print - printWindow.onload = () => { + // Wait for rendering then print + setTimeout(() => { printWindow.print(); printWindow.close(); - }; - - // Fallback if onload doesn't fire - setTimeout(() => { - if (!printWindow.closed) { - printWindow.print(); - printWindow.close(); - } - }, 500); + }, 100); } } };