import { ChangeDetectionStrategy, Component, computed, effect, inject, 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 { EpdfSearch, EpdfSearchLayer, withSearch } from '@embedpdf/angular/search'; import { localEngine } from '@embedpdf/engine'; 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()) }; }; @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSearchLayer], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withSearch(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './pass-through.css', encapsulation: ViewEncapsulation.None, template: `
    @for (hit of firstHits(); track hit.page.objectNumber + ':' + hit.start) { @if (hit.bounds; as bounds) {
  1. } }

Loading…

`, }) export class App { private readonly search = inject(EpdfSearch); private readonly document = inject(EpdfDocument); protected readonly firstHits = computed(() => this.search.hits().slice(0, 8)); protected readonly round = Math.round; constructor() { effect(() => { if (this.document.status() === 'ready') void this.search.search({ text: 'PDF' }); }); } }