import { ChangeDetectionStrategy, Component, computed, 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, EpdfSnapshotLayer, withRender } from '@embedpdf/angular/render'; import { EpdfInteraction, withInteraction } from '@embedpdf/angular/interaction'; import { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { cloudEngine } from '@cloudpdf/engine'; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; const LABELS: Record = { pointer: 'Select', pan: 'Hand', zoom: 'Zoom', snapshot: 'Snapshot', }; const HINTS: Record = { pointer: 'A drag selects text', pan: 'A drag scrolls the pages', zoom: 'A drag zooms to the box, a click zooms in', snapshot: 'A drag takes part of a page as an image', }; // A button for every tool you can switch to, the active one pressed. @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfSnapshotLayer, ], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), // The document opens with the hand tool. withInteraction({ defaultTool: 'pan' }), withSelection(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './switch.css', encapsulation: ViewEncapsulation.None, template: `
@for (tool of interaction.tools(); track tool.id) { }
{{ hint() }}

Loading…

`, }) export class App { protected readonly interaction = inject(EpdfInteraction); protected readonly labels = LABELS; protected readonly hint = computed(() => { const activeToolId = this.interaction.activeToolId(); return activeToolId ? HINTS[activeToolId] : ''; }); }