import { ChangeDetectionStrategy, Component, computed, effect, inject, 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 { EpdfInteraction, withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { EpdfMeasurement, withMeasurement } from '@embedpdf/angular/measurement'; import { cloudEngine } from '@cloudpdf/engine'; const sketch: OpenInput = { kind: 'grant', grant: 'shr_IyOgSdO4AmJqV4BoMv5V0nYU' }; const TOOLS = [ { id: 'pointer', label: 'Select' }, { id: 'distance', label: 'Distance' }, { id: 'perimeter', label: 'Perimeter' }, { id: 'area', label: 'Area' }, ]; @Component({ selector: 'demo-measure-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (tool of tools; track tool.id) { }
Scale {{ ratio() }}
`, }) export class MeasureToolbar { protected readonly interaction = inject(EpdfInteraction); private readonly measurement = inject(EpdfMeasurement); protected readonly tools = TOOLS; private readonly scale = this.measurement.scaleOf(0); // the floor plan's scale protected readonly ratio = computed(() => { const measure = this.scale().measure; return measure?.subtype === 'rectilinear' ? measure.ratio : '…'; }); private started = false; constructor() { // On load: the floor plan at 1:100, the building's width measured, and the distance tool on. effect(() => { if (!this.scale().ready || this.started) return; this.started = true; void this.measurement .setPreset(0, 'metric-100') .then(() => this.measurement.createMeasurement({ kind: 'distance', page: 0, points: [ { x: 62, y: 150 }, { x: 550, y: 150 }, ], }), ) .then(() => this.interaction.activateTool('distance')); }); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfAnnotationLayer, MeasureToolbar, ], providers: [ provideEmbedPdf( { engine: () => cloudEngine(), initialDocuments: [{ source: sketch }] }, withStage(), withRender(), withInteraction(), withAnnotation(), withMeasurement(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './basic.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}