import { ChangeDetectionStrategy, Component, inject, ViewEncapsulation } from '@angular/core'; import { EpdfDocumentGate, provideEmbedPdf } from '@embedpdf/angular/runtime'; import type { DocumentMetadata, OpenInput } from '@embedpdf/angular/runtime'; import { EpdfMetadata, withMetadata } from '@embedpdf/angular/metadata'; 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] const FIELDS = [ ['title', 'Title'], ['author', 'Author'], ['subject', 'Subject'], ['keywords', 'Keywords'], ['creator', 'Made in'], ['producer', 'Turned into a PDF by'], ['createdAt', 'Created'], ['modifiedAt', 'Last changed'], ['trapped', 'Trapped'], ] as const; // Dates are ISO strings: show them in the reader's own format. const DATES: ReadonlySet = new Set(['createdAt', 'modifiedAt']); const show = (field: string, value: string | null) => { if (value === null) return null; return DATES.has(field) ? new Date(value).toLocaleString() : value; }; // The document's properties, the way a "Document properties" dialog shows them. @Component({ selector: 'demo-root', imports: [EpdfDocumentGate], providers: [ provideEmbedPdf( { engine: () => localEngine(), initialDocuments: [{ source: welcome }] }, withMetadata(), ), ], changeDetection: ChangeDetectionStrategy.OnPush, styleUrl: './properties.css', encapsulation: ViewEncapsulation.None, template: `

Document properties

{{ metadata.status() }}
@for (entry of fields; track entry[0]) { @let value = valueOf(entry[0], metadata.fields());
{{ entry[1] }}
{{ value ?? 'not set' }}
}

Loading…

`, }) export class App { protected readonly metadata = inject(EpdfMetadata); protected readonly fields = FIELDS; protected valueOf(field: (typeof FIELDS)[number][0], metadata: DocumentMetadata | null) { return metadata ? show(field, metadata[field]) : null; } }