mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
44 lines
1.0 KiB
JavaScript
44 lines
1.0 KiB
JavaScript
import { useState } from "react";
|
|
import { Document, Page } from "react-pdf/dist/esm/entry.webpack5";
|
|
|
|
export default function PDFViewer(props) {
|
|
const [file, setFile] = useState("./sample.pdf");
|
|
const [numPages, setNumPages] = useState(null);
|
|
|
|
function onFileChange(event) {
|
|
setFile(event.target.files[0]);
|
|
}
|
|
|
|
function onDocumentLoadSuccess({ numPages: nextNumPages }) {
|
|
setNumPages(nextNumPages);
|
|
}
|
|
|
|
const options = {
|
|
cMapUrl: "cmaps/",
|
|
cMapPacked: true,
|
|
standardFontDataUrl: "standard_fonts/",
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className="">
|
|
<Document
|
|
file={props.pdfUrl}
|
|
onLoadSuccess={onDocumentLoadSuccess}
|
|
options={options}
|
|
>
|
|
{Array.from({ length: numPages }, (_, index) => (
|
|
<Page
|
|
className="mt-5"
|
|
key={`page_${index + 1}`}
|
|
pageNumber={index + 1}
|
|
renderAnnotationLayer={false}
|
|
renderTextLayer={false}
|
|
/>
|
|
))}
|
|
</Document>
|
|
</div>
|
|
</>
|
|
);
|
|
}
|