import { ChangeDetectionStrategy, Component, computed, inject, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime'; import type { Font, FontRestriction, OpenInput } from '@embedpdf/angular/runtime'; import { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotation, withAnnotation } from '@embedpdf/angular/annotation'; import { EpdfFonts, withFonts } from '@embedpdf/angular/fonts'; import { cloudEngine } from '@cloudpdf/engine'; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; 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', }; // Every font the document can be written in, grouped by where it comes from. @Component({ selector: 'demo-root', imports: [EpdfDocumentGate], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] }, withInteraction(), withAnnotation(), withFonts(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './list.css', encapsulation: ViewEncapsulation.None, template: `

Fonts

{{ fonts.status() }}
@for (group of groups(); track group.source) {

{{ group.title }}

@if (group.fonts.length === 0) {

None

} @else {
    @for (font of group.fonts; track font.name) { @let why = whyOf(font);
  • {{ font.name }} @if (why) { {{ why }} }
  • }
}
}

Loading…

`, }) export class App { protected readonly fonts = inject(EpdfFonts); private readonly annotation = inject(EpdfAnnotation); private readonly document = inject(EpdfDocument); protected readonly groups = computed(() => GROUPS.map(([source, title]) => ({ source, title, fonts: this.fonts.list()?.fonts.filter((font) => font.source === source) ?? [], })), ); protected whyOf(font: Font) { return font.canChoose ? null : WHY[font.restrictions[0] ?? 'unsupported-format']; } // The engine fills Hebrew in from a Hebrew font and puts it in the file: the list reads it. protected async writeHebrew() { const cover = this.document.pages()[0]?.ref; if (!cover) return; await this.annotation.create(cover, { subtype: 'free-text', box: { x: 72, y: 72, width: 220, height: 40 }, contents: 'שלום עולם', fontFamily: 'helvetica', }); } }