Hopding / pdf-lib

Create and modify PDF documents in any JavaScript environment
https://pdf-lib.js.org
MIT License
6.89k stars 656 forks source link

pdf.drawText is not supporting with custom font #1506

Open ldilshan opened 1 year ago

ldilshan commented 1 year ago

What were you trying to do?

               const pdfDoc = await PDFDocument.load(pdfBase64, { ignoreEncryption: false });

                    pdfDoc.registerFontkit(fontkit); // Register fontkit

            const fontPath = path.join(process.cwd(), 'src/fonts/arial.ttf');
            const fontBytes = await fs.readFile(fontPath);
            const customFont = await pdfDoc.embedFont(fontBytes);
            options.font = customFont
            options.color = rgb(0, 0, 0),
            pdfPage.drawText("Test", {x:300, y: 200, size: 10, font: customFont});

How did you attempt to do it?

Inside node backend

What actually happened?

Text is not displaying in the document with given position when we try to add a custom font. Standard fonts are working and need to use custom font here.

What did you expect to happen?

Needs to draw text with Custom fonts

How can we reproduce the issue?

try the above code

Version

"^1.17.1",

What environment are you running pdf-lib in?

Node

Checklist

Additional Notes

No response

SanjaySRocks commented 1 year ago

facing same issue using this custom font (https://fonts.google.com/specimen/Borel?query=borel&preview.text=Sanjay%20Singh&preview.text_type=custom)

pdf.drawText do not print text properly. screenshot is attached. image