import { Viewer, DocumentGate, usePageList } from '@embedpdf/react/runtime'; import type { Font, FontRestriction, OpenInput } from '@embedpdf/react/runtime'; import { interactionPlugin } from '@embedpdf/react/interaction'; import { annotationPlugin, useAnnotation } from '@embedpdf/react/annotation'; import { fontsPlugin, useFontsState } from '@embedpdf/react/fonts'; import { localEngine } from '@embedpdf/engine'; import './list.css'; const engine = localEngine(); const plugins = [interactionPlugin(), annotationPlugin(), fontsPlugin()]; // [!doc-source welcome] const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] const GROUPS = [ ['document', 'In this document'], ['engine', 'The engine’s fonts'], ['standard', 'Standard'], ] as const; // Why a font can't be chosen for new text, by its first restriction. const WHY: Record = { subset: 'holds only the characters its text uses', 'not-embedded': 'the file only names it', 'preview-and-print': 'licensed for viewing and printing only', 'unsupported-format': 'new text is written in TrueType or OpenType', 'no-unicode-map': 'doesn’t say which characters it draws', 'not-served': 'stays on the server', }; function FontChip({ font }: { font: Font }) { const why = font.canChoose ? null : WHY[font.restrictions[0] ?? 'unsupported-format']; return (
  • {font.name} {why && {why}}
  • ); } // Every font the document can be written in, grouped by where it comes from. function Fonts() { const { fonts, status } = useFontsState(); const annotation = useAnnotation(); const cover = usePageList()[0]?.ref; // The engine fills Hebrew in from a Hebrew font and puts it in the file: the list reads it. const writeHebrew = async () => { if (!cover) return; await annotation.create(cover, { subtype: 'free-text', box: { x: 72, y: 72, width: 220, height: 40 }, contents: 'שלום עולם', fontFamily: 'helvetica', }); }; return (

    Fonts

    {status}
    {GROUPS.map(([source, title]) => { const group = fonts?.fonts.filter((font) => font.source === source) ?? []; return (

    {title}

    {group.length === 0 ? (

    None

    ) : (
      {group.map((font) => ( ))}
    )}
    ); })}
    ); } export default function App() { return ( Loading…

    }>
    ); }