22import React , { useRef , useState , useEffect } from 'react' ;
33import { loadOpenCv } from './components/LoadOpenCV' ;
44
5- const PdfJsViewer = ( { fileUrl } ) => {
5+ const PdfJsViewer = ( { fileUrl } : { fileUrl : string } ) => {
66 const canvasRef = useRef ( null ) ;
77 const [ numPages , setNumPages ] = useState ( 0 ) ;
88 const [ pageNumber , setPageNumber ] = useState ( 1 ) ;
@@ -22,13 +22,16 @@ const PdfJsViewer = ({ fileUrl }) => {
2222 }
2323 main ( ) ;
2424 } , [ fileUrl ] ) ;
25- const handleFileChange = async ( e ) => {
25+ const handleFileChange = async ( e : any ) => {
2626 const file = e . target . files [ 0 ] ;
2727 if ( file && file . type === 'application/pdf' ) {
2828 const reader = new FileReader ( ) ;
2929 reader . onload = async function ( ) {
30+ // @ts -expect-error
3031 const typedArray = new Uint8Array ( reader . result ) ;
32+ // @ts -expect-error
3133 const loadingTask = pdfjsLib . getDocument ( { data : typedArray } ) ;
34+ // @ts -expect-error
3235 loadingTask . promise . then ( pdf => {
3336 pdfRef . current = pdf ;
3437 setNumPages ( pdf . numPages ) ;
@@ -41,7 +44,9 @@ const PdfJsViewer = ({ fileUrl }) => {
4144 alert ( 'Please upload a valid PDF file.' ) ;
4245 }
4346 } ;
47+ // @ts -expect-error
4448 const detectQRCode = ( canvas ) => {
49+ // @ts -expect-error
4550 const cv = window . cv
4651 let src = cv . imread ( canvas ) ;
4752 let qrDecoder = new cv . QRCodeDetector ( ) ;
@@ -81,13 +86,13 @@ const PdfJsViewer = ({ fileUrl }) => {
8186 const fontScale = 0.9 ;
8287 const color = new cv . Scalar ( 0 , 0 , 0 , 255 ) ;
8388 const thickness = 2 ;
84- function estimateTextSize ( text , thickness ) {
89+ function estimateTextSize ( text : string , thickness : number ) {
8590 const approxWidth = text . length * 16 ;
8691 const approxHeight = 20 + thickness ;
8792 return { width : approxWidth , height : approxHeight } ;
8893 }
8994
90- const textSize = estimateTextSize ( customText , fontScale , thickness ) ;
95+ const textSize = estimateTextSize ( customText , thickness ) ;
9196 const textWidth = textSize . width ;
9297 const textHeight = textSize . height ;
9398
@@ -120,14 +125,17 @@ const PdfJsViewer = ({ fileUrl }) => {
120125 straightQRCodes . delete ( ) ;
121126 }
122127 } ;
123-
128+ // @ts -expect-error
124129 const renderPage = async ( pdf , num ) => {
125130 const page = await pdf
126131 . getPage ( num ) ;
127132 const viewport = page . getViewport ( { scale : 1.5 } ) ;
128133 const canvas = canvasRef . current ;
134+ // @ts -expect-error
129135 const context = canvas . getContext ( '2d' ) ;
136+ // @ts -expect-error
130137 canvas . height = viewport . height ;
138+ // @ts -expect-error
131139 canvas . width = viewport . width ;
132140 const renderContext = {
133141 canvasContext : context ,
0 commit comments