import { Viewer, DocumentGate } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { metadataPlugin, useMetadataState } from '@embedpdf/react/metadata'; import { localEngine } from '@embedpdf/engine'; import './properties.css'; const engine = localEngine(); const plugins = [metadataPlugin()]; 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()) }; }; 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. function Properties() { const { metadata, status } = useMetadataState(); return (

Document properties

{status}
{FIELDS.map(([field, label]) => { const value = metadata ? show(field, metadata[field]) : null; return (
{label}
{value ?? 'not set'}
); })}
); } export default function App() { return ( Loading…

}>
); }