Files
sign/apps/web/components/editor/pdf-viewer.jsx

142 lines
5.1 KiB
React
Raw Normal View History

2023-02-08 14:20:55 +01:00
import { Fragment, useState } from "react";
2023-01-19 19:24:01 +01:00
import { Document, Page } from "react-pdf/dist/esm/entry.webpack5";
2023-02-13 16:11:53 +01:00
import Field from "./field";
2023-02-09 13:14:40 +01:00
import short from "short-uuid";
2023-01-19 19:24:01 +01:00
2023-01-23 16:32:06 +01:00
export default function PDFViewer(props) {
2023-01-24 19:10:24 +01:00
const [file, setFile] = useState("");
2023-01-19 19:24:01 +01:00
const [numPages, setNumPages] = useState(null);
2023-01-24 19:10:24 +01:00
const [loading, setLoading] = useState(true);
2023-02-09 15:48:26 +01:00
function onPositionChangedHandler(position, id) {
2023-02-13 18:04:44 +01:00
props.onPositionChanged(position, id);
2023-02-09 15:48:26 +01:00
}
2023-01-19 19:24:01 +01:00
2023-01-19 19:27:37 +01:00
function onFileChange(event) {
setFile(event.target.files[0]);
}
2023-01-19 19:24:01 +01:00
function onDocumentLoadSuccess({ numPages: nextNumPages }) {
setNumPages(nextNumPages);
}
2023-01-19 20:11:02 +01:00
const options = {
cMapUrl: "cmaps/",
cMapPacked: true,
standardFontDataUrl: "standard_fonts/",
};
2023-01-19 19:24:01 +01:00
return (
<>
2023-01-24 19:10:24 +01:00
<div hidden={loading}>
2023-02-13 18:04:44 +01:00
<div className="max-w-xs mt-6"></div>
2023-01-19 20:24:49 +01:00
<Document
2023-01-23 16:32:06 +01:00
file={props.pdfUrl}
2023-01-19 20:24:49 +01:00
onLoadSuccess={onDocumentLoadSuccess}
options={options}
>
{Array.from({ length: numPages }, (_, index) => (
2023-02-09 13:14:40 +01:00
<Fragment key={short.generate().toString()}>
2023-02-08 14:20:55 +01:00
<div
2023-02-09 13:14:40 +01:00
key={short.generate().toString()}
2023-02-08 14:20:55 +01:00
style={{
position: "relative",
background: "green",
}}
2023-02-13 18:13:04 +01:00
className="mx-auto w-fit"
2023-02-08 14:20:55 +01:00
>
2023-02-13 18:13:04 +01:00
<Page
className="mt-5"
key={`page_${index + 1}`}
pageNumber={index + 1}
renderAnnotationLayer={false}
renderTextLayer={false}
onLoadSuccess={() => setLoading(false)}
onRenderError={() => setLoading(false)}
></Page>
{props?.fields
.filter((item) => item.page === index)
.map((item) => (
<Field
key={item.id}
field={item}
className="absolute"
onPositionChanged={onPositionChangedHandler}
></Field>
))}
2023-02-08 14:20:55 +01:00
</div>
</Fragment>
2023-01-19 20:24:49 +01:00
))}
</Document>
</div>
2023-01-24 20:09:40 +01:00
<div className="mt-10 w-[600px]" hidden={!loading}>
2023-01-24 19:10:24 +01:00
<div className="ph-item">
<div className="ph-col-12">
<div className="ph-picture"></div>
<div className="ph-row">
<div className="ph-col-6 big"></div>
<div className="ph-col-4 empty big"></div>
<div className="ph-col-2 big"></div>
<div className="ph-col-4"></div>
<div className="ph-col-8 empty"></div>
<div className="ph-col-6"></div>
<div className="ph-col-6 empty"></div>
<div className="ph-col-12"></div>
</div>
2023-01-24 20:09:40 +01:00
<div className="ph-row">
<div className="ph-col-6 big"></div>
<div className="ph-col-4 empty big"></div>
<div className="ph-col-2 big"></div>
<div className="ph-col-4"></div>
<div className="ph-col-8 empty"></div>
<div className="ph-col-6"></div>
<div className="ph-col-6 empty"></div>
<div className="ph-col-12"></div>
</div>
<div className="ph-row">
<div className="ph-col-6 big"></div>
<div className="ph-col-4 empty big"></div>
<div className="ph-col-2 big"></div>
<div className="ph-col-4"></div>
<div className="ph-col-8 empty"></div>
<div className="ph-col-6"></div>
<div className="ph-col-6 empty"></div>
<div className="ph-col-12"></div>
</div>
<div className="ph-row">
<div className="ph-col-6 big"></div>
<div className="ph-col-4 empty big"></div>
<div className="ph-col-2 big"></div>
<div className="ph-col-4"></div>
<div className="ph-col-8 empty"></div>
<div className="ph-col-6"></div>
<div className="ph-col-6 empty"></div>
<div className="ph-col-12"></div>
</div>
<div className="ph-row">
<div className="ph-col-6 big"></div>
<div className="ph-col-4 empty big"></div>
<div className="ph-col-2 big"></div>
<div className="ph-col-4"></div>
<div className="ph-col-8 empty"></div>
<div className="ph-col-6"></div>
<div className="ph-col-6 empty"></div>
<div className="ph-col-12"></div>
</div>
<div className="ph-row">
<div className="ph-col-6 big"></div>
<div className="ph-col-4 empty big"></div>
<div className="ph-col-2 big"></div>
<div className="ph-col-4"></div>
<div className="ph-col-8 empty"></div>
<div className="ph-col-6"></div>
<div className="ph-col-6 empty"></div>
<div className="ph-col-12"></div>
</div>
2023-01-24 19:10:24 +01:00
</div>
</div>
</div>
2023-01-19 19:24:01 +01:00
</>
);
}