I’ve implemented a pdf download from an api route in Astro, it works good in localhost, but in prod it fails. I’ve tried literally everything… even after that, I’ve not being able to make it work.
This issue is very common, and everyone who is asking for this problem, seems like they weren’t able to fix it because are no comment in the threads…
The issue is the custom fonts used in pdf are not located in the vercel deploy:
I’ve this for fonts settings:
import path from "path";
import type { TFontFamilyTypes } from "pdfmake/interfaces";
const pathToFonts: string = path.join(
process.cwd(),
"public",
"resources",
"fonts",
);
const fonts: Record<string, TFontFamilyTypes> = {
Roboto: {
normal: path.join(pathToFonts, "Roboto-Regular.ttf"),
bold: path.join(pathToFonts, "Roboto-Bold.ttf"),
italics: path.join(pathToFonts, "Roboto-Italic.ttf"),
bolditalics: path.join(pathToFonts, "Roboto-BoldItalic.ttf"),
},
};
export { fonts };
And my fonts are located in the public folder public/resources/fonts/...
I also tried this in my astro config file:
adapter: vercel({
functionPerRoute: true,
includeFiles: [
"./public/resources/fonts/Roboto-Bold.ttf",
"./public/resources/fonts/Roboto-Regular.ttf",
"./public/resources/fonts/Roboto-Italic.ttf",
"./public/resources/fonts/Roboto-BoldItalic.ttf",
],
}),
But it doesn’t work.
Path are right, do doubt about it, must be something else.
I’m requiring your help 🙏