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 { copySelection, EpdfSelection, EpdfSelectionClipboard, EpdfSelectionLayer, EpdfSelectionMenu, withSelection, } from '@embedpdf/angular/selection'; import { localEngine } from '@embedpdf/engine'; const PLACEMENTS = ['top', 'bottom', 'left', 'right'] as const; type Placement = (typeof PLACEMENTS)[number]; 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()) }; }; // What's in the menu is yours: here, copy and clear. @Component({ selector: 'demo-selection-actions', changeDetection: ChangeDetectionStrategy.OnPush, template: ` `, }) export class SelectionActions { protected readonly selection = inject(EpdfSelection); protected copy() { void copySelection(this.selection).catch(() => { // Show your product's clipboard error message here. }); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfSelectionMenu, EpdfSelectionClipboard, SelectionActions, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), withSelection(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './menu.css', encapsulation: ViewEncapsulation.None, template: `
@for (name of placements; track name) { }

Loading…

`, }) export class App { protected readonly placements = PLACEMENTS; protected readonly placement = signal('top'); private readonly selection = inject(EpdfSelection); private readonly document = inject(EpdfDocument); constructor() { // Something selected on load, so the menu shows: "Documents", the first word on the cover. effect(() => { const cover = this.document.pages()[0]?.ref; if (cover) this.selection.select({ page: cover, start: 28, count: 9 }); }); } }