import { ChangeDetectionStrategy, Component, effect, inject, signal, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, 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 { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfSearch, EpdfSearchLayer, withSearch } from '@embedpdf/angular/search'; import { EpdfSelection, EpdfSelectionLayer, EpdfSelectionMenu, withSelection, } from '@embedpdf/angular/selection'; import { cloudEngine } from '@cloudpdf/engine'; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSearchLayer, EpdfSelectionLayer, EpdfSelectionMenu, ], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), withSelection(), withSearch(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './layers.css', encapsulation: ViewEncapsulation.None, template: `
@if (showSearch()) { } @if (showSelection()) { } @if (showSelection()) { }

Opening…

`, }) export class App { protected readonly showSearch = signal(true); protected readonly showSelection = signal(true); private readonly search = inject(EpdfSearch); private readonly selection = inject(EpdfSelection); private readonly document = inject(EpdfDocument); constructor() { // Something on every layer on load: the matches of a search, and the first word selected. effect(() => { const cover = this.document.pages()[0]?.ref; if (!cover) return; void this.search.search({ text: 'PDF' }); this.selection.select({ page: cover, start: 36, count: 9 }); }); } protected clearSelection() { this.selection.clear(); } }