Docs / Guides

Markdown

Fonts

Word documents, workbooks and many PDFs name fonts they do not include. DocuVerse uses fonts embedded in the file, fonts you register, and fonts installed on the server.

In the browser

The viewer asks your server for the fonts a document needs, through fontUrl. The npm package answers those requests from the fonts installed on a Node.js server:

import { fontResponse } from 'docuverse/fonts';export const GET = (request) => fontResponse(request);// createViewer(element, { fontUrl: '/uds-fonts' })

In .NET

app.MapGet("/uds-fonts", (string? family, string? bold, string? italic, int? @char) =>{    var bytes = family is not null ? DocuVerse.Fonts.Find(family, bold == "1", italic == "1")        : @char is int c ? DocuVerse.Fonts.ForChar(c) : null;    return bytes is null ? Results.NotFound() : Results.File(bytes, "font/ttf");});// <PdfViewer FontUrl="/uds-fonts" />

Your own fonts

registerFont(bytes) in JavaScript, or Fonts.Register(bytes) in .NET, adds a TrueType or OpenType font. After registering, call relayout() on an open document.

A font that is not embedded, registered or installed is replaced by the closest standard font: the same widths, different letter shapes.