Switched to playwright... puppeteer is kinda clunky
All checks were successful
Docker Deploy / build-and-push (push) Successful in 7m19s
All checks were successful
Docker Deploy / build-and-push (push) Successful in 7m19s
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
import type { APIRoute } from "astro";
|
||||
import puppeteer from "puppeteer";
|
||||
import { chromium } from 'playwright';
|
||||
import { siteConfig } from "../../../config/data";
|
||||
import * as TOML from "@iarna/toml";
|
||||
|
||||
@ -411,36 +411,34 @@ export const GET: APIRoute = async ({ request }) => {
|
||||
|
||||
const htmlContent = await generateResumeHTML(resumeData);
|
||||
|
||||
const browser = await puppeteer.launch({
|
||||
// Launch browser with Playwright
|
||||
const browser = await chromium.launch({
|
||||
headless: true,
|
||||
defaultViewport: null,
|
||||
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH ||
|
||||
executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH ||
|
||||
(process.env.NODE_ENV === "production" ? "/usr/bin/google-chrome" : undefined),
|
||||
args: [
|
||||
"--no-sandbox",
|
||||
"--disable-setuid-sandbox",
|
||||
"--disable-dev-shm-usage",
|
||||
"--disable-accelerated-2d-canvas",
|
||||
"--no-first-run",
|
||||
"--no-zygote",
|
||||
"--disable-gpu",
|
||||
],
|
||||
'--no-sandbox',
|
||||
'--disable-setuid-sandbox',
|
||||
'--disable-dev-shm-usage',
|
||||
'--disable-gpu',
|
||||
'--disable-web-security',
|
||||
'--disable-features=VizDisplayCompositor'
|
||||
]
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
|
||||
await page.setContent(htmlContent, { waitUntil: "networkidle0" });
|
||||
await page.setContent(htmlContent, { waitUntil: 'networkidle' });
|
||||
|
||||
const pdfBuffer = await page.pdf({
|
||||
format: "A4",
|
||||
format: 'A4',
|
||||
margin: {
|
||||
top: "0.2in",
|
||||
bottom: "0.2in",
|
||||
left: "0.2in",
|
||||
right: "0.2in",
|
||||
top: '0.2in',
|
||||
bottom: '0.2in',
|
||||
left: '0.2in',
|
||||
right: '0.2in',
|
||||
},
|
||||
printBackground: true,
|
||||
preferCSSPageSize: false,
|
||||
scale: 0.9,
|
||||
});
|
||||
|
||||
@ -459,4 +457,4 @@ export const GET: APIRoute = async ({ request }) => {
|
||||
console.error("Error generating PDF:", error);
|
||||
return new Response("Error generating PDF", { status: 500 });
|
||||
}
|
||||
};
|
||||
};
|
Reference in New Issue
Block a user