import { useState } from 'react'; 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 './identity.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()) }; }; const dana = { userId: 'u_381', displayName: 'Dana Smith' }; // What each role may do, as permissions. const roles = { reader: ['doc.open', 'doc.render', 'doc.text.select'], editor: [ 'doc.open', 'doc.render', 'doc.text.select', 'doc.text.copy', 'doc.download', 'doc.print', ], }; type Role = keyof typeof roles; function Toolbar({ role, onRoleChange }: { role: Role; onRoleChange: (role: Role) => void }) { const documents = useDocuments(); // Read the document too, so the checks are read again when it opens or closes. const { id } = useDocument(); // The role the open document was opened with: it keeps that one. const [openedAs, setOpenedAs] = useState(role); const openAgain = async () => { await documents.close(id); await documents.open(welcome, { name: 'welcome.pdf' }); setOpenedAs(role); }; return ( <>
Download Print

This document opened for a {openedAs}. {openedAs !== role && ( )}

); } export default function App() { const [role, setRole] = useState('reader'); return ( Opening…

}> {() => }
); }