forked from NotionX/react-notion-x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdf.tsx
21 lines (17 loc) · 756 Bytes
/
pdf.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import * as React from 'react'
import { Document, Page, pdfjs } from 'react-pdf'
// ensure pdfjs can find its worker script regardless of how react-notion-x is bundled
pdfjs.GlobalWorkerOptions.workerSrc = `//unpkg.com/pdfjs-dist@${pdfjs.version}/legacy/build/pdf.worker.min.mjs`
export function Pdf({ file, ...rest }: { file: string }) {
const [numPages, setNumPages] = React.useState<number>(0)
function onDocumentLoadSuccess({ numPages }: { numPages: number }) {
setNumPages(numPages)
}
return (
<Document file={file} onLoadSuccess={onDocumentLoadSuccess} {...rest}>
{Array.from(Array.from({ length: numPages }), (_, index) => (
<Page key={`page_${index + 1}`} pageNumber={index + 1} />
))}
</Document>
)
}