I am using pdfkit to create invoice in pdf.
When I tried to add newline/nextline (\n) in a string which I tried to add using doc.text("Text \n new line");
it shows Ð and then adds newline.
Here is the code:
const doc = new PDFDocument({
margin: 5,
autoFirstPage: false,
bufferPages: true,
});
doc.addPage();
// other codes ...
doc.text("1. Hello World");
doc.text(`2. Pdfkit
newline`);
Here is the rendered screenshot:
How can I get rid of this?
doc.text(`2. Pdfkit
newline`.replace(/\r\n|\r/g, '\n'));
I simply added string.replace(/\r\n|\r/g, '\n')
for the string and it worked
Reference: https://github.com/foliojs/pdfkit/issues/606