import { useEffect } from 'react'; import { Viewer, DocumentGate } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, StageToken, stagePlugin } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { commandsPlugin, standardCommands, useCommand, useCommands, useCommandsSettings, } from '@embedpdf/react/commands'; import type { CommandDefinition } from '@embedpdf/react/commands'; import { localEngine } from '@embedpdf/engine'; import './custom.css'; const engine = localEngine(); // A command of your own: pressed while the pages show two at a time. const twoPages: CommandDefinition = { id: 'layout:two-pages', label: 'Two pages', categories: ['layout'], active: ({ get }) => get(StageToken).getSettings().spread === 'odd', run: ({ get }) => { const stage = get(StageToken); stage.updateSettings({ spread: stage.getSettings().spread === 'odd' ? 'none' : 'odd' }); }, }; const plugins = [ stagePlugin(), renderPlugin(), commandsPlugin({ commands: [...standardCommands, twoPages] }), ]; // [!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] function CommandButton({ id }: { id: string }) { const command = useCommand(id); if (!command.visible) return null; return ( ); } // Turning a category off hides its commands wherever they appear. function CategorySwitch({ category, label }: { category: string; label: string }) { const commands = useCommands(); const off = useCommandsSettings((settings) => settings.disabledCategories.includes(category)); return ( ); } function Toolbar() { const commands = useCommands(); // Run from code: the document opens with its whole first page in view. useEffect(() => { void commands.execute('zoom:fit-page'); }, [commands]); return (
); } export default function App() { return ( Loading…

}> {() => }
); }