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

add utf8 characterannotaiton is failed #55

Open
alanJ198 opened this issue Dec 18, 2021 · 5 comments
Open

add utf8 characterannotaiton is failed #55

alanJ198 opened this issue Dec 18, 2021 · 5 comments

Comments

@alanJ198
Copy link

hi, when I try to add some annotations with utf8 character (for example Japanese), it seems not work.
hope to get an advice for this problem, thanks

@alanJ198
Copy link
Author

aha, I have solved the problem by myself.

@MarkMindCkm
Copy link

aha, I have solved the problem by myself.

Hi , can you explain how it was solved ?

@Envek
Copy link

Envek commented Nov 9, 2022

@alanJ198, please share your solution, I also need it!


The following code (source is UTF-8):

factory.createTextAnnotation({
  // …
  contents: "Hello! こんにちは! Привет!",
  // …
})

Produces following annotation:

Hello! Sfikao� ˜@825B!

How to write UTF-8 strings to annotations correctly?

@suziwen
Copy link

suziwen commented Feb 19, 2023

@Envek

function stringToUtf16Raw(text) {
  let out = [];
  out.push(String.fromCharCode(254));
  out.push(String.fromCharCode(255));
  for (let c of text) {
    c = c.charCodeAt(0);
    out.push(String.fromCharCode(c >> 8));
    out.push(String.fromCharCode(c & 0xFF));
  }
  return out.join('');
}

factory.createTextAnnotation({
  // …
  contents: stringToUtf16Raw("Hello! こんにちは! Привет!"),
  // …
})

@472530498
Copy link

@Envek

function stringToUtf16Raw(text) {
  let out = [];
  out.push(String.fromCharCode(254));
  out.push(String.fromCharCode(255));
  for (let c of text) {
    c = c.charCodeAt(0);
    out.push(String.fromCharCode(c >> 8));
    out.push(String.fromCharCode(c & 0xFF));
  }
  return out.join('');
}

factory.createTextAnnotation({
  // …
  contents: stringToUtf16Raw("Hello! こんにちは! Привет!"),
  // …
})

no show char in browser when open the export pdf file

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

No branches or pull requests

6 participants
@suziwen @Envek @MarkMindCkm @472530498 @alanJ198 and others