import { ChangeDetectionStrategy, Component, inject, ViewEncapsulation } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; 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 { cloudEngine } from '@cloudpdf/engine'; const sketch: OpenInput = { kind: 'grant', grant: 'shr_IyOgSdO4AmJqV4BoMv5V0nYU' }; const COLORS = ['#e5484d', '#1e90ff', '#30a46c', '#1a2748']; // The pen's color and width, for the strokes that follow. @Component({ selector: 'demo-pen-style', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (color of colors; track color) { }
`, }) export class PenStyle { protected readonly colors = COLORS; protected readonly annotation = inject(EpdfAnnotation); protected readonly defaults = this.annotation.tools.defaultsOf('ink'); } // Every change is kept for next time. @Component({ selector: 'demo-remember-defaults', changeDetection: ChangeDetectionStrategy.OnPush, template: '', }) export class RememberDefaults { constructor() { inject(EpdfAnnotation) .tools.defaultsChanged$.pipe(takeUntilDestroyed()) .subscribe(({ toolId, defaults }) => { localStorage.setItem(`tool:${toolId}`, JSON.stringify(defaults)); }); } } // On load: the pen is active. @Component({ selector: 'demo-start-with-the-pen', changeDetection: ChangeDetectionStrategy.OnPush, template: '', }) export class StartWithThePen { constructor() { inject(EpdfInteraction).activateTool('ink'); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfAnnotationLayer, StartWithThePen, RememberDefaults, PenStyle, ], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: sketch }] }, withStage(), withRender(), withInteraction(), // The pen starts with what the reader picked last time: see RememberDefaults above. withAnnotation({ tools: [{ id: 'ink', defaults: JSON.parse(localStorage.getItem('tool:ink') ?? '{}') }], }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './tool-defaults.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}