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 } from '@embedpdf/react/interaction'; import { AnnotationLayer, annotationPlugin, useAnnotation, useAnnotationDefaults, useAnnotationEvent, } from '@embedpdf/react/annotation'; import { localEngine } from '@embedpdf/engine'; import './tool-defaults.css'; const engine = localEngine(); // The pen starts with what the reader picked last time: see RememberDefaults below. const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), annotationPlugin({ tools: [{ id: 'ink', defaults: JSON.parse(localStorage.getItem('tool:ink') ?? '{}') }], }), ]; 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()) }; }; const COLORS = ['#e5484d', '#1e90ff', '#30a46c', '#1a2748']; // The pen's color and width, for the strokes that follow. function PenStyle() { const annotation = useAnnotation(); const defaults = useAnnotationDefaults('ink'); return (
{COLORS.map((color) => (
annotation.tools.updateDefaults('ink', { color: event.target.value })} />
); } // Every change is kept for next time. function RememberDefaults() { useAnnotationEvent( (annotation) => annotation.tools.onDefaultsChanged, ({ toolId, defaults }) => { localStorage.setItem(`tool:${toolId}`, JSON.stringify(defaults)); }, ); return null; } // On load: the pen is active. function StartWithThePen() { const interaction = useInteraction(); useEffect(() => { interaction.activateTool('ink'); }, [interaction]); return null; } export default function App() { return ( Loading…

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