Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

99
Visualizações
JsPdf Library can't read Arabic in PDF

Code to show Arabic value in pdf doesn't work. It shows me some weird language that I don't understand:

var sm = {
    nature:[
        {name:"nature1",ar:"الطبيعة  1"},
        {name:"nature2",ar:"الطبيعة 2"},
        {name:"nature3",ar:"الطبيعة 3"},
        {name:"nature4",ar:"الطبيعة 4"}
    ],
    exportateur:[
        {name:"exportateur1",ar:"المصدر 1"},
        {name:"exportateur2",ar:"المصدر 2"},
        {name:"exportateur3",ar:"المصدر 3"},
        {name:"exportateur4",ar:"المصدر 4"}
    ],
    pays:[
        {name:"germany",ar:"ألمانيا"},
        {name:"france",ar:"فرنسا"},
        {name:"belgium",ar:"بلجيكا"},
        {name:"spain",ar:"إسبانيا"}
    ]
}
function createPdf(event){
    "use strict";
    var doc = new jsPDF();
    doc.text("Nature de la marchandise: "+sm.nature[0].ar,10, 10);
    doc.save("output.pdf");  
}

Result :

Here is the result image

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You need to use a font that supports Arabic glyphs. And make sure it's ttf type. Amiri font is a one that works for jsPDF. Use this tool to upload the font file and it will generate a proper js file containing the base64 data of the font and jsPDF setup to add the font to its API. After that, you need to import the file into your code and set the doc font to the font you've just imported. Make sure to use the name that is set in the js file

doc.setFont("Amiri")
about 4 years ago · Juan Pablo Isaza Relatório

0

I got it working with this method. You need a font which shows the arabic text , I have included the base64 version of a font which shows arabic texts in this file

https://codesandbox.io/s/js-playground-forked-19t4vw?file=/src/index.js

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda