garbled only in textField
luckymore opened this issue · comments
flyflydogdog commented
Enviroment: nodejsv20.12.1
I'm getting garbled Chinese when using textField
, But it's normal in doc.text()
I've also tried Japanese and Russian and they are all garbled
import { jsPDF } from "jspdf";
import fs from "fs";
const doc = new jsPDF();
var SimSun = fs.readFileSync('./SimSun.ttf', {
encoding: 'latin1',
});
doc.addFileToVFS('simsun.ttf', SimSun);
doc.addFont('simsun.ttf', 'simsun', 'normal');
doc.setFont('simsun');
const textField = new doc.AcroForm.TextField()
textField.Rect = [20, 20, 50, 50]
textField.value = '你好 世界! hello world!';
textField.fontStyle = 'normal';
doc.text(20, 20, '你好 世界! hello world!');
doc.addField(textField)
doc.save("hello.pdf")