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 { EpdfSearch, EpdfSearchLayer, withSearch } from '@embedpdf/angular/search'; import { localEngine } from '@embedpdf/engine'; // Each pair: every match, and the active one. const COLORS = [ { name: 'Yellow', color: '#ffd500', activeColor: '#ff9632' }, { name: 'Blue', color: '#a5d8ff', activeColor: '#4c9bff' }, { name: 'Green', color: '#b2f2bb', activeColor: '#40c057' }, { name: 'Pink', color: '#fcc2d7', activeColor: '#f06595' }, ]; 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({ highlight: { color: '#ffd500', activeColor: '#ff9632' } }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './highlight-colors.css', encapsulation: ViewEncapsulation.None, template: `
@for (choice of colors; track choice.name) { }

Loading…

`, }) export class App { protected readonly colors = COLORS; protected readonly fromCss = signal(false); protected readonly search = inject(EpdfSearch); private readonly document = inject(EpdfDocument); constructor() { // Something to highlight, once the document is open. effect(() => { if (this.document.status() === 'ready') { void this.search.search({ text: 'PDF' }); } }); } }