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, withRender } from '@embedpdf/angular/render'; import { EpdfSearch, EpdfSearchLayer, withSearch } from '@embedpdf/angular/search'; import type { SearchHit } from '@embedpdf/angular/search'; import { EpdfShell, withShell } from '@embedpdf/angular/shell'; 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] // The panel shows the match its props name, and steps to the next one without reopening. @Component({ selector: 'aside[demoMatchPanel]', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'panel', 'aria-label': 'Match' }, template: `

Match {{ index() + 1 }} of {{ search.hits().length }}

@if (hit(); as hit) {

Page {{ hit.pageIndex + 1 }}

@if (hit.snippet; as snippet) {

…{{ snippet.before }}{{ snippet.match }}{{ snippet.after }}…

} } @else {

Searching…

}
`, }) export class MatchPanel { private readonly shell = inject(EpdfShell); protected readonly search = inject(EpdfSearch); protected readonly panel = this.shell.surface('match'); protected readonly index = computed(() => { const index = this.panel.props()['index']; return typeof index === 'number' ? index : 0; }); protected readonly hit = computed(() => this.search.hits()[this.index()]); protected show(next: number) { this.shell.updateSurfaceProps('match', { index: next }); this.search.goToHit(this.search.hits()[next]); } } @Component({ selector: 'div[demoWorkspace]', imports: [EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSearchLayer, MatchPanel], changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'workspace' }, template: ` @if (panel.isOpen()) { } `, }) export class Workspace { private readonly shell = inject(EpdfShell); private readonly search = inject(EpdfSearch); protected readonly panel = this.shell.surface('match'); constructor() { // Every "PDF" on the pages, and the first one open in the panel. void this.search.search({ text: 'PDF' }); this.shell.open('match', { exclusive: 'right', props: { index: 0 } }); } protected open(hit: SearchHit) { const index = this.search.hits().indexOf(hit); this.shell.open('match', { exclusive: 'right', props: { index } }); } } @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, Workspace], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withSearch(), withShell(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './props.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}