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, 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] // A pen, 24 Ă— 24, in a color: its tip is the bottom-left corner. const penIcon = (color: string) => `` + `` + ``; // The pen cursor follows the pen's color: the spec is read again when the color changes. @Component({ selector: 'demo-ink-cursor', changeDetection: ChangeDetectionStrategy.OnPush, template: '', }) export class InkCursor { constructor() { const defaults = inject(EpdfAnnotation).tools.defaultsOf('ink'); inject(EpdfInteraction).overrideCursor(() => ({ toolId: 'ink', cursors: { crosshair: { svg: penIcon(defaults().color ?? '#000000'), hotspot: { x: 2, y: 22 } }, }, })); } } const COLORS = ['#e5484d', '#1e90ff', '#30a46c', '#1a2748']; @Component({ selector: 'demo-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (swatch of colors; track swatch) { }
`, }) export class Toolbar { protected readonly colors = COLORS; private readonly annotation = inject(EpdfAnnotation); protected readonly interaction = inject(EpdfInteraction); protected readonly defaults = this.annotation.tools.defaultsOf('ink'); constructor() { // The pen is active on load: move the pointer over the page. this.interaction.activateTool('ink'); } protected pick(swatch: string) { this.annotation.tools.updateDefaults('ink', { color: swatch }); this.interaction.activateTool('ink'); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfAnnotationLayer, InkCursor, Toolbar, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: sketch }] }, withStage(), withRender(), withInteraction(), // A standard cursor for the rectangle tool: any CSS cursor name. withAnnotation({ tools: [{ id: 'square', cursor: 'cell' }] }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './cursor.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}