import { ChangeDetectionStrategy, Component, computed, effect, inject, model, signal, untracked, viewChild, 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 { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotation, EpdfAnnotationLayer, EpdfHandleTemplate, EpdfRotationHandleTemplate, withAnnotation, } from '@embedpdf/angular/annotation'; import { localEngine } from '@embedpdf/engine'; const layout = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/layout.pdf'); return { kind: 'bytes', id: 'layout', bytes: new Uint8Array(await response.arrayBuffer()) }; }; const ACCENTS = ['#054fb3', '#e91e63', '#0f6e56']; @Component({ selector: 'demo-chrome-controls', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (accent of accents; track accent) { }
`, }) export class ChromeControls { /** Whether the layer draws your handles. */ readonly own = model.required(); protected readonly annotation = inject(EpdfAnnotation); protected readonly chrome = computed(() => this.annotation.settings().chrome); protected readonly accents = ACCENTS; protected setAccent(accent: string) { this.annotation.updateSettings({ chrome: { accent } }); } protected setDashed(dashed: boolean) { this.annotation.updateSettings({ chrome: { outline: { style: dashed ? 'dashed' : 'solid' } } }); } protected setRound(round: boolean) { this.annotation.updateSettings({ chrome: { handles: { shape: round ? 'circle' : 'square' } } }); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfAnnotationLayer, EpdfHandleTemplate, EpdfRotationHandleTemplate, ChromeControls, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: layout }] }, withStage(), withRender(), withInteraction(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './handles.css', encapsulation: ViewEncapsulation.None, template: ` @if (own()) {
↻
}

Loading…

`, }) export class App { protected readonly own = signal(false); private readonly annotation = inject(EpdfAnnotation); private readonly stage = viewChild(EpdfStage); private done = false; constructor() { // On load: the document's square, selected, on its page. effect(() => { const stage = this.stage(); if (!stage || this.annotation.status() !== 'ready' || this.done) return; this.done = true; untracked(() => { const square = this.annotation.list().find((each) => each.nm === 'square'); if (!square) return; this.annotation.selection.select([square.ref]); stage.reveal(square.page, { rect: square.rect }); }); }); } }