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 { EpdfAnnotation, EpdfAnnotationDraftMenu, EpdfAnnotationLayer, withAnnotation, } from '@embedpdf/angular/annotation'; import { cloudEngine } from '@cloudpdf/engine'; const layout: OpenInput = { kind: 'grant', grant: 'shr_d2E_LaTuddJbZR00d1CvkqLM' }; const TOOLS = [ { id: 'pointer', label: 'Select' }, { id: 'polygon', label: 'Polygon' }, { id: 'polyline', label: 'Polyline' }, ]; @Component({ selector: 'demo-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (tool of tools; track tool.id) { }

Delete removes the selection; Escape stops a shape

`, }) export class Toolbar { protected readonly interaction = inject(EpdfInteraction); protected readonly tools = TOOLS; constructor() { // The polygon tool is active on load: click a few points on the page. this.interaction.activateTool('polygon'); } } // Done and Cancel next to the shape being drawn, for touch screens. @Component({ selector: 'demo-draft-menu', imports: [EpdfAnnotationDraftMenu], changeDetection: ChangeDetectionStrategy.OnPush, template: ` `, }) export class DraftMenu { protected readonly annotation = inject(EpdfAnnotation); } // Delete and Escape: the plugin leaves the keys to your app. @Component({ selector: 'demo-annotation-keys', changeDetection: ChangeDetectionStrategy.OnPush, host: { '(window:keydown)': 'onKey($event)' }, template: '', }) export class AnnotationKeys { private readonly annotation = inject(EpdfAnnotation); private readonly interaction = inject(EpdfInteraction); protected onKey(event: KeyboardEvent) { if (event.target instanceof HTMLInputElement || this.annotation.text.getEditing()) return; if (event.key === 'Delete' || event.key === 'Backspace') { void this.annotation.selection.delete(); } if (event.key === 'Escape') { this.annotation.cancel(); // a drag or a polygon in progress this.interaction.activateDefaultTool(); } } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfAnnotationLayer, AnnotationKeys, Toolbar, DraftMenu, ], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: layout }] }, withStage(), withRender(), withInteraction(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './polygon.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}