Guides / Arabic text missing in PDFs on Vercel or AWS Lambda

Problems · Updated 2026-12-03

Arabic text missing in PDFs on Vercel or AWS Lambda

You generate PDFs with Puppeteer or Playwright and @sparticuz/chromium. On your laptop the Arabic invoice looks right. Deployed to a serverless function, the same page comes out with empty boxes where the Arabic was, or with the Arabic simply gone. Chinese, Japanese, Korean, Hindi and Thai do the same. Nothing errors, and the PDF is otherwise fine.

This page explains why it happens, how to fix it yourself, and when it is simpler to hand rendering to an API.

#Symptoms

  • Latin text renders. Arabic, Hebrew, CJK, Devanagari or Thai text shows as rectangles (often called "tofu"), or as nothing at all.
  • It works locally and on a normal server, and fails only in the function.
  • No exception, no console warning. page.pdf() succeeds.
  • Emoji are missing too.

A quick way to confirm it is a font problem: run pdffonts (part of Poppler) on the bad PDF. You will see which fonts Chromium actually embedded, and none of them will cover the missing script.

#Why it happens

A browser draws text with the fonts it can find on the machine. When no available font has a glyph for a character, the browser has nothing to draw it with.

On a desktop or a full Linux server, the operating system provides dozens of fonts, including ones for Arabic and CJK. A serverless function does not. The @sparticuz/chromium README says it directly:

The AWS Lambda runtime is not provisioned with any font faces.

To make Chromium usable at all, the package bundles one font family. The same section of the README says it "ships with Open Sans", which supports Latin, Greek and Cyrillic. Nothing else. So any character outside those three scripts has no font, and Chromium renders it as a box or skips it, silently.

The README also explains where Chromium looks for extra fonts. Font folders are set in a fonts.conf inside the package, and the defaults are:

  • /var/task/.fonts
  • /var/task/fonts
  • /opt/fonts
  • /tmp/fonts

The package describes itself as a Chromium build for AWS Lambda "and other serverless platforms". Wherever you deploy it, Vercel included, the only font it brings is Open Sans. If you switch to @sparticuz/chromium-min because your host limits deployment size (the README notes the Chromium archive is over 50 MB), nothing changes for fonts: the -min package only moves the browser files to a location you host.

#A note on chromium.font()

Older tutorials, and the package's own README up to version 143.0.0, tell you to call await chromium.font("https://.../NotoSansArabic.ttf") before launching. Up to that version the method exists, and its type definition describes it as "Downloads or symlinks a custom font and returns its basename, patching the environment so that Chromium can find it." It is not in 143.0.2 or any later release, including 158.0.0 (current on npm as of this writing). We checked the published packages: npm pack @sparticuz/chromium@143.0.0 has static font(input: string) in build/index.d.ts, and 143.0.2 does not. If you are on an older version it still works. On current versions, use one of the fixes below.

#Fix 1: embed the font in your HTML

This works on any host and any version, because the font travels with the page instead of depending on the machine. Load a font file that covers your script and declare it with @font-face as a data URI:

api/invoice.js
import chromium from "@sparticuz/chromium";
import puppeteer from "puppeteer-core";
import { readFile } from "node:fs/promises";

// Bundle the font with your function, e.g. fonts/NotoSansArabic-Regular.ttf
const arabic = (await readFile(new URL("../fonts/NotoSansArabic-Regular.ttf", import.meta.url))).toString("base64");

export async function renderArabicPdf(bodyHtml) {
  const html = `<!doctype html>
<html lang="ar" dir="rtl">
<head>
  <meta charset="utf-8">
  <style>
    @font-face {
      font-family: "Noto Sans Arabic";
      src: url(data:font/ttf;base64,${arabic}) format("truetype");
    }
    body { font-family: "Open Sans", "Noto Sans Arabic", sans-serif; }
  </style>
</head>
<body>${bodyHtml}</body>
</html>`;

  const browser = await puppeteer.launch({
    args: chromium.args,
    executablePath: await chromium.executablePath(),
    headless: true,
  });
  try {
    const page = await browser.newPage();
    await page.setContent(html, { waitUntil: "load" });
    await page.evaluateHandle("document.fonts.ready");
    return await page.pdf({ format: "A4", printBackground: true });
  } finally {
    await browser.close();
  }
}

Points that matter:

  • Wait for fonts. document.fonts.ready makes sure the web font has loaded before the PDF is captured.
  • One font per script. Noto Sans Arabic covers Arabic. Japanese needs Noto Sans JP, Hindi needs Noto Sans Devanagari, and so on. CJK fonts are large (several MB each), so subset them if you can.
  • List it in font-family. Put your Latin font first and the script font after it. The browser falls through to the second font for characters the first one lacks.
  • Mind the bundle size. Every font you embed counts toward your function's size limit.

We ran this script with @sparticuz/chromium 158.0.0 and puppeteer-core 26, and pdffonts on the output lists NotoSansArabic-Regular as embedded.

#Fix 2: put font files where Chromium looks

Because /tmp/fonts is one of the default font folders, you can copy font files there before the browser starts:

import { mkdir, copyFile } from "node:fs/promises";

await mkdir("/tmp/fonts", { recursive: true });
await copyFile(new URL("../fonts/NotoSansArabic-Regular.ttf", import.meta.url), "/tmp/fonts/NotoSansArabic-Regular.ttf");

// then launch puppeteer as usual

On AWS Lambda you can instead ship the fonts as a Lambda Layer, which the README describes: put them in a fonts folder, zip it, and attach the layer so they land in /opt/fonts. Either way, do it before puppeteer.launch(), so the files are in place when Chromium starts.

#Fix 3: make right-to-left layout correct too

Fonts fix the missing glyphs. They do not mirror your layout. For Arabic, Hebrew, Persian and Urdu also:

  • set dir="rtl" and the right lang on <html>;
  • use text-align: start / end and margin-inline-start instead of left / right, so the CSS flips with the direction;
  • wrap numbers, codes and mixed Latin text in an element with unicode-bidi: isolate, so INV-2041 does not come out backwards.

#Or use an API

If documents in many languages are a regular part of your product, you may not want a browser, a font collection and a bundle-size budget inside your functions. DevilPDF runs the browser for you, with fonts for Arabic, Hebrew, CJK, Indic, Thai and other scripts already loaded. Your function only makes an HTTP request:

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-1002",
      currency: "SAR",
      customer: { name: "شركة الأفق للتجارة" },
      items: [{ name: "استشارات", quantity: 3, unit_price: 1250 }],
    },
    output: "file",
  }),
});
if (!res.ok) throw new Error((await res.json()).error.message);
const pdf = Buffer.from(await res.arrayBuffer());

With "locale": "ar" the starter template's labels come out in Arabic, money is formatted for the locale, and the page mirrors right to left. You can also send your own HTML instead of a template. With "options": { "kit": true } it gets the same fonts; a complete HTML document is passed through untouched and loads its own fonts. The languages page lists which font is used for each script.

The free plan has 500 documents a month, enough to test your real templates.

#Next steps