mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
This commit is contained in:
@ -2,32 +2,37 @@ import { useState } from "react";
|
|||||||
import { Document, Page } from "react-pdf/dist/esm/entry.webpack5";
|
import { Document, Page } from "react-pdf/dist/esm/entry.webpack5";
|
||||||
|
|
||||||
export default function PDFViewer() {
|
export default function PDFViewer() {
|
||||||
|
const [file, setFile] = useState("./sample.pdf");
|
||||||
const [numPages, setNumPages] = useState(null);
|
const [numPages, setNumPages] = useState(null);
|
||||||
|
|
||||||
|
function onFileChange(event) {
|
||||||
|
setFile(event.target.files[0]);
|
||||||
|
}
|
||||||
|
|
||||||
function onDocumentLoadSuccess({ numPages: nextNumPages }) {
|
function onDocumentLoadSuccess({ numPages: nextNumPages }) {
|
||||||
setNumPages(nextNumPages);
|
setNumPages(nextNumPages);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Document
|
<div>
|
||||||
file="/sample.pdf"
|
<div>
|
||||||
onLoadSuccess={onDocumentLoadSuccess}
|
<label htmlFor="file">Load from file:</label>{" "}
|
||||||
onLoadError={(err) => {
|
<input onChange={onFileChange} type="file" />
|
||||||
console.error(err);
|
</div>
|
||||||
}}
|
<div>
|
||||||
onSourceError={(err) => {
|
<Document file={file} onLoadSuccess={onDocumentLoadSuccess}>
|
||||||
console.error(err);
|
{Array.from({ length: numPages }, (_, index) => (
|
||||||
}}
|
<Page
|
||||||
onLoadProgress={(err) => {
|
key={`page_${index + 1}`}
|
||||||
console.error(err);
|
pageNumber={index + 1}
|
||||||
}}
|
renderAnnotationLayer={false}
|
||||||
onPassword={(err) => {
|
renderTextLayer={false}
|
||||||
console.error(err);
|
/>
|
||||||
}}
|
))}
|
||||||
>
|
|
||||||
<Page pageNumber={1} />
|
|
||||||
</Document>
|
</Document>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user