// 在 playwright docker 镜像内运行:chromium 打印 HTML → PDF // 用法:node pdf-print.mjs import { createRequire } from 'node:module'; const require = createRequire('/home/weichen/projects/Agent-System/web/package.json'); const { chromium } = require('playwright'); const [htmlPath, pdfPath] = process.argv.slice(2); const browser = await chromium.launch(); const page = await browser.newPage(); await page.goto('file://' + htmlPath, { waitUntil: 'networkidle' }); await page.pdf({ path: pdfPath, format: 'A4', printBackground: true, margin: { top: '18mm', bottom: '18mm', left: '15mm', right: '15mm' }, }); await browser.close(); console.log('[ok] PDF:', pdfPath);