import { useEffect } from 'react'; import { Viewer, DocumentGate } 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 { interactionPlugin, useInteraction, useInteractionState, } from '@embedpdf/react/interaction'; import { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection'; import { AnnotationLayer, annotationPlugin, useAnnotationList } from '@embedpdf/react/annotation'; import { cloudEngine } from '@cloudpdf/engine'; import './draw.css'; const engine = cloudEngine(); // The selection plugin lets the highlight tool mark the text you select. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin(), annotationPlugin(), ]; const article: OpenInput = { kind: 'grant', grant: 'shr_v09cJHOmj3C8vrfUlZNTDyqX' }; const TOOLS = [ { id: 'pointer', label: 'Select' }, { id: 'square', label: 'Rectangle' }, { id: 'ink', label: 'Pen' }, { id: 'highlight', label: 'Highlight' }, { id: 'note', label: 'Note' }, ]; function Toolbar() { const interaction = useInteraction(); const { activeToolId } = useInteractionState(); const count = useAnnotationList().length; // The rectangle tool is active on load: drag on the page to draw one. useEffect(() => { interaction.activateTool('square'); }, [interaction]); return (
{TOOLS.map((tool) => ( ))}
{count} {count === 1 ? 'annotation' : 'annotations'}
); } export default function App() { return ( Loading…

}> {() => ( <> )}
); }