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 { EpdfInteraction, withInteraction } from '@embedpdf/angular/interaction'; import { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { EpdfAnnotation, EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { EpdfRedaction, withRedaction } from '@embedpdf/angular/redaction'; import { localEngine } from '@embedpdf/engine'; // [!doc-source welcome] 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()) }; }; // [!/doc-source] // The cover's subtitle, in page coordinates. const SUBTITLE = { x: 44, y: 318, width: 206, height: 50 }; /** Next to ``: ``. */ @Component({ selector: 'demo-redact-bar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
{{ marking() ? 'Select text, or drag over an area' : 'Click a mark to move it' }}
`, }) export class RedactBar { readonly stage = input.required(); protected readonly interaction = inject(EpdfInteraction); protected readonly redaction = inject(EpdfRedaction); private readonly annotation = inject(EpdfAnnotation); protected readonly marking = computed(() => this.interaction.activeToolId() === 'redact'); private started = false; constructor() { // On load: the cover's subtitle marked, and the redact tool on. effect(() => { if (this.annotation.status() !== 'ready' || this.started) return; this.started = true; const stage = this.stage(); void this.redaction.markArea(0, SUBTITLE).then(() => stage.reveal(0, { rect: SUBTITLE })); this.interaction.activateTool('redact'); }); } } // The selection plugin lets the redact tool mark the text you select. @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, RedactBar, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), withRedaction(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './basic.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}