Arabic and Urdu documents

Build Arabic and Urdu documents with DocStudio: page direction, locale, registering fonts for the renderer and the PDF service, mixed content and limitations.

Direction and locale

{
  "schemaVersion": "1.0.0",
  "config": { "page": { "direction": "rtl" }, "locale": "ar" },
  "body": [{ "id": "title", "type": "text", "content": ["كشف الحساب: ", { "path": "company" }] }]
}

Use locale: "ur" for Urdu. Alignment, row order and table column order mirror. See right-to-left support.

Register a font

Arabic and Urdu need a font with the script. The package ships none. Register the faces you have the right to use:

fonts.ts
import { readFileSync } from 'node:fs';
import { createFontRegistry } from 'docstudio/render';

export function loadFonts() {
  const fonts = createFontRegistry();
  const problem = fonts.register({
    family: 'Noto Naskh Arabic',
    weight: 400,
    format: 'woff2',
    data: new Uint8Array(readFileSync('fonts/noto-naskh-arabic-400.woff2')),
  });
  if (problem !== undefined) throw new Error(problem.message);
  return fonts;
}

Then reference the family in the template with "style": { "fontFamily": "Noto Naskh Arabic" }, or on a section with config.style. Faces are embedded in the document as data URIs, with a size limit per font.

Render

const result = renderDocument(template, data, { target: 'print', lang: 'ar', fonts: loadFonts() });

For PDF, pass the same registry to createPdfService({ fonts }). The service waits for fonts to load before it prints.

Mixed content

A section with direction: "rtl" inside an English document holds an Arabic note. Bound Latin names and numbers keep their order inside Arabic text.

Limitations

  • The PDF text layer for Arabic and Urdu is lossy: copy, search and accessibility of extracted text are degraded.
  • Digit shapes depend on the runtime's Intl data. Digits come out Latin in tested runtimes.
  • Fixed-region frames use physical left and top.

Test with your own fonts and a real PDF viewer before you rely on extracted text. The Arabic and Urdu article covers the trade-offs.

Last updated 2026-12-03