const puppeteer = require('puppeteer-core');
const path = require('path');

(async () => {
  const browser = await puppeteer.launch({
    executablePath: 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe',
    headless: 'new',
    args: ['--no-sandbox', '--disable-setuid-sandbox'],
  });

  const page = await browser.newPage();

  const templatePath = 'file:///' + path.join(__dirname, 'infosheet-template.html').replace(/\\/g, '/');
  await page.goto(templatePath, { waitUntil: 'networkidle0', timeout: 15000 });

  // Wait for Google Fonts to load
  await new Promise(r => setTimeout(r, 1500));

  const outPath = path.join(__dirname, 'marszalek-architekten-infosheet.pdf');

  await page.pdf({
    path: outPath,
    format: 'A4',
    printBackground: true,
    margin: { top: 0, right: 0, bottom: 0, left: 0 },
  });

  await browser.close();
  console.log('PDF written to', outPath);
})();
