import { Viewer, DocumentGate, useDocument, useDocuments } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { localEngine } from '@embedpdf/engine'; import './open.css'; const engine = localEngine(); const plugins = [stagePlugin(), renderPlugin()]; const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', bytes: new Uint8Array(await response.arrayBuffer()) }; }; function Toolbar() { const documents = useDocuments(); const { id, name, status, pageCount } = useDocument(); // A file the user picks opens next to the welcome, and becomes the active document. const openFile = async (file: File) => { await documents.open({ kind: 'bytes', bytes: await file.arrayBuffer() }, { name: file.name }); }; return (
{id ? ( <> {name ?? 'Untitled'} {status === 'ready' ? ` · ${pageCount} pages` : ` · ${status}`} ) : ( 'No document open' )} {id ? ( ) : ( )}
); } // The gate's fallback: a document on its way, or none at all. function Empty() { const { id } = useDocument(); return (

{id ? 'Opening…' : 'No document is open. Open a PDF to see it here.'}

); } export default function App() { return ( }> {() => } ); }