# Custom Fonts

> Add licensed TrueType fonts to TX Sheet Control: extend the editor's font catalog, set fontCatalogURL and fill a server font folder with FontDirectory.

- **Product:** TX Sheet Control
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Sheet Control > Deployment Guide > Custom Fonts
- **1870 words**
- **Web URL:** https://docs.textcontrol.com/tx-sheet-control/deployment/custom-fonts/
- **LLMs URL:** https://docs.textcontrol.com/tx-sheet-control/deployment/custom-fonts/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-sheet-control/deployment/custom-fonts/llms-full.txt

---

When your documents use a font that TX Sheet Control does not include, such as a corporate typeface, add it to the deployment: to the font catalog of the editor and to the font folder of the server. Check that your font license allows you to deploy the font and to embed it in PDF files, and deploy every weight and style the documents use. Then check the result in the browser and in the exported files.

### Add a Font to the Editor

The editor finds its fonts through the catalog `catalog.json`. To add a font, copy the supplied `fonts` folder into your application, add the TrueType file and add an entry for its family to the catalog. Keep the supplied families: Liberation Sans is the default font of new workbooks, and the Noto families provide the characters other fonts lack.

1. Copy the supplied `fonts` folder to `public/fonts/` in your application, from the `browser` folder of the download or from `node_modules/@txtextcontrol/tx-sheet-control/dist/fonts`.
2. Add the font file, for example `ExampleSans-Regular.ttf`, to `public/fonts/`.
3. Run the following Node.js script in the folder that contains `public`. It adds the family `Example Sans` to the catalog, or replaces it when the script runs again.

```javascript
import { readFile, writeFile } from 'node:fs/promises';
import { createHash } from 'node:crypto';

const folder = new URL('./public/fonts/', import.meta.url);
const family = 'Example Sans';
const filename = 'ExampleSans-Regular.ttf';

const catalog = JSON.parse(await readFile(new URL('catalog.json', folder), 'utf8'));
const bytes = await readFile(new URL(filename, folder));
const digest = createHash('sha256').update(bytes).digest('hex');

catalog.families = catalog.families.filter(entry => entry.family !== family);
catalog.families.push({
    family, displayName: family, fallback: 'sans-serif',
    faces: [{ url: `./${filename}?v=${digest}`, format: 'ttf', weight: 400, style: 'normal' }]
});
catalog.revision = createHash('sha256')
    .update(JSON.stringify([catalog.families, catalog.warnings])).digest('hex');

await writeFile(new URL('catalog.json', folder), JSON.stringify(catalog, null, 4));
```

The script works as follows:

- It reads `catalog.json` and the bytes of the font file, and computes the SHA-256 hash of the font, which becomes the `?v=` version of its URL, as in the supplied catalog.
- `catalog.families.filter` removes an earlier entry of the family, because a family listed twice makes the editor fail with "Invalid deployed font family."
- `catalog.families.push` adds the family with one face: the relative URL of the file, the format `ttf`, the weight 400 and the style `normal`. Add a face for each further file, such as `{ ..., weight: 700, style: 'normal' }` for bold and `{ ..., weight: 400, style: 'italic' }` for italic.
- `catalog.revision` becomes the SHA-256 hash of the families and the warnings, computed the same way as for the supplied catalog.
- `writeFile` writes the extended catalog back to `catalog.json`.

Then serve `public/fonts/` with your application and set the editor's `fontCatalogURL` to the URL of its `catalog.json`:

- **JavaScript, TypeScript and Angular.** Set the [fontCatalogURL](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/browser/spreadsheetoptions/fontcatalogurl-property/llms-full.txt) option.
- **ASP.NET Core.** Set [TXSheetControlOptions.FontCatalogURL](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-aspnetcore/txsheetcontroloptions/fontcatalogurl-property/llms-full.txt) in the options of the Tag Helper.

The editor then shows the family and embeds it in the PDF files it exports. Run the script again whenever you add or replace a font file, so that the URL versions and the revision stay correct.

### Add a Font to the Server

The server packages use every TrueType file in their font folder. To add fonts, create a font folder of your own and point the server at it:

1. Copy the supplied font folder: `tx-sheet-engine/fonts` from the output of a .NET application, or `node_modules/@txtextcontrol/tx-sheet-control-server/dist/fonts` in Node.js.
2. Add your font files to the copy.
3. Set the folder in the options, or with the environment variable `TX_SHEET_FONT_DIRECTORY`, which both packages read when the option is not set:
    - .NET: [ServerSheetControlOptions.FontDirectory](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontroloptions/fontdirectory-property/llms-full.txt)
    - Node.js: [fontDirectory](https://docs.textcontrol.com/tx-sheet-control/reference/typescript-api/nodejs/serversheetcontroloptions/fontdirectory-property/llms-full.txt)

```csharp
await using var control = new ServerSheetControl(new ServerSheetControlOptions
{
    License = licenseText,
    FontDirectory = "/srv/sheet-fonts"
});
```

> Warning
>
> **Copy the Supplied Fonts.** The font folder replaces the supplied fonts; it does not add to them. A folder with only your own fonts makes PDF export fail with "No document font available: Liberation Sans", because the default font is missing.

The folder is trusted configuration of your application. Do not build its path from user input. You do not need to rebuild or reinstall the package to add a font.

### Check the Result

- **The catalog.** On the server, [GetFontCatalogAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/getfontcatalogasync-method/llms-full.txt) in .NET and [getFontCatalog](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/nodejs/serversheetcontrol/getfontcatalog-method/llms-full.txt) in Node.js list the families found and a warning for every file that could not be read, such as "Broken.ttf: Invalid TrueType font size." After you change the folder of a running server, call [RefreshFontsAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/refreshfontsasync-method/llms-full.txt) or [refreshFonts](https://docs.textcontrol.com/tx-sheet-control/reference/javascript-api/nodejs/serversheetcontrol/refreshfonts-method/llms-full.txt).
- **The editor.** `editor.ready` must resolve. A catalog error rejects it, for example with "Invalid deployed font face." for a WOFF2 file or a weight outside 1 to 1000.
- **The family name.** In the editor, a family has the name of its catalog entry. On the server, it has the family name stored in the font file, which [GetFontCatalogAsync](https://docs.textcontrol.com/tx-sheet-control/reference/dotnet-api/txtextcontrol-txsheetcontrol-server/serversheetcontrol/getfontcatalogasync-method/llms-full.txt) shows. Give the catalog entry the same name, so that cells formatted in the editor find the font on the server.
- **The output.** Export a PDF with text in the new font, including accented characters, currency symbols and the languages of your application, and check the line breaks and page breaks.

### Next Steps

- [Font Handling](https://docs.textcontrol.com/tx-sheet-control/deployment/fonts/llms-full.txt): see how the catalog, the font folder and the replacement fonts work.
- [Fonts in Documents](https://docs.textcontrol.com/tx-sheet-control/document-processing/document-fonts/llms-full.txt): supply fonts with a document, and embed the used fonts in the files you save.
- [Deployment Problems](https://docs.textcontrol.com/tx-sheet-control/deployment/problems/llms-full.txt): fix font errors after the deployment.

---

## Nearby

- **Previous:** [Included Fonts and Notices](https://docs.textcontrol.com/tx-sheet-control/deployment/included-fonts/llms-full.txt)
- **Next:** [ASP.NET Core Applications](https://docs.textcontrol.com/tx-sheet-control/deployment/aspnet-core/llms-full.txt)
