Created
March 10, 2024 19:30
-
-
Save kapraran/bfa927785dd7e4edfbeb1e785b6dda55 to your computer and use it in GitHub Desktop.
vite to pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { build, preview } from "vite"; | |
import { chromium } from "playwright"; | |
async function generatePdf(url) { | |
const browser = await chromium.launch(); | |
const page = await browser.newPage(); | |
await page.goto(url); | |
await page.pdf({ path: `cv-${Date.now()}.pdf`, printBackground: true }); | |
await browser.close(); | |
} | |
async function main() { | |
await build(); | |
const previewServer = await preview(); | |
const url = previewServer.resolvedUrls.local[0]; | |
await generatePdf(url); | |
await previewServer.close(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment