Files
folio/scripts/resume-to-pdf.ts
T

44 lines
1.0 KiB
TypeScript
Raw Normal View History

2026-07-24 18:03:05 -05:00
import { chromium } from 'playwright'
import { mkdir } from 'node:fs/promises'
import { dirname, join, resolve } from 'node:path'
2026-07-24 17:55:24 -05:00
2026-07-24 18:03:05 -05:00
const root = join(import.meta.dir, '..')
const resumeHtml = join(root, 'public/resume/index.html')
2026-07-24 17:55:24 -05:00
const outputPath = resolve(
2026-07-24 18:03:05 -05:00
Bun.argv[2] ?? join(root, 'public/resume/paper.pdf'),
)
2026-07-24 17:55:24 -05:00
async function main() {
2026-07-24 18:03:05 -05:00
await mkdir(dirname(outputPath), { recursive: true })
2026-07-24 17:55:24 -05:00
2026-07-24 18:03:05 -05:00
const browser = await chromium.launch()
const page = await browser.newPage()
2026-07-24 17:55:24 -05:00
2026-07-24 18:03:05 -05:00
await page.goto(Bun.pathToFileURL(resumeHtml).href, {
waitUntil: 'networkidle',
})
2026-07-24 17:55:24 -05:00
await page.evaluate(async () => {
2026-07-24 18:03:05 -05:00
await document.fonts.ready
})
2026-07-24 17:55:24 -05:00
await page.pdf({
path: outputPath,
format: 'Letter',
printBackground: true,
margin: {
top: '0',
right: '0',
bottom: '0',
left: '0',
},
2026-07-24 18:03:05 -05:00
})
2026-07-24 17:55:24 -05:00
2026-07-24 18:03:05 -05:00
await browser.close()
console.log(`Wrote ${outputPath}`)
2026-07-24 17:55:24 -05:00
}
main().catch((error) => {
2026-07-24 18:03:05 -05:00
console.error(error)
process.exit(1)
})