import { ChangeDetectionStrategy, Component, inject, signal, ViewEncapsulation, } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; 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 { withInteraction } from '@embedpdf/angular/interaction'; import { withActions, withActionsUi } from '@embedpdf/angular/actions'; import { EpdfLink, EpdfLinkLayer, withLink } from '@embedpdf/angular/link'; import type { Link } from '@embedpdf/angular/link'; import { localEngine } from '@embedpdf/engine'; // [!doc-source links] const links = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/links.pdf'); return { kind: 'bytes', id: 'links', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // The first page's links, read from the plugin, each with a button that follows it. @Component({ selector: 'aside[demoLinkList]', changeDetection: ChangeDetectionStrategy.OnPush, host: { class: 'panel' }, template: `

Links on page 1

activated$ {{ last() ?? 'not yet' }}

`, }) export class LinkList { protected readonly link = inject(EpdfLink); protected readonly items = signal([]); protected readonly last = signal(null); protected readonly round = Math.round; constructor() { void this.link.ensureLoaded(0).then(() => this.items.set(this.link.listLinks(0))); // Every way of following a link ends up here: a click, a key, or code. this.link.activated$ .pipe(takeUntilDestroyed()) .subscribe(({ target, activation }) => this.last.set(`${target.kind} → ${activation.status}`), ); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfLinkLayer, LinkList, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: links }] }, withStage(), withRender(), withInteraction(), // The actions plugin runs a link that names a viewer command, such as the footer's Next. withActions(), // The browser's way to open a website, once for the viewer. withActionsUi(), withLink(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './list.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}