24 lines
871 B
JavaScript
24 lines
871 B
JavaScript
import { chromium } from '../../../catalog/screenshots/node_modules/playwright/index.mjs';
|
|
import { fileURLToPath } from 'url';
|
|
import path from 'path';
|
|
import fs from 'fs';
|
|
|
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
const htmlPath = path.join(__dirname, 'factory-asset-guide.html');
|
|
const pdfPath = path.join(__dirname, 'factory-asset-guide.pdf');
|
|
|
|
const browser = await chromium.launch({ headless: true });
|
|
const page = await browser.newPage();
|
|
await page.goto(`file:///${htmlPath.replace(/\\/g, '/')}`, { waitUntil: 'networkidle' });
|
|
await page.waitForTimeout(3000);
|
|
await page.pdf({
|
|
path: pdfPath,
|
|
format: 'A4',
|
|
printBackground: true,
|
|
margin: { top: '15mm', bottom: '15mm', left: '12mm', right: '12mm' },
|
|
});
|
|
await browser.close();
|
|
|
|
const stats = fs.statSync(pdfPath);
|
|
console.log('PDF created:', pdfPath, '(' + stats.size + ' bytes)');
|