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 { localEngine } from '@embedpdf/engine'; // [!doc-source welcome] const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] 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: () => localEngine(), 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] : ''; }); }