【问题标题】:How to export a table in CSV using aws textract service and .net from a document (PDF/Image)如何使用 aws textract 服务和 .net 从文档中导出 CSV 表(PDF/图像)
【发布时间】:2019-09-03 07:18:57
【问题描述】:

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

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

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

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

【问题讨论】:

标签: .net amazon-web-services amazon-textract


【解决方案1】:

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

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);
            }
        });
    }

供参考 - 请参阅底部的代码链接:-

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-09
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多