> ## Documentation Index
> Fetch the complete documentation index at: https://komga-sdk.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Fonts

> List font families and retrieve CSS or font files

Komga exposes font resources for WebPub and EPUB readers. Font listing returns strings; CSS and font-file operations return binary `Blob | File` data.

## List available fonts

```typescript theme={null}
import { getFonts } from 'komga-sdk';

const result = await getFonts({ client });
if (result.error) {
  console.error(result.response?.status, result.error);
} else {
  for (const family of result.data ?? []) {
    console.log(family);
  }
}
```

The list contains family names, not file descriptors. To discover the files for a family, fetch its CSS and inspect the `@font-face` declarations or use the file names supplied by your reader integration. Keep the exact spelling and casing returned by Komga when passing `fontFamily`.

> [!NOTE]
>
> The CSS and file routes are reader resources, but deployment security and browser origin still matter. Fetch them through the SDK when the reader needs the configured base URL, session credentials, or API key; a direct CSS `<link>` cannot use the SDK client's headers.

## Load a font in a browser reader

Use the CSS endpoint when you want the server's `@font-face` declarations. Use `getFontFile` when a reader needs an explicit `FontFace` and remember to release the object URL:

```typescript theme={null}
import { getFontFile } from 'komga-sdk';

async function loadReaderFont(family: string, fileName: string): Promise<FontFace> {
  const result = await getFontFile({ fontFamily: family, fontFile: fileName }, { client });
  if (result.error || !result.data) {
    throw new Error(`Could not load ${family}/${fileName}`);
  }

  const objectUrl = URL.createObjectURL(result.data);
  try {
    const font = new FontFace(family, `url(${JSON.stringify(objectUrl)})`);
    await font.load();
    document.fonts.add(font);
    return font;
  } finally {
    URL.revokeObjectURL(objectUrl);
  }
}
```

## Get font-family CSS

Pass the family as the flat `fontFamily` parameter. The response is a `Blob | File`, so read it as text before injecting it:

```typescript theme={null}
import { getFontFamilyAsCss } from 'komga-sdk';

const result = await getFontFamilyAsCss(
  { fontFamily: 'Noto Sans' },
  { client },
);

if (!result.error && result.data) {
  const css = await result.data.text();
  const style = document.createElement('style');
  style.textContent = css;
  document.head.appendChild(style);
}
```

## Get a font file

The file operation takes both `fontFamily` and `fontFile` as flat parameters:

```typescript theme={null}
import { getFontFile } from 'komga-sdk';

const result = await getFontFile(
  {
    fontFamily: 'Noto Sans',
    fontFile: 'NotoSans-Regular.ttf',
  },
  { client },
);

if (!result.error && result.data) {
  const fontUrl = URL.createObjectURL(result.data);
  console.log(fontUrl);
}
```

## Save a font file in Node.js

The generated response is binary in every runtime. In Node.js, use the native `Blob` and `ArrayBuffer` APIs and write the bytes with `node:fs/promises`:

```typescript theme={null}
import { writeFile } from 'node:fs/promises';
import { getFontFile } from 'komga-sdk';

const result = await getFontFile(
  { fontFamily: 'Noto Sans', fontFile: 'NotoSans-Regular.ttf' },
  { client },
);

if (result.error || !(result.data instanceof Blob)) {
  throw new Error(`Font request failed (${result.response?.status ?? 'network error'})`);
}

await writeFile('NotoSans-Regular.ttf', Buffer.from(await result.data.arrayBuffer()));
```

The SDK does not cache fonts. Cache the bytes or CSS in your reader application only when the server's update policy permits it, and key cached values by both family and file name.

## Error handling

Font calls return the generated result union by default. Use `unwrap` when you want a typed throwing boundary:

```typescript theme={null}
import { getFonts, KomgaApiError, unwrap } from 'komga-sdk';

try {
  const families = unwrap(await getFonts({ client }));
  console.log(families);
} catch (error) {
  if (error instanceof KomgaApiError) {
    console.error(`Font request failed (${error.status})`, error.body);
  } else {
    throw error;
  }
}
```

## Next steps

> **[Book content](/guides/book-content)**
>
> Access pages, manifests, and resources.

> **[Authentication](/authentication)**
>
> Configure Basic or API-key authentication.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.