Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strange character "Ð" every time I press "intro" #606

Open
cfibla opened this issue Jan 15, 2017 · 10 comments
Open

Strange character "Ð" every time I press "intro" #606

cfibla opened this issue Jan 15, 2017 · 10 comments

Comments

@cfibla
Copy link

cfibla commented Jan 15, 2017

Hello,
I'm trying to get a text from an object in NodeJs but I have a little problem:
For example:
doc.text(myObject.text);
if myObject.text is like (with "intro's"):
"THIS
IS
MY
TEXT"

when I render the PDF it looks like:
"THIS Ð
IS Ð
MY Ð
TEXT"

I've been looking for info, but I didn't found anything about this, am I the only person in the world??

@alafr
Copy link
Collaborator

alafr commented Jan 16, 2017

There are probably strange invisible unicode characters in your text...

@cfibla
Copy link
Author

cfibla commented Jan 17, 2017

Mmmm... but in console the text is clean, with no symbpls.

@alafr
Copy link
Collaborator

alafr commented Jan 17, 2017

It can be some kind of space character and look cleen.
Just to be sure, check it with charCodeAt()

for (i = 0; i < string.length; i++) {
  console.log(string.charCodeAt(i));
}

Which font are you using?

@cfibla
Copy link
Author

cfibla commented Jan 17, 2017

Thanks for your answer alafr,
I'm using the default font of PDFkit. I tried your code with:
H(intro)E(intro)L(intro)L(intro)O
the result was:
72, 13, 10, 69, 13, 10, 76, 13, 10, 76, 13, 10, 79

@alafr
Copy link
Collaborator

alafr commented Jan 17, 2017

Thanks, with these details the bug is easy to reproduce:
doc.text('H\r\nE\r\nL\r\nL\r\nO');
Apparently the character 13 (carriage return, \r) is not processed correctly by PDFKit, when using standard fonts.

As a workaround you can clean the line breaks with a regular expression:
string.replace(/\r\n|\r/g, '\n')

@cfibla
Copy link
Author

cfibla commented Jan 21, 2017

It works pretty fine!
Thank you @alafr !

@FabriceReynolds
Copy link

FabriceReynolds commented Jun 7, 2018

Although @alafr has found a workaround would it be possible to have a more permanent fix?

@unknowndomain
Copy link

Just for the record this issue is still reproducible and the fix above by @alafr to replace the \r\n carriage return with just \n new line.

@joshua-animas
Copy link

joshua-animas commented Jul 19, 2019

although @alafr solution does seem to work on the output, if you have the pdf read by a reader (i.e. pdf.js) it will return a "UnkownErrorException" - " bad XRef entry"

@Flo0806
Copy link

Flo0806 commented Jul 26, 2020

although @alafr solution does seem to work on the output, if you have the pdf read by a reader (i.e. pdf.js) it will return a "UnkownErrorException" - " bad XRef entry"

Hi,
i think the XRef error comes from somewhere else. I load my data from a mysql database, change '\r\n' to '\n' and my PDF can be loaded without errors by any common reader (Adobe, PDF.js).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants