#fonts #next.js #pdfkit #vercel
Вопрос:
У меня возникли проблемы с включением нового шрифта в маршрут api.
Структура моего файла
Код
Мой маршрут api, который генерирует файл pdf
import PDFDocument from "pdfkit";
import PDF from "../../services/PDF";
import serverPath from "../../serverPath";
import { fetchImage } from "../../services/fetchImages";
const environment = process.env.NODE_ENV;
export default async (req, res) => {
if (req.method === "POST") {
try {
let theOutput = new PDFDocument({ bufferPages: true });
const newPdf = new PDF();
theOutput.registerFont("Roboto",environment === "development" ?
serverPath("fonts/Roboto.ttf") : "public/fonts/Roboto.ttf");
theOutput.registerFont("RobotoBold",environment === "development" ?
serverPath("fonts/RobotoB.ttf") :"public/fonts/RobotoB.ttf");
// theOutput.registerFont("Roboto", "/fonts/roboto/Roboto.ttf");
// theOutput.registerFont("RobotoBold", "/fonts/roboto/RobotoB.ttf");
theOutput.font("Roboto");
theOutput.pipe(res);
const logo = await fetchImage(req.body.images);
theOutput.image(logo[0], 50, 90, { fit: [theOutput.page.width, 300] });
newPdf.generateTable(theOutput);
newPdf.generateDescription(theOutput);
newPdf.generateImages(theOutput, logo);
newPdf.generateHeader(theOutput);
newPdf.generateFooter(theOutput);
theOutput.end();
} catch (err) {
console.log(err);
res.status(500).json(err);
}
} else {
res.status(400).json("Bad request");
}
};
When I run api-route on dev or locally after build everything is fine, fonts attach and pdf is generated
however, when I put applications on Vercel, I get a message
I have tried to give this path in all possible ways but it still does not work.
I always thought that the path to public should look like ‘/ folder-name / etc ..’ but when I set the path to /fonts/Roboto.ttf it doesn’t work locally either
I have no idea what to do next ;d