43 lines
921 B
TypeScript
43 lines
921 B
TypeScript
|
|
#!/usr/bin/env bun
|
||
|
|
import { mkdir } from "node:fs/promises"
|
||
|
|
import { dirname } from "node:path"
|
||
|
|
import { chromium } from "playwright"
|
||
|
|
|
||
|
|
const url = "file:///finch/da.nfin.ch/dist/cv.html"
|
||
|
|
const output = "dist/cv.pdf"
|
||
|
|
|
||
|
|
await mkdir(dirname(output), { recursive: true })
|
||
|
|
|
||
|
|
const executablePath =
|
||
|
|
process.env.CHROMIUM_PATH ??
|
||
|
|
Bun.which("thorium-browser") ??
|
||
|
|
Bun.which("chromium") ??
|
||
|
|
Bun.which("chromium-browser") ??
|
||
|
|
Bun.which("google-chrome") ??
|
||
|
|
Bun.which("google-chrome-canary") ??
|
||
|
|
undefined
|
||
|
|
|
||
|
|
const browser = await chromium.launch({
|
||
|
|
executablePath,
|
||
|
|
headless: true,
|
||
|
|
args: ["--no-sandbox", "--disable-gpu"],
|
||
|
|
})
|
||
|
|
|
||
|
|
try {
|
||
|
|
const page = await browser.newPage()
|
||
|
|
|
||
|
|
await page.goto(url, {
|
||
|
|
waitUntil: "networkidle",
|
||
|
|
timeout: 30_000,
|
||
|
|
})
|
||
|
|
|
||
|
|
await page.pdf({
|
||
|
|
path: output,
|
||
|
|
printBackground: true,
|
||
|
|
displayHeaderFooter: false,
|
||
|
|
preferCSSPageSize: true,
|
||
|
|
})
|
||
|
|
} finally {
|
||
|
|
await browser.close()
|
||
|
|
}
|