I am currently using vue.js and nuxt.js to extract text from both PDF and image files, however, I am encountering some issues as it doesn't seem to be working properly. This is the first time I'm reaching out for help on this matter, so please feel free to ask if you need more information. I've been stuck trying to resolve this error for the past 4 days and really could use some assistance.
I have been tirelessly attempting to fix this error. All I want is to successfully debug and resolve the issue.
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);
}