import { ChangeDetectionStrategy, Component, computed, 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 { EpdfSelectionLayer, withSelection } from '@embedpdf/angular/selection'; import { EpdfAnnotation, EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { localEngine } from '@embedpdf/engine'; // [!doc-source article] const article = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/article.pdf'); return { kind: 'bytes', id: 'article', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] const TOOLS = [ { id: 'pointer', label: 'Select' }, { id: 'square', label: 'Rectangle' }, { id: 'ink', label: 'Pen' }, { id: 'highlight', label: 'Highlight' }, { id: 'note', label: 'Note' }, ]; @Component({ selector: 'demo-toolbar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
@for (tool of tools; track tool.id) { }
{{ count() }} {{ count() === 1 ? 'annotation' : 'annotations' }}
`, }) export class Toolbar { protected readonly tools = TOOLS; protected readonly interaction = inject(EpdfInteraction); private readonly annotations = inject(EpdfAnnotation).watch(); protected readonly count = computed(() => this.annotations().length); constructor() { // The rectangle tool is active on load: drag on the page to draw one. this.interaction.activateTool('square'); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, Toolbar, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: article }] }, withStage(), withRender(), withInteraction(), // The selection plugin lets the highlight tool mark the text you select. withSelection(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './draw.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}