ocr-document-classification
Advanced tools
Comparing version 1.2.11 to 1.2.12
@@ -10,3 +10,4 @@ // src/functions.ts | ||
try { | ||
const doc = await pdfjsLib.getDocument(pdfPath).promise; | ||
const loadingTask = pdfjsLib.getDocument(pdfPath); | ||
const doc = await loadingTask.promise; | ||
const page = await doc.getPage(1); | ||
@@ -16,2 +17,5 @@ const viewport = page.getViewport({ scale: 1.5 }); | ||
const context = canvas.getContext("2d"); | ||
if (!context) { | ||
throw new Error("Failed to get canvas context"); | ||
} | ||
canvas.height = viewport.height; | ||
@@ -24,4 +28,11 @@ canvas.width = viewport.width; | ||
await page.render(renderContext).promise; | ||
const buffer = canvas.toDataURL("image/png"); | ||
return buffer; | ||
return new Promise((resolve, reject) => { | ||
canvas.toBlob((blob) => { | ||
if (blob) { | ||
resolve(blob); | ||
} else { | ||
reject(new Error("Failed to convert canvas to blob")); | ||
} | ||
}, "image/png"); | ||
}); | ||
} catch (error) { | ||
@@ -70,5 +81,8 @@ console.error("Error processing PDF:", error); | ||
}; | ||
let blobToRead; | ||
if (file.type === "application/pdf") { | ||
const pdfPath = URL.createObjectURL(file); | ||
file = await convert(pdfPath); | ||
blobToRead = await convert(pdfPath); | ||
} else { | ||
blobToRead = file; | ||
} | ||
@@ -115,3 +129,3 @@ let progress = 0; | ||
}; | ||
reader.readAsDataURL(file); | ||
reader.readAsDataURL(blobToRead); | ||
}); | ||
@@ -118,0 +132,0 @@ } |
{ | ||
"name": "ocr-document-classification", | ||
"version": "1.2.11", | ||
"version": "1.2.12", | ||
"description": "Document classification using tesseract.js and string-similarity-js.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.cjs", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32520
323