File size: 1,899 Bytes
3302f5e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
const { chromium } = require('playwright');
const fs = require('fs');
const { execSync } = require('child_process');

(async () => {
  const browser = await chromium.launch({ headless: true });
  const page = await browser.newPage({ viewport: { width: 1440, height: 1000 } });
  await page.goto('http://127.0.0.1:5173/preview-certificate');
  await page.waitForTimeout(2000);

  // Hook in page with refined baseline correction
  await page.evaluate(() => {
    const origFillText = CanvasRenderingContext2D.prototype.fillText;
    CanvasRenderingContext2D.prototype.fillText = function(text, x, y, maxWidth) {
      let correctedY = y;
      const match = this.font.match(/([\d.]+)px/);
      if (match) {
        const fontSize = parseFloat(match[1]);
        let shift;
        if (fontSize >= 36) {
          shift = fontSize * 0.44;
        } else if (fontSize >= 24) {
          shift = fontSize * 0.46;
        } else if (fontSize >= 16) {
          shift = fontSize * 0.52;
        } else {
          shift = fontSize * 0.78;
        }
        correctedY = y - shift;
      }
      return origFillText.call(this, text, x, correctedY, maxWidth);
    };
  });

  // Trigger PDF export
  const [ download ] = await Promise.all([
    page.waitForEvent('download'),
    page.click('#btn-download-pdf')
  ]);
  const pdfPath = '/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_test_v3.pdf';
  await download.saveAs(pdfPath);
  
  execSync(`pdftoppm -png -r 150 "${pdfPath}" "/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_pdf_v3"`);
  fs.renameSync('/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_pdf_v3-1.png', '/home/grim/.gemini/antigravity/brain/780fc6f2-0ee4-4d27-a3c9-d81026488398/corrected_pdf_v3.png');
  console.log('Saved corrected_pdf_v3.png');

  await browser.close();
})();