import { ChangeDetectionStrategy, Component, inject, signal, ViewEncapsulation, } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; 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 { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { EpdfInteraction, withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotation, EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { localEngine } from '@embedpdf/engine'; // [!doc-source report] const report = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/report.pdf'); return { kind: 'bytes', id: 'report', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] interface Entry { id: number; text: string; origin: string; } // Every change, once the engine has saved it, newest first. @Component({ selector: 'ol[demoActivityLog]', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'panel log' }, template: ` @for (entry of entries(); track entry.id) {
  • {{ entry.text }} {{ entry.origin }}
  • } @empty {
  • Nothing yet
  • } `, }) export class ActivityLog { private readonly annotation = inject(EpdfAnnotation); protected readonly entries = signal([]); private nextId = 0; constructor() { this.annotation.created$ .pipe(takeUntilDestroyed()) .subscribe(({ annotation, origin }) => this.log(`${annotation.author ?? 'Someone'} added a ${annotation.subtype}`, origin.kind), ); this.annotation.updated$ .pipe(takeUntilDestroyed()) .subscribe(({ annotation, origin }) => this.log(`Changed a ${annotation.subtype}`, origin.kind), ); this.annotation.deleted$ .pipe(takeUntilDestroyed()) .subscribe(({ refs, origin }) => this.log( `Deleted ${refs.length === 1 ? 'one annotation' : `${refs.length} annotations`}`, origin.kind, ), ); this.annotation.reordered$ .pipe(takeUntilDestroyed()) .subscribe(({ order, origin }) => this.log(`Restacked ${order.length} on a page`, origin.kind), ); } private log(text: string, origin: string) { this.entries.update((current) => [{ id: this.nextId++, text, origin }, ...current].slice(0, 30), ); } } const TOOLS = [ { id: 'pointer', label: 'Select' }, { id: 'square', label: 'Rectangle' }, { id: 'ink', label: 'Pen' }, ]; @Component({ selector: 'demo-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
    @for (tool of tools; track tool.id) { }
    `, }) export class Toolbar { protected readonly annotation = inject(EpdfAnnotation); protected readonly interaction = inject(EpdfInteraction); protected readonly tools = TOOLS; } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, ActivityLog, Toolbar, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), identity: { userId: 'u_381', displayName: 'Dana Smith' }, initialDocuments: [{ source: report }], }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './events.css', encapsulation: ViewEncapsulation.None, template: `

      Loading…

      `, }) export class App {}