Guides / jsPDF Arabic text missing or broken

Problems · Updated 2026-12-03

jsPDF Arabic text missing or broken

You add Arabic to a jsPDF document and get one of three results: gibberish, nothing at all, or something that is almost right but has letters missing and words that look broken. The last one is the most confusing, because some fonts work and others with full Arabic support do not.

This page explains each case with sources, gives a fix we tested, and shows the API route if you would rather not manage it.

#Symptoms

  • Garbled characters or nothing. You used the default font (Helvetica, Times, Courier).
  • Some letters missing, words broken apart. You loaded an Arabic font with addFont, the text is right to left and mostly joined, but certain letters vanish. This is jsPDF issue #3867.
  • It works with one font and fails with another, even though both fonts display Arabic fine in a browser or word processor.

#Cause 1: the standard fonts have no Arabic

The jsPDF README is clear about this:

The 14 standard fonts in PDF are limited to the ASCII-codepage. If you want to use UTF-8 you have to integrate a custom font, which provides the needed glyphs.

So the first step is always to load a TrueType font that contains Arabic. The README shows two ways: convert the .ttf with its font converter, or load the file yourself and register it:

const doc = new jsPDF();
const myFont = ... // load the *.ttf font file as binary string
doc.addFileToVFS("MyFont.ttf", myFont);
doc.addFont("MyFont.ttf", "MyFont", "normal");
doc.setFont("MyFont");

#Cause 2: the font lacks Arabic presentation forms

Arabic letters change shape depending on their position in a word. A browser shapes text using tables inside the font (OpenType). jsPDF takes a different route: it ships an Arabic module that replaces each letter with a separate Unicode character for the right shape before drawing. The module's own comment describes its table as "Arabic shape substitutions: char code => (isolated, final, initial, medial)". Those replacement characters live in the Unicode blocks called Arabic Presentation Forms-A (U+FB50–U+FDFF) and Presentation Forms-B (U+FE70–U+FEFF).

That means the font must map those presentation-form code points to glyphs. Many fonts do. Some include only part of the block, since browsers shape Arabic from the basic letters and do not need these characters. When a shaped character is missing from the font, jsPDF has nothing to draw, and the letter disappears.

Issue #3867, "Most Arabic fonts not being rendered/painted properly", reports exactly this. The author, a native Arabic speaker, writes that "Some letters were missing, letters were not connected properly", that "The only font that sort of works is Amiri", and shows the Cairo font turning a sentence from the Universal Declaration of Human Rights into one with letters dropped. They traced it into jsPDF's TrueType glyph lookup but did not post a fix. The issue was closed by a stale bot in November 2025, then reopened by a maintainer in January 2026 with the labels Improvement and persistent. It is open at the time of writing.

We reproduced it with jsPDF 4.2.1 and the font files from the Google Fonts repository:

FontResult
CairoThe same broken output as in the issue: لما كا تناسي حقو لإنسا ها قد فضيا لى عما همجية
AmiriFull sentence, correctly joined
Noto Sans ArabicFull sentence, correctly joined

Checking the fonts' character maps with fontTools explains it. After jsPDF's shaping, the sentence uses 35 distinct presentation-form characters. Cairo has no glyph for 11 of them, the isolated or final forms of و ن ق ا ز د ر ؤ أ إ ل, which are precisely the letters missing from the output. Amiri and Noto Sans Arabic have all 35.

#Fix: use a font with full presentation forms

Check a font before you build on it. With Python and fontTools (pip install fonttools):

check_font.py
import sys
from fontTools.ttLib import TTFont

cmap = TTFont(sys.argv[1]).getBestCmap()
forms_a = sum(1 for c in cmap if 0xFB50 <= c <= 0xFDFF)
forms_b = sum(1 for c in cmap if 0xFE70 <= c <= 0xFEFF)
print(f"Presentation Forms-A: {forms_a}, Presentation Forms-B: {forms_b}")

Presentation Forms-B has 141 assigned characters. A font with all or nearly all of them, such as Amiri (140) or Noto Sans Arabic (141), is a safe choice for jsPDF. Cairo, at 89, is not.

Then load it. This runs in Node and in the browser (fetch the file and convert it to base64 there instead of readFileSync):

arabic.mjs
import { jsPDF } from "jspdf";
import { readFileSync, writeFileSync } from "node:fs";

const doc = new jsPDF();

// A font with full Arabic presentation forms, e.g. Amiri or Noto Sans Arabic
const font = readFileSync("NotoSansArabic-Regular.ttf").toString("base64");
doc.addFileToVFS("NotoSansArabic-Regular.ttf", font);
doc.addFont("NotoSansArabic-Regular.ttf", "NotoSansArabic", "normal");
doc.setFont("NotoSansArabic");
doc.setFontSize(18);

const right = doc.internal.pageSize.getWidth() - 15;
doc.text("فاتورة رقم ١٠٢٤", right, 25, { align: "right" });
doc.text("ولما كان تناسي حقوق الإنسان وازدراؤها قد أفضيا إلى أعمال همجية", right, 40, { align: "right" });

writeFileSync("arabic.pdf", Buffer.from(doc.output("arraybuffer")));

What else to know:

  • Align right yourself. jsPDF positions text at the x you give. Pass the right margin and { align: "right" } for right-to-left paragraphs.
  • Direction is handled. jsPDF runs a bidi engine on text by default, which is why the Arabic above comes out in the right order without calling setR2L. Its text() options also accept isInputRtl, isOutputRtl, isInputVisual and isOutputVisual if your input is already in visual order.
  • Register every weight. Bold is a separate file and a separate addFont(..., "bold") call.
  • Test your own text. The issue author reports a few letters wrong even with Amiri. We did not see that with our sample, and we did not test vowel marks (harakat). Check the strings your product actually prints.
  • Layout is manual. jsPDF draws text at coordinates. Tables, wrapping and page breaks for right-to-left documents are yours to calculate, or to handle with a plugin such as jspdf-autotable.

#Or use an API

jsPDF is a good fit for a small client-side PDF with a few lines of text. For invoices, receipts or statements in Arabic and other languages, you may prefer to send data and get the finished document back. DevilPDF renders with a full browser engine, so Arabic is shaped by the font's own OpenType tables, and the page layout mirrors for right-to-left languages.

const res = await fetch("https://devilpdf.com/v1/render", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.DEVILPDF_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    template: "invoice",
    locale: "ar",
    data: {
      number: "INV-1024",
      currency: "SAR",
      customer: { name: "شركة الأفق للتجارة" },
      items: [{ name: "استشارات", quantity: 3, unit_price: 1250 }],
    },
  }),
});
const doc = await res.json();
console.log(doc.url);

"locale": "ar" translates the starter template's labels, formats the money for the locale and mirrors the layout. Call this from your server, not the browser: the API key must stay secret. You can also send your own HTML and CSS, see HTML to PDF. The free plan includes 500 documents a month.

#Next steps