import { ChangeDetectionStrategy, Component, inject, ViewEncapsulation } from '@angular/core'; import { 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 { EpdfOutline, withOutline } from '@embedpdf/angular/outline'; import type { OutlineItem } from '@embedpdf/angular/outline'; import { localEngine } from '@embedpdf/engine'; // [!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] // Bookmarks the reader adds: each one goes to the place in view when it's added. @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withOutline(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './bookmarks.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App { protected readonly outline = inject(EpdfOutline); protected add(pageIndex: number) { void this.outline.create({ title: `Page ${pageIndex + 1}` }, { select: true }); } protected follow(item: OutlineItem) { this.outline.select([item.ref]); this.outline.activate(item.ref); } protected isCurrent(item: OutlineItem): boolean { return item.ref.objectNumber === this.outline.current()?.objectNumber; } protected isSelected(item: OutlineItem): boolean { return item.ref.objectNumber === this.outline.selected()[0]?.objectNumber; } }