import { ChangeDetectionStrategy, Component, inject, 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 { annotationKey, EpdfAnnotation, EpdfAnnotationLayer, withAnnotation, } from '@embedpdf/angular/annotation'; import { localEngine } from '@embedpdf/engine'; // [!doc-source sketch] const sketch = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/sketch.pdf'); return { kind: 'bytes', id: 'sketch', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] const TOOLS = [ { id: 'pointer', label: 'Select' }, { id: 'square', label: 'Rectangle' }, { id: 'note', label: 'Note' }, ]; @Component({ selector: 'demo-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (tool of tools; track tool.id) { }
`, }) export class Toolbar { protected readonly tools = TOOLS; protected readonly interaction = inject(EpdfInteraction); } const time = (date: string | null) => date ? new Date(date).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }) : ''; // Who wrote each annotation, and when: the engine fills these in from the identity. @Component({ selector: 'ul[demoAuthors]', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'panel authors' }, template: ` @if (annotations().length === 0) {
  • Draw something
  • } @for (annotation of annotations(); track key(annotation.ref)) {
  • {{ annotation.subtype }} {{ annotation.author ?? 'Nobody' }} · {{ time(annotation.createdAt) }}
  • } `, }) export class Authors { protected readonly annotations = inject(EpdfAnnotation).watch(); protected readonly key = annotationKey; protected readonly time = time; } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfAnnotationLayer, Toolbar, Authors, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), identity: { userId: 'u_381', displayName: 'Dana Smith' }, initialDocuments: [{ source: sketch }], }, withStage(), withRender(), withInteraction(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './identity.css', encapsulation: ViewEncapsulation.None, template: `

      Loading…

      `, }) export class App {}