import { ChangeDetectionStrategy, Component, computed, inject, signal, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime'; import type { OpenInput } from '@embedpdf/angular/runtime'; import { EpdfPageView } from '@embedpdf/angular/page-view'; 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', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // A card that shows one page, like a preview next to a search result or a comment. @Component({ selector: 'demo-page-card', imports: [EpdfPageView, EpdfRenderLayer], changeDetection: ChangeDetectionStrategy.OnPush, template: `
Page {{ page()?.label ?? index() + 1 }} @if (page(); as page) { {{ round(page.size.width) }} × {{ round(page.size.height) }} points }
`, }) export class PageCard { protected readonly pages = inject(EpdfDocument).pages; protected readonly index = signal(0); protected readonly page = computed(() => this.pages()[this.index()]); protected readonly round = Math.round; } // No Stage: a page on its own needs only the render plugin. @Component({ selector: 'demo-root', imports: [EpdfDocumentGate, PageCard], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withRender(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './basic.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}