如何使用 aws textract 服务和 .net 从文档 (PDF/Image) 导出 CSV 格式的 table

How to export a table in CSV using aws textract service and .net from a document (PDF/Image)

我尝试使用 C#/.NET 从 AWS textract 服务中使用 DetectDocument(异步)从 PDF 文件中提取表格和数据。

我成功提取了数据,但无法弄清楚如何使用 AnalyzeDocument 提取 PDF 中的表格并导出为 CSV 文件。

阅读 AWS 文档,发现 CSV 提取是在 Python 而不是在 .NET 中。 参考 link:- https://docs.aws.amazon.com/textract/latest/dg/examples-export-table-csv.html

尝试查看 Python 代码并为 .NET 复制但未成功。

我们可以使用这段代码,遍历由 textract 的 GetDocumentTextAnalysis() 返回的块中的关系,并获取所有子节点 linked。

var relationships = block.Relationships;
    if(relationships != null && relationships.Count > 0) {
        relationships.ForEach(r => {
            if(r.Type == "CHILD") {
                r.Ids.ForEach(id => {
                    var cell = new Cell(blocks.Find(b => b.Id == id), blocks);
                    if(cell.RowIndex > ri) {
                        this.Rows.Add(row);
                        row = new Row();
                        ri = cell.RowIndex;
                    }
                    row.Cells.Add(cell);
                });
                if(row != null && row.Cells.Count > 0)
                    this.Rows.Add(row);
            }
        });
    }

供参考 - 请参考底部的 link 代码:-

https://github.com/aws-samples/amazon-textract-code-samples/blob/master/src-csharp/TextractExtensions/Table.cs