import { ChangeDetectionStrategy, Component, inject, signal, ViewEncapsulation, } from '@angular/core'; import { EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime'; import type { OpenInput } from '@embedpdf/angular/runtime'; import { EpdfPageTemplate, EpdfStage, withStage } from '@embedpdf/angular/stage'; import { EpdfRenderLayer, withRender } from '@embedpdf/angular/render'; import { EpdfInteraction, withInteraction } from '@embedpdf/angular/interaction'; import { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { standardCommands, withCommands } from '@embedpdf/angular/commands'; import { EpdfToolbar, EpdfToolbarCommandTemplate, group } from '@embedpdf/angular/toolbar'; import type { BarSchema } from '@embedpdf/angular/toolbar'; import { localEngine } from '@embedpdf/engine'; // [!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] // A bar per mode. const viewBar: BarSchema = { id: 'view', sections: { start: [group('tools', ['tool:pointer', 'tool:pan'])], center: [ group('pages', ['page:previous', 'page:next']), group('zoom', ['zoom:out', 'zoom:in']), ], }, }; const annotateBar: BarSchema = { id: 'annotate', sections: { start: [group('markup', ['tool:highlight', 'tool:underline', 'tool:strikeout'])], center: [group('draw', ['tool:ink', 'tool:square', 'tool:circle', 'tool:note'])], end: [group('edit', ['annotation:delete'])], }, }; type Mode = 'view' | 'annotate'; const BARS: Record = { view: viewBar, annotate: annotateBar }; const TOOL_OF_MODE: Record = { view: 'pointer', annotate: 'highlight' }; @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, EpdfToolbar, EpdfToolbarCommandTemplate, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), withCommands({ commands: standardCommands }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './modes.css', encapsulation: ViewEncapsulation.None, template: `
@for (each of modes; track each) { }

Loading…

`, }) export class App { private readonly interaction = inject(EpdfInteraction); protected readonly modes = ['view', 'annotate'] as const; protected readonly bars = BARS; protected readonly mode = signal('view'); // Each mode starts with its own tool. protected switchTo(next: Mode) { this.mode.set(next); this.interaction.activateTool(TOOL_OF_MODE[next]); } }