pdf-lib icon indicating copy to clipboard operation
pdf-lib copied to clipboard

pdf.drawText is not supporting with custom font

Open ldilshan opened this issue 2 years ago • 1 comments

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

  • [X] My report includes a Short, Self Contained, Correct (Compilable) Example.
  • [X] I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

No response

ldilshan avatar Aug 12 '23 19:08 ldilshan

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

SanjaySRocks avatar Sep 17 '23 16:09 SanjaySRocks