import { ChangeDetectionStrategy, Component, inject, input, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, EpdfDocumentGate, EpdfDocuments, 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'; 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()) }; }; const sketch = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/sketch.pdf'); return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) }; }; @Component({ selector: 'demo-tabs', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (document of documents.documents(); track document.id) {
}
`, }) export class Tabs { protected readonly documents = inject(EpdfDocuments); protected openFloorPlan() { void this.documents.open(sketch, { name: 'Floor plan' }); } } // The active tab: rename it, move it to the front, and zoom it. Each tab keeps its own zoom. @Component({ selector: 'demo-tab-tools', changeDetection: ChangeDetectionStrategy.OnPush, template: `
{{ percent(stage().zoomLevel()) }}%
`, }) export class TabTools { readonly stage = input.required(); protected readonly documents = inject(EpdfDocuments); protected readonly document = inject(EpdfDocument); protected percent(zoomLevel: number): number { return Math.round(zoomLevel * 100); } } @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, Tabs, TabTools], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [ { source: welcome, name: 'Guide' }, { source: article, name: 'Article' }, ], }, withStage(), withRender(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './tabs.css', encapsulation: ViewEncapsulation.None, template: `

Opening…

`, }) export class App {}