import { ChangeDetectionStrategy, Component, computed, DestroyRef, inject, input, signal, ViewEncapsulation, } from '@angular/core'; import { EpdfDocumentGate, injectPage, pageRefsEqual, provideEmbedPdf, } from '@embedpdf/angular/runtime'; import type { OpenInput, PageRef } from '@embedpdf/angular/runtime'; import { EpdfPageTemplate, EpdfStage, withStage } from '@embedpdf/angular/stage'; import { EpdfRenderLayer, withRender } from '@embedpdf/angular/render'; import { EpdfInteraction, svgCursor, withInteraction } from '@embedpdf/angular/interaction'; import { cloudEngine } from '@cloudpdf/engine'; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; interface Pin { readonly id: number; readonly page: PageRef; readonly point: { readonly x: number; readonly y: number }; } // The cursor is the pin itself; its tip is the point that clicks. const PIN_CURSOR = svgCursor({ svg: ` `, hotspot: { x: 12, y: 23 }, fallback: 'copy', }); // The pins on one page, placed in its pixels at the last moment. @Component({ selector: 'demo-pin-layer', changeDetection: ChangeDetectionStrategy.OnPush, template: ` @for (pin of onThisPage(); track pin.id) { {{ pin.id }} } `, }) export class PinLayer { readonly pins = input.required(); private readonly page = injectPage(''); protected readonly onThisPage = computed(() => this.pins().filter((pin) => pageRefsEqual(pin.page, this.page.ref)), ); protected pixels(pin: Pin) { return this.page.transform().toPixels(pin.point); } } @Component({ selector: 'demo-pin-board', imports: [EpdfStage, EpdfPageTemplate, EpdfRenderLayer, PinLayer], changeDetection: ChangeDetectionStrategy.OnPush, template: `
{{ pins().length === 0 ? 'Click a page to drop a pin' : pins().length + ' pins' }}
`, }) export class PinBoard { protected readonly interaction = inject(EpdfInteraction); protected readonly pins = signal([]); constructor() { // A tool of your own: a click on a page drops a pin there, in page coordinates. const remove = this.interaction.registerTool({ id: 'pin', cursor: PIN_CURSOR, onPointerDown: ({ page, point }) => { this.pins.update((current) => [...current, { id: current.length + 1, page, point }]); return true; // this tool handled the click }, }); this.interaction.activateTool('pin'); inject(DestroyRef).onDestroy(remove); } } @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, PinBoard], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './pin.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}