1- "use client"
2- import React , { useRef , useState , useEffect } from ' react' ;
3- import { loadOpenCv } from ' ./components/LoadOpenCV' ;
1+ "use client" ;
2+ import React , { useRef , useState , useEffect } from " react" ;
3+ import { loadOpenCv } from " ./components/LoadOpenCV" ;
44
55const PdfJsViewer = ( { fileUrl } : { fileUrl : string } ) => {
66 const canvasRef = useRef ( null ) ;
@@ -13,18 +13,18 @@ const PdfJsViewer = ({ fileUrl }: { fileUrl: string }) => {
1313
1414 useEffect ( ( ) => {
1515 const main = async ( ) => {
16- const pdfjs = ( await import ( "pdfjs-dist" ) )
16+ const pdfjs = ( await import ( "pdfjs-dist" ) ) ;
1717 pdfjs . GlobalWorkerOptions . workerSrc = new URL (
1818 "pdfjs-dist/build/pdf.worker.min.mjs" ,
1919 import . meta. url
20- ) . toString ( )
20+ ) . toString ( ) ;
2121 loadOpenCv ( ( ) => { setCVRead ( true ) ; } ) ;
22- }
22+ } ;
2323 main ( ) ;
2424 } , [ fileUrl ] ) ;
2525 const handleFileChange = async ( e : any ) => {
2626 const file = e . target . files [ 0 ] ;
27- if ( file && file . type === ' application/pdf' ) {
27+ if ( file && file . type === " application/pdf" ) {
2828 const reader = new FileReader ( ) ;
2929 reader . onload = async function ( ) {
3030// @ts -expect-error
@@ -37,26 +37,26 @@ const PdfJsViewer = ({ fileUrl }: { fileUrl: string }) => {
3737 setNumPages ( pdf . numPages ) ;
3838 setPdfDoc ( pdf ) ;
3939 renderPage ( pdf , pageNumber ) ;
40- } )
40+ } ) ;
4141 } ;
4242 reader . readAsArrayBuffer ( file ) ;
4343 } else {
44- alert ( ' Please upload a valid PDF file.' ) ;
44+ alert ( " Please upload a valid PDF file." ) ;
4545 }
4646 } ;
4747// @ts -expect-error
4848 const detectQRCode = ( canvas ) => {
4949// @ts -expect-error
50- const cv = window . cv
51- let src = cv . imread ( canvas ) ;
52- let qrDecoder = new cv . QRCodeDetector ( ) ;
53- let decodedStrings = new cv . StringVector ( ) ;
54- let points = new cv . Mat ( ) ;
55- let straightQRCodes = new cv . MatVector ( ) ;
56- let result = [ ] ;
50+ const cv = window . cv ;
51+ const src = cv . imread ( canvas ) ;
52+ const qrDecoder = new cv . QRCodeDetector ( ) ;
53+ const decodedStrings = new cv . StringVector ( ) ;
54+ const points = new cv . Mat ( ) ;
55+ const straightQRCodes = new cv . MatVector ( ) ;
56+ const result = [ ] ;
5757 try {
5858 const success = qrDecoder . detectAndDecodeMulti ( src , decodedStrings , points , straightQRCodes ) ;
59- console . log ( success )
59+ console . log ( success ) ;
6060 if ( success ) {
6161 for ( let i = 0 ; i < decodedStrings . size ( ) ; i ++ ) {
6262 const decodedText = decodedStrings . get ( i ) ;
@@ -116,7 +116,7 @@ const PdfJsViewer = ({ fileUrl }: { fileUrl: string }) => {
116116 setQrValue ( [ ...qrValue , "No QR code found." ] ) ;
117117 }
118118 } catch ( err ) {
119- console . error ( ' QR detection error:' , err ) ;
119+ console . error ( " QR detection error:" , err ) ;
120120 setQrValue ( [ ...qrValue , "Error detecting QR code." ] ) ;
121121 } finally {
122122 src . delete ( ) ;
@@ -132,7 +132,7 @@ const PdfJsViewer = ({ fileUrl }: { fileUrl: string }) => {
132132 const viewport = page . getViewport ( { scale : 1.5 } ) ;
133133 const canvas = canvasRef . current ;
134134// @ts -expect-error
135- const context = canvas . getContext ( '2d' ) ;
135+ const context = canvas . getContext ( "2d" ) ;
136136// @ts -expect-error
137137 canvas . height = viewport . height ;
138138// @ts -expect-error
0 commit comments