import { ChangeDetectionStrategy, Component, computed, effect, inject, input, 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 { EpdfAnchored } from '@embedpdf/angular/anchored'; import type { AnchoredPlacement, AnchoredSide } from '@embedpdf/angular/anchored'; import { cloudEngine } from '@cloudpdf/engine'; const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' }; const SIDES: AnchoredSide[] = ['top', 'right', 'bottom', 'left']; const ALIGNS = ['start', 'center', 'end'] as const; // A card next to the active match, where you put it, `gap` pixels away. @Component({ selector: 'demo-match-card', imports: [EpdfAnchored], changeDetection: ChangeDetectionStrategy.OnPush, template: ` Match {{ search.activeHitIndex() + 1 }} of {{ search.hitCount() }} Page {{ (search.activeHit()?.pageIndex ?? 0) + 1 }} ← → `, }) export class MatchCard { readonly placement = input.required(); readonly gap = input.required(); readonly pinned = input.required(); 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, MatchCard, ], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withSearch(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './placement.css', encapsulation: ViewEncapsulation.None, template: ` @for (each of sides; track each) { {{ each }} } @for (each of aligns; track each) { {{ each }} } Gap {{ gap() }} px Pinned Loading… `, }) export class App { protected readonly sides = SIDES; protected readonly aligns = ALIGNS; protected readonly side = signal('top'); protected readonly align = signal<(typeof ALIGNS)[number]>('center'); protected readonly gap = signal(8); protected readonly pinned = signal(false); protected readonly placement = computed((): AnchoredPlacement => { const side = this.side(); const align = this.align(); return align === 'center' ? side : `${side}-${align}`; }); private readonly search = inject(EpdfSearch); private readonly document = inject(EpdfDocument); constructor() { effect(() => { if (this.document.status() !== 'ready') return; void this.search.search({ text: 'PDF' }).then(() => this.search.revealActiveHit()); }); } }
Loading…