| 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; |
| 87 | const heightInInches = height / dpi; |
| 88 | |
| 89 | const isA1 = widthInInches > 23.39 && heightInInches > 16.54; |
| 90 | const isA2 = widthInInches > 16.54 && heightInInches > 11.69; |
| 91 | const isA3 = widthInInches > 11.69 && heightInInches > 8.27; |
| 92 | const isA4 = widthInInches > 8.27 && heightInInches > 5.83; |
| 93 | const isLegal = widthInInches > 8.5 && heightInInches > 14; |
| 94 | const isLetter = widthInInches > 8.5 && heightInInches > 11; |
| 95 | const isLedger = widthInInches > 11 && heightInInches > 17; |
| 96 | |
| 97 | if (isA1) return "A1"; |
| 98 | if (isA2) return "A2"; |
| 99 | if (isA3) return "A3"; |
| 100 | if (isA4) return "A4"; |
| 101 | if (isLegal) return "Legal"; |
| 102 | if (isLetter) return "Letter"; |
| 103 | if (isLedger) return "Ledger"; |
| 104 | |
| 105 | return "Unknown"; |
| 106 | } catch (error) { |
| 107 | console.error("Error getting page dimensions:", error); |
| 108 | return "Unknown"; |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | const handleSubmit = (e) => { |
| 113 | e.preventDefault(); |