googleapis / googleapis/google-cloud-node

empty content field in text anchor object when using DocumentAI's form processor

Open
#4,740 3 comments 3 reactions 1 assignee Claimed by @sofisl View on GitHub
priority: p2 type: bug
Dominant language
TypeScript
Stars
3.2k
Forks
712
Avg merge
2d 3h
Merged PRs (30d)
99

Description

I checked everywhere I could and see one Reddit thread on this same behavior (https://www.reddit.com/r/googlecloud/comments/16xwhzt/entities_from_gc_document_ai_always_have/)

#### Environment details

- which product (packages/*): Google Cloud Document AI Node.js + Typescript
- OS: Windows 10
- Node.js version: 16
- npm version: latest
- google-cloud-node version: latest ("@google-cloud/documentai": "^8.0.1")

### Problem description
Expected behavior: use DocumentAI's Form Processor to extract table data. It's expected that the `content` field in the various nodes of the document response object return a value (ie: `response[i].document?.pages[i].tables[i].headerRows[i].cells[i].layout?.textAnchor?.content` should return with the table cell's content.

Actual behavior: all `content` fields on any `textAnchor` object are a blank string (`""`)).

![image](https://github.com/googleapis/google-cloud-node/assets/13476732/54a7629e-30c0-41c4-9d39-ddf871181627)

#### Steps to reproduce

``` ts
import * as fs from 'fs';
import { DocumentProcessorServiceClient } from '@google-cloud/documentai';
import { google } from '@google-cloud/documentai/build/protos/protos';

// Set up the Google Cloud Document AI client
const client = new DocumentProcessorServiceClient();
const projectId = 'your-project';
const location = 'region';
const processorId = 'processor ID';

// read in file from local storage
const testPDF = fs.readFileSync("src/test.pdf");
const docProcessor = new DocumentProcessorServiceClient();

// Define the request object for processing the document
const request:google.cloud.documentai.v1.IProcessRequest = {
name: `projects/${projectId}/locations/${location}/processors/${processorId}`,
rawDocument: {
content: testPDF.toString('base64'),
mimeType: 'application/pdf',
}
};

// parse tables
function parseTables(response:Array):any{
var tables:any[] = [];
const pagei = 0;
const tablei = 0;
response[0].document?.pages?.forEach((page, index) => {
page.tables?.forEach((table, index) => {
table.headerRows?.forEach((row, index) => {
row.cells?.forEach((cell, index) => {
console.log(cell.layout?.textAnchor?.content);
});
});
table.bodyRows?.forEach((row, index) => {
row.cells?.forEach((cell, index) => {
console.log(cell.layout?.textAnchor?.content);
});
});
console.log(index);
});
});
}

function processDocument(){
docProcessor.processDocument(request).then(
data => {
parseTables(data);
console.log(data);
}).catch(function(error:any) {
console.log(error);
});

}
processDocument();
```

#### Additional information
It is clearly stated in the documentation that this content field should be filled for user convenience: https://cloud.google.com/document-ai/docs/reference/rest/v1/Document#TextAnchor
![image](https://github.com/googleapis/google-cloud-node/assets/13476732/c4340331-ba5b-4509-a170-02956ed514d1)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.