Spaces:
Running
Running
Enable PDF footer with page numbers (1/N) and powered-by text
Browse files
server.js
CHANGED
|
@@ -45,20 +45,29 @@ app.post('/api/generate_pdf', async (req, res) => {
|
|
| 45 |
// Inject styles to ensure 100% width and print media simulation
|
| 46 |
await page.addStyleTag({
|
| 47 |
content: `
|
| 48 |
-
@page { margin:
|
| 49 |
body { -webkit-print-color-adjust: exact; }
|
| 50 |
`
|
| 51 |
});
|
| 52 |
|
| 53 |
-
// Generate PDF
|
| 54 |
const pdfBuffer = await page.pdf({
|
|
|
|
| 55 |
printBackground: true,
|
| 56 |
-
preferCSSPageSize:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
margin: {
|
| 58 |
-
top:
|
| 59 |
-
bottom:
|
| 60 |
-
left:
|
| 61 |
-
right:
|
| 62 |
}
|
| 63 |
});
|
| 64 |
|
|
|
|
| 45 |
// Inject styles to ensure 100% width and print media simulation
|
| 46 |
await page.addStyleTag({
|
| 47 |
content: `
|
| 48 |
+
@page { margin: 0; size: A4; } /* Reset CSS page margin to let Puppeteer control it */
|
| 49 |
body { -webkit-print-color-adjust: exact; }
|
| 50 |
`
|
| 51 |
});
|
| 52 |
|
| 53 |
+
// Generate PDF with Header/Footer
|
| 54 |
const pdfBuffer = await page.pdf({
|
| 55 |
+
format: 'A4',
|
| 56 |
printBackground: true,
|
| 57 |
+
preferCSSPageSize: false, // Disable to ensure footerTemplate works
|
| 58 |
+
displayHeaderFooter: true,
|
| 59 |
+
headerTemplate: '<div></div>', // Empty header
|
| 60 |
+
footerTemplate: `
|
| 61 |
+
<div style="font-size: 8px; font-family: sans-serif; color: #888; width: 100%; text-align: center; padding-left: 10mm; padding-right: 10mm;">
|
| 62 |
+
<span style="margin-right: 10px;">Powered by XWX AI Chat Exporter</span>
|
| 63 |
+
<span><span class="pageNumber"></span> / <span class="totalPages"></span></span>
|
| 64 |
+
</div>
|
| 65 |
+
`,
|
| 66 |
margin: {
|
| 67 |
+
top: '10mm',
|
| 68 |
+
bottom: '20mm', // Space for footer
|
| 69 |
+
left: '10mm',
|
| 70 |
+
right: '10mm'
|
| 71 |
}
|
| 72 |
});
|
| 73 |
|