mirror of
https://github.com/JOYCEQL/magic-resume.git
synced 2026-07-03 14:07:11 +02:00
fix: severless font
This commit is contained in:
Binary file not shown.
@@ -1,7 +1,9 @@
|
||||
// import puppeteer from "puppeteer";
|
||||
import puppeteer from "puppeteer";
|
||||
import { NextResponse } from "next/server";
|
||||
import puppeteer from "puppeteer-core";
|
||||
// import puppeteer from "puppeteer-core";
|
||||
import chrome from "@sparticuz/chromium";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
@@ -26,6 +28,19 @@ export async function POST(req: Request) {
|
||||
});
|
||||
|
||||
const page = await browser.newPage();
|
||||
const fontPath = path.join(
|
||||
process.cwd(),
|
||||
"public",
|
||||
"fonts",
|
||||
"NotoSansSC.ttf"
|
||||
);
|
||||
const fontBuffer = fs.readFileSync(fontPath);
|
||||
|
||||
await page.evaluate(async (fontBuffer) => {
|
||||
const font = new FontFace("Noto Sans SC", fontBuffer);
|
||||
await font.load();
|
||||
document.fonts.add(font);
|
||||
}, fontBuffer);
|
||||
|
||||
await page.setContent(content);
|
||||
|
||||
|
||||
@@ -37,17 +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') format('woff2');
|
||||
font-weight: normal;
|
||||
font-style: normal;
|
||||
}
|
||||
body {
|
||||
font-family: 'Noto Sans SC', sans-serif;
|
||||
}
|
||||
</style>
|
||||
<style>${styles}</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -55,6 +44,7 @@ export function PdfExport() {
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
|
||||
const response = await fetch("/api/generate-pdf", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user