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 { AnnotationLayer, annotationPlugin } from '@embedpdf/react/annotation'; import { localEngine } from '@embedpdf/engine'; import './click-create.css'; const engine = localEngine(); // What one click makes: a 120 × 80 rectangle, an arrow pointing down at the click, and no circle. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin({ tools: [ { id: 'square', clickCreate: { width: 120, height: 80 } }, { id: 'arrow', extends: 'line', defaults: { lineEndings: { start: 'none', end: 'closed-arrow' } }, clickCreate: { length: 80, rotation: 90, anchor: 'end' }, }, { id: 'circle', clickCreate: false }, // drag only ], }), ]; // [!doc-source sketch] const sketch = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/sketch.pdf'); return { kind: 'bytes', id: 'sketch', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] const TOOLS = [ { id: 'square', label: 'Rectangle', hint: 'A click makes 120 × 80 points' }, { id: 'arrow', label: 'Arrow', hint: 'A click points an arrow down at it' }, { id: 'circle', label: 'Circle', hint: 'Drag only: a click does nothing' }, ]; function Toolbar() { const interaction = useInteraction(); const { activeToolId } = useInteractionState(); const active = TOOLS.find((tool) => tool.id === activeToolId); // The rectangle tool is active on load: click the page. useEffect(() => { interaction.activateTool('square'); }, [interaction]); return (
{TOOLS.map((tool) => ( ))}

{active?.hint ?? 'Pick a tool, then click the page'}

); } export default function App() { return ( Loading…

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