Error type: worker.load is not a function
P粉937769356
P粉937769356 2023-09-01 18:33:44
0
1
438
<p>When I want to extract text from PDF or image files, I use vue.js and nuxt.js. But doesn't seem to work. I do not know why. This is my first time asking, if you need more information please feel free to ask me. I was stuck with this error for 4 days T^T. I really need help. </p> <p>I tried to fix this error. I just want to fix the bug. </p> <p> <pre class="brush:js;toolbar:false;">async parseFile() { if (this.uploadedFile) { const fileType = this.getFileType(this.uploadedFile.name); if (fileType === "image") { const worker = createWorker(); await worker.load(); await worker.loadLanguage("eng"); await worker.initialize("eng"); const { data: { text }, } = await worker.recognize(this.uploadedFile); console.log(text); await worker.terminate(); } else if (fileType === "pdf") { const fileReader = new FileReader(); fileReader.onload = async () => { const typedArray = new Uint8Array(fileReader.result); const pdf = await pdfjsLib.getDocument(typedArray).promise; const numPages = pdf.numPages; let pdfText = ""; for (let i = 1; i <= numPages; i ) { const page = await pdf.getPage(i); const content = await page.getTextContent(); const pageText = content.items.map((item) => item.str).join(" "); pdfText = pageText "\n"; } console.log(pdfText); }; fileReader.readAsArrayBuffer(this.uploadedFile); }</pre> </p>
P粉937769356
P粉937769356

reply all(1)
P粉022140576

Just a suggestion, Check whether the createWorker() function is not imported correctly, or whether there is a problem with the library you are using. Also check to see if the necessary dependencies are installed

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!