| 61 | |
| 62 | // Extract shards from the text field |
| 63 | const getText = textAnchor => { |
| 64 | if (!textAnchor.textSegments || textAnchor.textSegments.length === 0) { |
| 65 | return ''; |
| 66 | } |
| 67 | |
| 68 | // First shard in document doesn't have startIndex property |
| 69 | const startIndex = textAnchor.textSegments[0].startIndex || 0; |
| 70 | const endIndex = textAnchor.textSegments[0].endIndex; |
| 71 | |
| 72 | return text.substring(startIndex, endIndex); |
| 73 | }; |
| 74 | |
| 75 | // Read the text recognition output from the processor |
| 76 | console.log('The document contains the following paragraphs:'); |