Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

100
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!