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 { SearchLayer, searchPlugin, useSearch, useSearchState } from '@embedpdf/react/search'; import { localEngine } from '@embedpdf/engine'; import './click-match.css'; const engine = localEngine(); const plugins = [stagePlugin(), renderPlugin(), searchPlugin()]; const welcome = async (): Promise => { const response = await fetch('https://www.embedpdf.com/pdfs/welcome.pdf'); return { kind: 'bytes', id: 'welcome', bytes: new Uint8Array(await response.arrayBuffer()) }; }; // Which match is the active one: the first on load, then the one you click. function ActiveMatch() { const search = useSearch(); const { hitCount, activeHitIndex } = useSearchState(); useEffect(() => { void search.search({ text: 'PDF' }); }, [search]); return (
{hitCount > 0 ? `Match ${activeHitIndex + 1} of ${hitCount}` : 'Searching…'} Click a highlighted match to make it the active one.
); } function Pages() { const search = useSearch(); return ( {() => ( <> search.goToHit(hit)} /> )} ); } export default function App() { return ( Loading…

}>
); }