I am using Google Document A.I for recognition of different types of forms such as U.S Government forms, W2 Forms, W9 Forms, Invoice Forms, Receipt Forms.
And I am getting this error from Google Document A.I when I try to process the form:
Unable to find a document of type 'w2_', found 1 other document types
OR
Unable to find a document of type 'w9_', found 1 other document types
got this error when I tried to process a W2 Form PDF file, also getting this error on some other type of PDF.
Here's my code:
const download_pdf = (bucketName, fileName) => {
return new Promise(async (resolve, reject) => {
//console.log("finalGS URL", `gs://${bucketName}/${fileName}`, "bucket:", bucketName, "fileName: ", fileName)
const storage = new Storage()
const bucket = storage.bucket(bucketName)
const file = bucket.file(fileName)
try {
//download the file in memory
const res = await file.download()
let pdfBuffer = res?.flat()?.[0] || res?.[0]
if (pdfBuffer) {
resolve(pdfBuffer)
} else {
throw new Error(`Something went wrong when downloading file!`)
}
} catch (e) {
console.error("error When Downloading Fiile ", e)
reject(e)
}
})
}
const encodedImage = await download_pdf(bucket_name, file_name)
const request = {
name,
document: {
content: encodedImage,
mimeType: 'application/pdf',
}
};
// Recognizes text entities in the PDF document
const [result] = await client.processDocument(request);
document = result?.document;
At first, I thought something is wrong with my file, but then when I am uploading it directly to the google cloud platform It works there, but not when I try to process it from my code, and the error is not permanent it only happens randomly, sometimes it works and I get the recognized data but most of the time I am getting this error.
I have reviewed my code twice and it is according to google's document and I couldn't find any mistake.
Thank you in advance!.
PDF FILE: https://pdfhost.io/v/3~UcB6x0w_W9.pdf
UPDATE: It looks like that the problem is on google's side as of now I am getting this same error when uploading the file to Google Cloud Platform Document AI, still waiting for a response from google team.