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 { EpdfAnchored } from '@embedpdf/angular/anchored';
import { cloudEngine } from '@cloudpdf/engine';
const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' };
// A button below the active match: it follows the match while you scroll and zoom.
@Component({
selector: 'demo-next-match',
imports: [EpdfAnchored],
changeDetection: ChangeDetectionStrategy.OnPush,
template: `
`,
})
export class NextMatch {
protected readonly search = inject(EpdfSearch);
protected readonly anchor = computed(() => {
const hit = this.search.activeHit();
return hit && { page: hit.page, bounds: hit.bounds };
});
}
@Component({
selector: 'demo-root',
imports: [
EpdfDocumentGate,
EpdfStage,
EpdfPageTemplate,
EpdfRenderLayer,
EpdfSearchLayer,
NextMatch,
],
providers: [
provideEmbedPdf(
{ engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] },
withStage(),
withRender(),
withSearch(),
),
],
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrl: './overlay.css',
encapsulation: ViewEncapsulation.None,
template: `
Loading…
`,
})
export class App {
private readonly search = inject(EpdfSearch);
private readonly document = inject(EpdfDocument);
constructor() {
// Every "PDF" in the document, and the view on the first one.
effect(() => {
if (this.document.status() !== 'ready') return;
void this.search.search({ text: 'PDF' }).then(() => this.search.revealActiveHit());
});
}
}