Skip to content
Document Authoring DA  API Docs v1.9.1
npmGitHub

FontConfig>= v1.0.26

FontConfig:

Font configuration for the Document Authoring system.

The font system supports three approaches:

import { createDocAuthSystem, defaultFontIndex } from '@nutrient-sdk/document-authoring';
const system = await createDocAuthSystem({
fontConfig: {
fonts: [
{ type: 'file', blob: fetch('/fonts/custom-font.ttf') },
{ type: 'file', blob: fetch('/fonts/another-font.ttf') },
],
},
});
// Step 1: Generate font index using CLI
// $ npx document-authoring create-font-index --scan-directory ./fonts --write-to public/fonts/font-index.json
// Step 2: Configure system to use the index
import { createDocAuthSystem, defaultFontIndex } from '@nutrient-sdk/document-authoring';
const system = await createDocAuthSystem({
fontConfig: {
fonts: [
defaultFontIndex, // Built-in fonts
{
type: 'index',
index: fetch('/fonts/font-index.json'),
loadFn: (name) => fetch(`/fonts/${name}`),
},
],
},
});
// Fonts from the index are loaded on-demand as documents use them
import { createDocAuthSystem, defaultFontIndex } from '@nutrient-sdk/document-authoring';
// Configure font sources
const system = await createDocAuthSystem({
fontConfig: {
fonts: [
{
type: 'index',
index: fetch('/fonts/corporate-fonts.json'),
loadFn: (name) => fetch(`/fonts/${name}`),
},
],
},
});
// Import a DOCX that uses custom fonts
const doc = await system.importDOCX(fetch('/template.docx'));
// System automatically loads required fonts from the index
// Create editor with the document
const editor = await system.createEditor(targetElement, { document: doc });
// Users can now select from all available fonts in the UI

optional fonts: (DefaultFontIndex | FontIndex | FontFile)[]

The set of fonts available to the Document Authoring system. If unset the DefaultFontIndex is used.

Individual fonts can be added directly using a FontFile or loaded by the system as they are needed using a pre-built FontIndex that lists all available fonts. A FontIndex is the recommended way to provide a set of fonts to the system in a production environment.