Replies: 1 comment
-
Ok. I was waiting for someone to answer me fast, believing I was doing something stupid, and give me enlightenment about this problem. After that, I just decided to open the file before going to sleep and investigate a bit more. import Noto from 'url:./NotoSansJP-Regular.ttf'; is only giving me a path to the file, as I printed it out using console.log(Noto) it returned me Converting it to an ArrayBuffer using the I also tested hosting the font somewhere else and trying to fetch it to see the results and... SUCCESS! I could manage to get the file and Then I had the dumbest thing I ever thought lol. I will do a fetch to a file in my project... AND IT WORKED. I hated it. I really hated it, but it will be how it's going to be used for now. This is the code of how I'm loading it: import { PDFDocument } from 'pdf-lib';
import fontKit from '@pdf-lib/fontkit';
import Noto from 'url:./NotoSansJP-Regular.ttf';
async function main() {
const test = await fetch(Noto).then((res) => res.arrayBuffer());
const pdfDoc = await PDFDocument.create();
pdfDoc.registerFontkit(fontKit);
const customFont = await pdfDoc.embedFont(test);
}
main(); Again, I don't like this solution, but I hope there is another way to do that, or even someone explains that what I'm doing is ok haha (I doubt tho). |
Beta Was this translation helpful? Give feedback.
-
Hi there,
I have been trying to use pdf-lib to generate a PDF in a project, but I have to use a Japanese font, as well I want to allow people to choose a font before rendering it.
The problem is that every time I try to load a font, but I keep getting the error
Uncaught (in promise) Error: Unknown font format
.I did a small test in another project just to make it cleaner (the error still occurs).
Don't mind the lack of structure (font in the root along with the js file), and I'm using parcel (that's why the font import has a
url:
in it).Later I want to use Google Fonts or another repo of fonts to grab fonts or even allow the user to upload fonts to the webpage and use them when generating a PDF.
This is the error I get every time.

Am I doing something wrong? Does it work on the client side (browser)? Thank you very much for the help.
Beta Was this translation helpful? Give feedback.
All reactions