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 { cloudEngine } from '@cloudpdf/engine';
const welcome: OpenInput = { kind: 'grant', grant: 'shr_gvpJcG1ULUMon19C0D1wODSY' };
// 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: () => cloudEngine(), initialDocuments: [{ source: welcome }] },
withRender(),
),
],
changeDetection: ChangeDetectionStrategy.OnPush,
styleUrl: './basic.css',
encapsulation: ViewEncapsulation.None,
template: `
Loading…
`,
})
export class App {}