MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / getText

Function getText

document-ai/process-document-ocr.js:147–157  ·  view source on GitHub ↗
(textAnchor, text)

Source from the content-addressed store, hash-verified

145
146 // Extract shards from the text field
147 const getText = (textAnchor, text) => {
148 if (!textAnchor.textSegments || textAnchor.textSegments.length === 0) {
149 return '';
150 }
151
152 // First shard in document doesn't have startIndex property
153 const startIndex = textAnchor.textSegments[0].startIndex || 0;
154 const endIndex = textAnchor.textSegments[0].endIndex;
155
156 return text.substring(startIndex, endIndex);
157 };
158
159 // [END documentai_process_ocr_document]
160 await processDocument();

Callers 4

printParagraphsFunction · 0.70
printBlocksFunction · 0.70
printLinesFunction · 0.70
printTokensFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected