import { ChangeDetectionStrategy, Component, computed, inject, input, signal, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, 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 { withInteraction } from '@embedpdf/angular/interaction'; import { annotationKey, EpdfAnnotation, EpdfAnnotationLayer, withAnnotation, type Annotation, type AnnotationSubtype, } from '@embedpdf/angular/annotation'; import { localEngine } from '@embedpdf/engine'; // [!doc-source proposal] const proposal = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/proposal.pdf'); return { kind: 'bytes', id: 'proposal', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] interface Kind { label: string; subtype?: AnnotationSubtype; } const KINDS: Kind[] = [ { label: 'All' }, { label: 'Highlights', subtype: 'highlight' }, { label: 'Notes', subtype: 'text' }, { label: 'Rectangles', subtype: 'square' }, ]; /** * The annotations of one kind, in drawing order. A click shows one on its page. Next to * ``: `
`. */ @Component({ selector: 'div[demoAnnotationList]', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'panel' }, template: `
@for (each of kinds; track each.label) { }

{{ annotations().length }} found

`, }) export class AnnotationList { readonly stage = input.required(); private readonly annotation = inject(EpdfAnnotation); private readonly pages = inject(EpdfDocument).pages; protected readonly kinds = KINDS; protected readonly kind = signal(KINDS[0]!); private readonly ofKind = this.annotation.watch(() => { const subtype = this.kind().subtype; return subtype ? { subtype } : undefined; }); // Replies and review states belong to their comment's thread: the list leaves them out. protected readonly annotations = computed(() => this.ofKind().filter((each) => each.reply?.type !== 'reply'), ); protected readonly key = annotationKey; protected pageNumberOf(objectNumber: number) { return this.pages().findIndex((page) => page.ref.objectNumber === objectNumber) + 1; } protected show(each: Annotation) { this.stage().reveal(each.page, { rect: each.rect }); this.annotation.selection.select([each.ref]); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, AnnotationList, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: proposal }] }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './list.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}