XWX-AI commited on
Commit
c04468e
·
1 Parent(s): 6907e14

Use preferCSSPageSize: true for exact print preview matching

Browse files
Files changed (1) hide show
  1. server.js +6 -6
server.js CHANGED
@@ -45,20 +45,20 @@ 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: 0; size: A4; }
49
  body { -webkit-print-color-adjust: exact; }
50
  `
51
  });
52
 
53
  // Generate PDF
54
  const pdfBuffer = await page.pdf({
55
- format: 'A4',
56
  printBackground: true,
 
57
  margin: {
58
- top: '10mm',
59
- bottom: '10mm',
60
- left: '10mm',
61
- right: '10mm'
62
  }
63
  });
64
 
 
45
  // Inject styles to ensure 100% width and print media simulation
46
  await page.addStyleTag({
47
  content: `
48
+ @page { margin: 10mm; size: A4; }
49
  body { -webkit-print-color-adjust: exact; }
50
  `
51
  });
52
 
53
  // Generate PDF
54
  const pdfBuffer = await page.pdf({
 
55
  printBackground: true,
56
+ preferCSSPageSize: true,
57
  margin: {
58
+ top: 0,
59
+ bottom: 0,
60
+ left: 0,
61
+ right: 0
62
  }
63
  });
64