fix: pdf font

This commit is contained in:
JOYCEQL
2024-11-26 16:31:49 +08:00
parent b97cc54ea8
commit ada7dfe8a7
2 changed files with 12 additions and 26 deletions
+12 -17
View File
@@ -17,8 +17,7 @@ export async function POST(req: Request) {
"--no-sandbox",
"--disable-setuid-sandbox",
"--font-render-hinting=none",
"--disable-web-security",
"--font-family=Microsoft YaHei"
"--disable-web-security"
],
// defaultViewport: chrome.defaultViewport,
executablePath: await chrome.executablePath(
@@ -29,7 +28,17 @@ export async function POST(req: Request) {
const page = await browser.newPage();
await page.evaluate(() => document.fonts.ready);
await page.addStyleTag({
content: `
@font-face {
font-family: 'GeistMonoVF';
src: url('/fonts/GeistMonoVF.woff') format('woff');
font-weight: normal;
font-style: normal;
}
`
});
await page.evaluateHandle("document.fonts.ready");
await page.setContent(content);
@@ -50,20 +59,6 @@ export async function POST(req: Request) {
waitUntil: ["domcontentloaded", "networkidle0"]
});
// 加入fonts文件夹加入的字体
await page.addStyleTag({
content: `
@font-face {
font-family: 'GeistMonoVF';
src: url('/fonts/GeistMonoVF.woff') format('woff');
font-weight: normal;
font-style: normal;
}
`
});
await page.evaluateHandle("document.fonts.ready");
await browser.close();
return new NextResponse(pdf, {
@@ -37,15 +37,6 @@ export function PdfExport() {
const content = `
<html>
<head>
<style>
@font-face {
font-family: 'Noto Sans SC';
src: url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC&display=swap');
}
body {
font-family: 'Noto Sans SC', sans-serif;
}
</style>
<style>${styles}</style>
</head>
<body>