add utf8 characterannotaiton is failed
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
aha, I have solved the problem by myself.
aha, I have solved the problem by myself.
Hi , can you explain how it was solved ?
@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?
@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! こんにちは! Привет!"),
// …
})
@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