pdf-lib - How to add a custom font with a text to a existing PDF

385 Views Asked by At

   const fontPath = path.join(process.cwd(), 'src/fonts/arial.ttf');
   const fontBytes = await fs.readFile(fontPath);
            
   pdfDoc.registerFontkit(fontkit);

    const customFont = await pdfDoc.embedFont(fontBytes);
    
    pdfPage.drawText("", options, {
        x: 40,
        y: 450,
        size: 12,
        font: customFont,
        color: rgb(0, 0.53, 0.71),
      });

I have tried to draw a text with custom font using pdf-lib. Nothing print in the pdf according to above code. How can we use custom fonts with pdf library?

0

There are 0 best solutions below