import { ChangeDetectionStrategy, Component, computed, effect, inject, input, ViewEncapsulation, } from '@angular/core'; import { EpdfDocumentGate, 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 { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotation, EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { EpdfStamp, withStamp } from '@embedpdf/angular/stamp'; import { loadDefaultLibrary } from '@embedpdf/default-stamps/library'; import { cloudEngine } from '@cloudpdf/engine'; import { localEngine } from '@embedpdf/engine'; const engine = cloudEngine(); const assetEngine = localEngine(); const approvals: OpenInput = { kind: 'grant', grant: 'shr_lu5Sb4r9PYjKrHS3qfNeUywM' }; // The middle of a Letter page, in page coordinates. const MIDDLE = { x: 306, y: 396 }; /** Next to ``: ``. */ @Component({ selector: 'demo-place-stamps', changeDetection: ChangeDetectionStrategy.OnPush, template: `
{{ stamps().length }} {{ stamps().length === 1 ? 'stamp' : 'stamps' }} in the document
`, }) export class PlaceStamps { readonly stage = input.required(); private readonly stamp = inject(EpdfStamp); private readonly annotation = inject(EpdfAnnotation); private readonly assets = this.stamp.assetsOf(); protected readonly approved = computed(() => this.assets().find((asset) => asset.name === 'Approved'), ); protected readonly draft = computed(() => this.assets().find((asset) => asset.name === 'Draft')); protected readonly stamps = this.annotation.watch({ subtype: 'stamp' }); private loaded = false; constructor() { // On load: the standard stamps, ready to place. effect(() => { if (this.annotation.status() !== 'ready' || this.loaded) return; this.loaded = true; void loadDefaultLibrary('en').then((bytes) => this.stamp.importLibrary(bytes)); }); } protected approve() { const approved = this.approved(); if (!approved) return; const page = this.stage().currentPageIndex(); void this.stamp.placeAsset(approved.id, { page, center: MIDDLE, select: true }); } protected draftEverywhere() { const draft = this.draft(); if (!draft) return; void this.stamp.placeAssetOnPages(draft.id, 'all', { center: MIDDLE, targetWidth: 320, rotation: -30, }); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, PlaceStamps, ], providers: [ provideEmbedPdf( { engine, initialDocuments: [{ source: approvals }] }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), withStamp({ assetEngine }), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './programmatic.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}