CloudPDF
DocsPricing
Start building

Fonts

The server decides which fonts exist, for every user and every document. Its fonts do three things:

  • Text can be written in them. A free text box or a form field names one by its key, and doc.fonts.list() lists them with source: 'engine'.
  • They fill in missing characters. When a document’s fonts lack a character, in a page’s text or in a box being written, the server draws it with its fallback fonts.
  • They can go to browsers. With serve: true, the viewer loads a font while someone types in it, so the text shows exactly as the server will draw it.

This is a server-side decision on purpose. Cloud clients can’t register fonts (the client engine.fonts API is local-engine only, and the viewer’s fonts setting is ignored on the cloud, with a warning); the deployment owns the font policy and applies it uniformly to every render and every saved appearance. The local engine, which runs in the browser, registers its fonts there instead.

Configure with CLOUDPDF_FONTS#

Set a JSON array of font descriptors. Each needs a stable key and a path to a TTF/OTF file readable by the server process:

CLOUDPDF_FONTS='[
  { "key": "noto-sc", "path": "/srv/fonts/NotoSansSC-Regular.otf", "familyName": "Noto Sans SC" },
  { "key": "brand-sans", "path": "/srv/fonts/BrandSans-Regular.ttf", "fallback": false, "serve": true }
]'
FieldRequiredDescription
keyyesStable id for the font: what fontFamily names it by.
pathyesAbsolute path to a TTF/OTF file the server can read.
familyNamenoBase font name; inferred from the file if omitted.
weightnoStyle weight (100–900) for matching; inferred if omitted.
italicnoItalic flag for matching; inferred if omitted.
fallbacknoFill in characters other fonts lack. Defaults to true.
servenoSend the font to browsers, so text being typed shows in it before the server draws it. Defaults to false.

Your fallback fonts are tried before the ones the server comes with (Noto Sans Hebrew and Noto Naskh Arabic). Within each, the font closest to the text’s style comes first (a bold one for bold text), then the order listed, so put your preferred faces first. A font of yours with the same key as one the server comes with replaces it. doc.fonts.list() marks the ones it comes with builtIn: true, and the viewer’s font picker leaves them out: they fill in characters whichever font a box is in. Yours are offered, fallback or not.

Sending fonts to browsers#

Every client can see your fonts (doc.fonts.list() lists them) and write with them by key. Their files stay on the server unless you set serve: true. Then the viewer loads the font while someone types in it, so the text shows exactly as the server will draw it. A font kept on the server is listed with the restriction 'not-served', and the viewer shows a similar font until the server’s picture arrives.

Serving a font sends it to your users’ browsers, which some font licences don’t allow: check yours. A served font goes only to a token that may write text in a document, and browsers keep it privately, never on a shared CDN. Noto Sans Hebrew and Noto Naskh Arabic are served: their licences allow it.

Fonts are loaded by path and range-read on demand: the bytes are never held resident in memory. You can configure several large CJK families and each costs a file handle, not RAM per font. Make sure the paths are present in your container image or mounted volume and readable by the server user.

A font that can’t be read or parsed fails worker startup: a bad font config is a boot error, not a silent degrade. Check the path and the file on a startup failure.

How it applies#

Each PDFium worker thread registers the fonts on startup, before it serves any request (the runtime is thread-confined, so every worker holds its own copy). From then on, any character a document’s fonts can’t draw, in a page’s text or in an appearance the server writes, is filled from the first fallback font that has it.

Pictures depend on the fallback fonts, so the server’s fonts are part of the engine value every picture’s URL and the font list’s carry. When you change them, every page is drawn again once and the font list is read again; a restart that changes nothing keeps every cached picture. During a rolling deploy, a replica asked for a URL with another engine value draws the picture with its own fonts and answers it uncached, so nothing is cached under the wrong fonts and no request fails; the client then reads the document’s head again.

Embedding via buildApp#

If you embed the server with buildApp instead of running the CLI, pass the same descriptors programmatically:

import { buildApp, createLicenseRuntime, loadServerFontsFromEnv } from '@cloudpdf/server';
 
const { app } = await buildApp({
  license: await createLicenseRuntime({ db }),
  db,
  workerEntry,
  fonts: [
    { key: 'noto-sc', path: '/srv/fonts/NotoSansSC-Regular.otf', familyName: 'Noto Sans SC' },
  ],
  // …or reuse the env convention: fonts: loadServerFontsFromEnv(),
});