Files
resume/convert.js
T

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2026-07-11 10:16:46 +08:00
const { chromium } = require('playwright');
const path = require('path');
async function htmlToJpg() {
// Launch browser with custom library path
const browser = await chromium.launch({
env: {
...process.env,
LD_LIBRARY_PATH: '/tmp/libs/usr/lib/x86_64-linux-gnu:' + (process.env.LD_LIBRARY_PATH || '')
}
});
const page = await browser.newPage();
// Set viewport to A4 size (210mm x 297mm at 96dpi)
await page.setViewportSize({ width: 794, height: 1123 });
// Load the HTML file
const htmlPath = path.join(__dirname, 'resume.html');
await page.goto(`file://${htmlPath}`, { waitUntil: 'networkidle' });
// Get the actual page height
const bodyHeight = await page.evaluate(() => document.body.scrollHeight);
// Set viewport to full page height
await page.setViewportSize({ width: 794, height: bodyHeight });
// Take a full-page screenshot
const outputPath = path.join(__dirname, 'resume_output.jpg');
await page.screenshot({
path: outputPath,
fullPage: true,
type: 'jpeg',
quality: 95,
});
console.log(`Screenshot saved to: ${outputPath}`);
console.log(`Page dimensions: 794 x ${bodyHeight}`);
await browser.close();
}
htmlToJpg().catch(console.error);