Custom Font List

PDF text and the editor font menu draw on two related but distinct sources.

SourceWhat it controls
document.assets.fonts and a text run’s fontIdImported PDF font metadata and the resources used to reconstruct native content.
fontFamily on an editable text runThe CSS font family used to lay out and render editable text.
Univer’s shared font listThe options shown in the PDF inspector’s font dropdown.

Adding an option to the shared list does not add an asset to document.assets.fonts, and it does not download or embed a font file.

Configure the editor font list

When editor.enabled is true, the PDF inspector uses the shared FontFamilyDropdown. Configure that list on UniverUIPlugin when initializing the browser:

UniverUIPlugin

  • container
    string | HTMLElement
    Element to mount into, or its DOM ID.
  • customFontFamily
    IFontConfig[] | object
    Adds these fonts to the dropdown.
    • list
      IFontConfig[]
      Adds these fonts to the dropdown.
      • value
        string
        Font family name used in CSS.
      • label
        string
        Display name or translation key.
      • category
        FontCategory
        Font group. Use sans-serif, serif, monospace, display, or handwriting.
    • override
      booleanDefault: false
      Replaces the built-in choices with the supplied list.
TypeScript
import { FontCategory, UniverUIPlugin } from '@univerjs/ui'univer.registerPlugin(UniverUIPlugin, {  container: 'app',  customFontFamily: {    list: [      {        value: 'Inter',        label: 'Inter',        category: FontCategory.SANS_SERIF,      },      {        value: 'Noto Serif',        label: 'Noto Serif',        category: FontCategory.SERIF,      },    ],    override: false,  },})

Load each browser font through @font-face or a stylesheet. Otherwise Canvas uses the browser’s fallback font.

Add choices at runtime

After the UI Facade has loaded, append choices to the same shared list with addFonts:

TypeScript
import { FontCategory } from '@univerjs/ui'univerAPI.addFonts([  {    value: 'Inter',    label: 'Inter',    category: FontCategory.SANS_SERIF,  },])

This only updates the application font list. It does not load font bytes or rewrite existing PDF runs.

Apply a font to editable PDF text

Pass fontFamily when inserting text, or update an editable text box through the PDF Facade:

TypeScript
const page = univerAPI.getActivePdf()?.getPageByIndex(0)const textBox = page?.insertTextBox({  text: 'Hello PDF',  fontFamily: 'Inter',  fontSize: 14,  left: 36,  top: 36,})textBox?.setTextStyle({ fontFamily: 'Noto Serif' })

Native imported text returned by page.getTextSpans() is a snapshot, so its style cannot be changed in place. Call replaceText(...) first to convert it into an editable text box, then call setTextStyle.

How is this guide?

© 2026 DreamNum Co., Ltd.