react-pdf-highlighter
react-pdf-highlighter copied to clipboard
How to get the loading status?
I want to do something after the PDF loaded successfully. Anyway to get the loading status? One more thing, when I try to use document.querySelectorAll('span'), it seems that I can only get the spans in first page and rest pages are null. What's the reason and how can I make them render at the same time?
Yeah, it is not straightforward. You can create a local component and put it under <PdfLoader> and fire a callback as soon as you receive pdfDocument.
I'll also accept a PR with the loading callback status for ./packages/react-pdf-highlighter/src/components/PdfLoader.js.
The rendering is done by PDF.js and it is done in a lazy way to have good performance on large files.
I had success with this:
const [node, setNode] = useState(null)
const onRefChange = useCallback(n => {
if (n)
setNode(true)
}, [])
// useEffect with dependency [node]
...
<PdfHighlighter
scrollRef={scrollTo => {
scrollViewerTo.current = scrollTo
onRefChange(scrollTo)
}}
...
您好 您的邮件已收到我会尽快处理!