PDF(pdfkit)中的俄语符号

3

按照示例https://pspdfkit.com/blog/2019/generate-invoices-pdfkit-node/创建PDF文件。

问题在于俄语字符显示为"Aô@Cä2CT@C¤0",而应该是"Проверка"。如何设置编码为UTF-8?

function createInvoice(invoice, path) {
  let doc = new PDFDocument({ margin: 50 });

  generateHeader(doc);

  doc.end();
  doc.pipe(fs.createWriteStream(path));
}

function generateHeader(doc) {
  doc
    .image("logo.png", 50, 45, { width: 50 })
    .fillColor("#444444")
    .fontSize(20)
    .text("Проверка", 110, 57)
    .fontSize(10)
    .text("Проверка", 100, 65, { align: "right" })
    .text("Проверка", 100, 80, { align: "right" })
    .moveDown();
}

你是怎么创建这个PDF文件的呢?顺便说一下,你可能应该将字体更换一下:一些旧的遗留字体在PDF中使用遗留编码以保证兼容性,而其他字体(和文本)则必须使用Unicode编码。 - undefined
function createInvoice(invoice, path) { let doc = new PDFDocument({ margin: 50 }); generateHeader(doc); doc.end(); doc.pipe(fs.createWriteStream(path)); }function generateHeader(doc) { doc .image("logo.png", 50, 45, { width: 50 }) .fillColor("#444444") .fontSize(20) .text("检查", 110, 57) .fontSize(10) .text("检查", 100, 65, { align: "right" }) .text("检查", 100, 80, { align: "right" }) .moveDown(); } - undefined
请注意:您应该编辑您的问题,添加这些细节。 - undefined
2个回答

2

我下载了字体文件并将其包含在页面中:

.font(`${__dirname}/arial.ttf`)

谢谢!


0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接