i have this electron code, and whene i remove the css the print works, but whene add css…
- User
i have this electron code, and whene i remove the css the print works, but whene add css the print doesn't work : // Load the content into a temporary window const printWin = new BrowserWindow({ show: false, // Don't show the window webPreferences: { nodeIntegration: true, contextIsolation: false, // Be cautious in production }, });
// Create an HTML document with the content printWin.loadURL( "data:text/html;charset=utf-8," + encodeURIComponent(`body { margin: 0; padding: 0; font-family: Arial, sans-serif; } .print-container { width: 80mm; height: 60mm; box-sizing: border-box; padding-right: 10mm; padding-top: 12mm; padding-bottom: 12mm; } .test { width: 100%; height: 100%; display: flex; } .height-content { display: flex; align-items: flex-end; justify-content: flex-end; height: 35mm; max-height: 35mm; } .image { width: 6rem; /* approx 24px */ align-self: flex-end; margin: 0; padding: 0; } .content-container { display: flex; flex-direction: column; gap: 0.25rem; width: 100%; position: relative; } .title { font-weight: 600; font-size: 11px; color: #374151; } .element-container { display: flex; gap: 0.25rem; justify-content: space-between; align-items: flex-start; } .zone { border-width: 1px; border-color: #10B981; color: #10B981; padding: 0.125rem 0.5rem; border-radius: 0.375rem; font-size: 9px; } .footer { position: absolute; bottom: 0.5rem; } .footer-text { font-size: 8px; color: #374151; line-height: 1; } .padmar { padding-right: 10px !important; } </style> </head> <body> <div class="print-container"> <div class="test" dir="rtl"> ${content} </div> </div> </body>// When the content is loaded, print it printWin.webContents.on("did-finish-load", () => { printWin.webContents.print( { silent: true, printBackground: true, }, (success, errorType) => { if (!success) console.log(errorType); printWin.close(); // Close the window after printing event.returnValue = 1; } ); }); - Assistant
When you add CSS to your Electron application, and the print functionality stops working, it usually indicates a potential conflict or error related to the way styles are rendered or how the content is structured. Here are a few suggestions to troubleshoot and potentially fix the issue: