import { ChangeDetectionStrategy, Component, effect, inject, untracked, ViewEncapsulation, } from '@angular/core'; import { EpdfDocumentGate, EpdfDocuments, EpdfDocumentScope, 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 { EpdfViewManager, withViewManager, type PaneInfo } from '@embedpdf/angular/view-manager'; import { localEngine } from '@embedpdf/engine'; const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) }; }; const article = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/article.pdf'); return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) }; }; @Component({ selector: 'demo-root', imports: [EpdfDocumentScope, EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [ { source: welcome, name: 'Guide' }, { source: article, name: 'Article' }, ], }, withStage(), withRender(), withViewManager(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './panes.css', encapsulation: ViewEncapsulation.None, template: `
@for (pane of views.panes(); track pane.id) {
@for (id of pane.documentIds; track id) { }
@if (pane.activeDocumentId; as documentId) { } @else {

No document in this pane.

}
}

Opening…

`, }) export class App { protected readonly views = inject(EpdfViewManager); private readonly documents = inject(EpdfDocuments); constructor() { // On load, both documents land in the first pane: put the second one beside it, once. const splitOnLoad = effect(() => { const panes = this.views.panes(); if (panes.length !== 1 || panes[0].documentIds.length !== 2) return; splitOnLoad.destroy(); untracked(() => this.views.splitPane(panes[0].documentIds[1])); }); } protected nameOf(id: string): string { return this.documents.documents().find((document) => document.id === id)?.name ?? id; } protected split(pane: PaneInfo) { if (pane.activeDocumentId) this.views.splitPane(pane.activeDocumentId, { from: pane.id }); } }