import { useState } 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 } from '@embedpdf/react/interaction'; import { FormLayer, formPlugin, toFieldRef, useForm } from '@embedpdf/react/form'; import type { FormCapability } from '@embedpdf/react/form'; import { localEngine } from '@embedpdf/engine'; import './fill.css'; const engine = localEngine(); const plugins = [stagePlugin(), renderPlugin(), interactionPlugin(), formPlugin()]; // [!doc-source forms] const forms = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/forms.pdf'); return { kind: 'bytes', id: 'forms', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // [!/doc-source] /** One field of each kind, with `setValue()` in the shape each one takes. */ async function fillIn(form: FormCapability) { await form.setValue(toFieldRef('name'), { value: 'Ada Lovelace' }); // text await form.setValue(toFieldRef('updates'), { checked: true }); // checkbox await form.setValue(toFieldRef('plan'), { value: 'yearly' }); // radio group: a button's value await form.setValue(toFieldRef('framework'), { value: 'React' }); // dropdown: an option's value return form.setValue(toFieldRef('topics'), { selectedValues: ['Forms', 'Signatures'] }); // list } function FillToolbar() { const form = useForm(); const [result, setResult] = useState(''); return (
{result && {result}}
); } export default function App() { return ( Loading…

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