Skip to content

Instantly share code, notes, and snippets.

@kapraran
Created March 10, 2024 19:30
Show Gist options
  • Save kapraran/bfa927785dd7e4edfbeb1e785b6dda55 to your computer and use it in GitHub Desktop.
Save kapraran/bfa927785dd7e4edfbeb1e785b6dda55 to your computer and use it in GitHub Desktop.
vite to pdf
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