import { ChangeDetectionStrategy, Component, computed, inject, ViewEncapsulation, } from '@angular/core'; import { EpdfDocument, EpdfDocumentGate, EpdfDocuments, provideEmbedPdf, saveFile, } 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 { EpdfInteraction, withInteraction } from '@embedpdf/angular/interaction'; import { EpdfAnnotationLayer, withAnnotation } from '@embedpdf/angular/annotation'; import { localEngine } from '@embedpdf/engine'; // [!doc-source report] const report = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/report.pdf'); return { kind: 'bytes', id: 'report', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] // The annotations are part of the document: the downloaded PDF has every one. @Component({ selector: 'demo-save-bar', changeDetection: ChangeDetectionStrategy.OnPush, template: `
{{ document.hasUnsavedChanges() ? 'Unsaved changes' : 'All saved' }}
`, }) export class SaveBar { private readonly documents = inject(EpdfDocuments); protected readonly interaction = inject(EpdfInteraction); protected readonly document = inject(EpdfDocument); protected readonly drawing = computed(() => this.interaction.activeToolId() === 'ink'); protected async download() { saveFile(await this.documents.download(), 'annotated.pdf'); } } @Component({ selector: 'demo-root', imports: [ EpdfDocumentGate, EpdfStage, EpdfPageTemplate, EpdfRenderLayer, EpdfSelectionLayer, EpdfAnnotationLayer, SaveBar, ], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: report }] }, withStage(), withRender(), withInteraction(), withSelection(), withAnnotation(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './download.css', encapsulation: ViewEncapsulation.None, template: `

Loading…

`, }) export class App {}