15 lines
847 B
JavaScript
15 lines
847 B
JavaScript
// Print /work/page.html to /work/out.pdf with Chromium, as build-pdf.sh runs it inside the playwright-for-claude image.
|
|
const { chromium } = require('/app/node_modules/playwright');
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch({ args: ['--no-sandbox', '--disable-dev-shm-usage'] });
|
|
const page = await browser.newPage({ viewport: { width: 1100, height: 1400 } });
|
|
// networkidle waits for the Google Fonts the page loads; fonts.ready waits for them to apply.
|
|
await page.goto('file:///work/page.html', { waitUntil: 'networkidle' });
|
|
await page.evaluate(() => document.fonts.ready);
|
|
await page.emulateMedia({ media: 'print' });
|
|
// preferCSSPageSize takes the page's own @page rule: A4 landscape.
|
|
await page.pdf({ path: '/work/out.pdf', format: 'A4', printBackground: true, preferCSSPageSize: true });
|
|
await browser.close();
|
|
})();
|