import { ChangeDetectionStrategy, Component, inject, input, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, 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 { 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', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // [!doc-source article] const article = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/article.pdf'); return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // The same component in both panes: each talks to the document its [epdfDocumentScope] names. @Component({ selector: 'demo-header', changeDetection: ChangeDetectionStrategy.OnPush, template: `
{{ document.name() }} {{ document.pageCount() }} pages {{ percent(stage().zoomLevel()) }}%
`, }) export class Header { readonly stage = input.required(); protected readonly document = inject(EpdfDocument); protected percent(zoomLevel: number): number { return Math.round(zoomLevel * 100); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentScope, EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, Header, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [ { source: welcome, name: 'Guide' }, { source: article, name: 'Article' }, ], }, withStage(), withRender(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './scope.css', encapsulation: ViewEncapsulation.None, template: `
@for (document of documents.documents(); track document.id) {
}

Opening…

`, }) export class App { protected readonly documents = inject(EpdfDocuments); }