import { useEffect, useRef } from 'react'; import { Viewer, DocumentGate } from '@embedpdf/react/runtime'; import type { OpenInput } from '@embedpdf/react/runtime'; import { Stage, stagePlugin, useStageState } from '@embedpdf/react/stage'; import { RenderLayer, renderPlugin } from '@embedpdf/react/render'; import { SelectionLayer, selectionPlugin } from '@embedpdf/react/selection'; import { interactionPlugin } from '@embedpdf/react/interaction'; import { AnnotationLayer, annotationPlugin, useAnnotationList, useAnnotationState, } from '@embedpdf/react/annotation'; import { stampPlugin, useStamp, useStampAssets } from '@embedpdf/react/stamp'; import { loadDefaultLibrary } from '@embedpdf/default-stamps/library'; import { localEngine } from '@embedpdf/engine'; import './programmatic.css'; const engine = localEngine(); const assetEngine = engine; // stamp libraries are PDFs; they open here too const plugins = [ stagePlugin(), renderPlugin(), interactionPlugin(), selectionPlugin(), annotationPlugin(), stampPlugin({ assetEngine }), ]; const approvals = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/approvals.pdf'); return { kind: 'bytes', id: 'approvals', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // The middle of a Letter page, in page coordinates. const MIDDLE = { x: 306, y: 396 }; function PlaceStamps() { const stamp = useStamp(); const assets = useStampAssets(); const ready = useAnnotationState((state) => state.status === 'ready'); const currentPage = useStageState((state) => state.currentPageIndex); const stamps = useAnnotationList({ subtype: 'stamp' }); const loaded = useRef(false); const approved = assets.find((asset) => asset.name === 'Approved'); const draft = assets.find((asset) => asset.name === 'Draft'); // On load: the standard stamps, ready to place. useEffect(() => { if (!ready || loaded.current) return; loaded.current = true; void loadDefaultLibrary('en').then((bytes) => stamp.importLibrary(bytes)); }, [stamp, ready]); return (
{stamps.length} {stamps.length === 1 ? 'stamp' : 'stamps'} in the document
); } export default function App() { return ( Loading…

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