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 { EpdfSearch, EpdfSearchLayer, withSearch } from '@embedpdf/angular/search'; 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] // Which match is the active one: the first on load, then the one you click. @Component({ selector: 'demo-active-match', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@if (search.hitCount() > 0) { Match {{ search.activeHitIndex() + 1 }} of {{ search.hitCount() }} } @else { Searching… } Click a highlighted match to make it the active one.
`, }) export class ActiveMatch { protected readonly search = inject(EpdfSearch); constructor() { // It's drawn once the document is open: search right away. void this.search.search({ text: 'PDF' }); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSearchLayer, ActiveMatch, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withSearch(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './click-match.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App { protected readonly search = inject(EpdfSearch); }