import { ChangeDetectionStrategy, Component, effect, inject, signal, untracked, 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 { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfSelection, EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { EpdfSearch, EpdfSearchLayer, withSearch } from '@embedpdf/angular/search'; import { localEngine } from '@embedpdf/engine'; const FIRST_WORD = { start: 28, count: 9 }; 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()) }; }; // On load: the first word is selected and "PDF" is found, so every color below has something to paint. @Component({ selector: 'demo-show-colors', changeDetection: ChangeDetectionStrategy.OnPush, template: '', }) export class ShowColors { constructor() { const selection = inject(EpdfSelection); const document = inject(EpdfDocument); void inject(EpdfSearch).search({ text: 'PDF' }); effect(() => { const cover = document.pages()[0]?.ref; if (cover) untracked(() => selection.select({ page: cover, ...FIRST_WORD })); }); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSearchLayer, EpdfSelectionLayer, ShowColors, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), withSelection(), withSearch(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './dark-mode.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App { protected readonly theme = signal<'light' | 'dark'>('dark'); }