()
| 27 | }; |
| 28 | } |
| 29 | const DebugPdf = () => { |
| 30 | const { t } = useTranslation(); |
| 31 | const { width } = useWindowSize(); |
| 32 | const [pdf, setPdf] = useState(""); |
| 33 | const [isModal, setIsModal] = useState(true); |
| 34 | const [allPages, setAllPages] = useState(null); |
| 35 | const [pageNumber, setPageNumber] = useState(1); |
| 36 | const [pdfLoadFail, setPdfLoadFail] = useState({ |
| 37 | status: false, |
| 38 | type: "load" |
| 39 | }); |
| 40 | const [pdfDetails, setPdfDetails] = useState({ |
| 41 | name: "", |
| 42 | pdftype: "", |
| 43 | totalPages: "", |
| 44 | currentPage: 1, |
| 45 | x: 0, |
| 46 | y: 0, |
| 47 | base64: "" |
| 48 | }); |
| 49 | const [hoverCoordinates, setHoverCoordinates] = useState({ x: 0, y: 0 }); |
| 50 | const [pdfDimension, setPdfDimension] = useState({ width: 0, height: 0 }); |
| 51 | const [annotations, setAnnotations] = useState([]); |
| 52 | const [newAnnotation, setNewAnnotation] = useState([]); |
| 53 | const [copied, setCopied] = useState(false); |
| 54 | |
| 55 | useEffect(() => { |
| 56 | if (pdf && pdf.name) { |
| 57 | const fetchPdfMetadata = async () => { |
| 58 | try { |
| 59 | const pdfDataURL = URL.createObjectURL(pdf); // Convert File to data URL |
| 60 | // console.log("pdfDataURL ", pdfDataURL); |
| 61 | const pdfInfo = await pdfjs.getDocument({ url: pdfDataURL }).promise; |
| 62 | const pdfType = await inferPdfType(pdfInfo); |
| 63 | setPdfDetails((prevDetails) => ({ |
| 64 | ...prevDetails, |
| 65 | pdftype: pdfType |
| 66 | })); |
| 67 | } catch (error) { |
| 68 | console.error("Error fetching PDF metadata:", error); |
| 69 | } |
| 70 | }; |
| 71 | |
| 72 | fetchPdfMetadata(); |
| 73 | } |
| 74 | }, [pdf]); |
| 75 | |
| 76 | const inferPdfType = async (pdf) => { |
| 77 | try { |
| 78 | const firstPage = await pdf.getPage(pdf?.numPages > 1 ? 2 : 1); |
| 79 | const scale = 1; |
| 80 | const { width, height } = firstPage.getViewport({ scale }); |
| 81 | setPdfDimension({ width: width, height: height }); |
| 82 | |
| 83 | // Assuming a standard DPI of 72, you can adjust this value if needed |
| 84 | const dpi = 72; |
| 85 | |
| 86 | const widthInInches = width / dpi; |
nothing calls this directly
no test coverage detected