Files
resume/convert.js
T
wonder 28d9c29b35 添加简历生成项目文件
- 添加 .gitignore 配置
- 添加 HTML 简历模板 (resume.html)
- 添加转换脚本 (convert.js, convert.py)
- 添加字体下载脚本 (download_font.js)
- 添加项目配置 (package.json)
2026-07-11 10:16:46 +08:00

43 lines
1.3 KiB
JavaScript

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);