YevgeniyM
YevgeniyM

Reputation: 51

Russian symbols in PDF (pdfkit)

Сreate a pdf file following the example https://pspdfkit.com/blog/2019/generate-invoices-pdfkit-node/

the problem is that characters in Russian are displayed : "Aô@Cä2CT@C¤0", but should be "Проверка". How can I set encoding to 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();
}

Upvotes: 3

Views: 1689

Answers (2)

YevgeniyM
YevgeniyM

Reputation: 51

I downloaded the font file and include it:

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

thanks!

Upvotes: 2

Constant Gillet
Constant Gillet

Reputation: 116

I think that you have to use a font which support russian characters

Look this thread https://github.com/foliojs/pdfkit/issues/262

Upvotes: 0

Related Questions