Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda