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 { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfSelection, EpdfSelectionHandles, EpdfSelectionLayer, withSelection, } from '@embedpdf/angular/selection'; import { localEngine } from '@embedpdf/engine'; // Each: the selected text and its handles. `null` is the viewer's accent: at 35% for the text. const COLORS = [ { name: 'Accent', color: null, handles: null, swatch: '#3858e9' }, { name: 'Yellow', color: 'rgb(250 204 21 / 0.45)', handles: '#ca8a04', swatch: '#facc15' }, { name: 'Green', color: 'rgb(34 197 94 / 0.35)', handles: '#16a34a', swatch: '#22c55e' }, { name: 'Pink', color: 'rgb(236 72 153 / 0.3)', handles: '#db2777', swatch: '#ec4899' }, ]; // [!doc-source welcome] 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()) }; }; // [!/doc-source] @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfSelectionHandles, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), withSelection({ handles: { shadow: '0 1px 3px rgb(0 0 0 / 0.3)' } }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './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 selection = inject(EpdfSelection); private readonly document = inject(EpdfDocument); constructor() { // Something selected on load: "Documents", the first word on the cover. effect(() => { const cover = this.document.pages()[0]?.ref; // [!doc-range welcome firstWord] if (cover) this.selection.select({ page: cover, start: 28, count: 9 }); // [!/doc-range] }); } }