Document AI get table values

Herson Ian Moneda 40 Reputation points
2025-04-19T15:55:07.2766667+00:00

Hello,

I have a field table in my model. How can I get their values? I can get the values of the string fields just fineUser's image

I have this code but it only gives the value of string fields. The Items field is blank. Am I missing something?

User's image

This is the code I am using Azure.AI.FormRecognizer.DocumentAnalysis

        // Initialize client

        var client = new DocumentAnalysisClient(

            new Uri(AzureEndpoint),

            new AzureKeyCredential(AzureKey)

        );

        // Your custom model ID

        string modelId = DocumentModel;

        // Load local file into stream

        var filePath = @"D:\Invoices\Test1.pdf";

        var stream = File.OpenRead(filePath);

        AnalyzeDocumentOperation operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, modelId, stream);

        AnalyzeResult result = operation.Value;

        // Use the result here

        Console.WriteLine($"Document was analyzed with model with ID: {result.ModelId}");

        foreach (AnalyzedDocument document in result.Documents)

        {

            Console.WriteLine($"Document of type: {document.DocumentType}");

            foreach (KeyValuePair<string, DocumentField> fieldKvp in document.Fields)

            {

                string fieldName = fieldKvp.Key;

                DocumentField field = fieldKvp.Value;

                Console.WriteLine($"Field '{fieldName}': ");

                Console.WriteLine($"  Content: '{field.Content}'");

                Console.WriteLine($"  Confidence: '{field.Confidence}'");

            }

        }
Azure AI Document Intelligence
Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
2,016 questions
0 comments No comments
{count} votes

Accepted answer
  1. Suwarna S Kale 1,906 Reputation points
    2025-04-20T01:41:49.21+00:00

    Hello Herson Ian Moneda,

    Thank you for posting your question in the Microsoft Q&A forum. 

    Your current code extracts string fields but misses table values because tables require specialized handling in the Azure Document Analysis client. The DocumentField object contains a ValueType property distinguishing between primitive fields (strings, numbers, dates) and complex types (tables, arrays). For tables, you must explicitly check for DocumentFieldType.Array or DocumentFieldType.Object and process the nested structure. The Items field likely contains tabular data stored as a collection of DocumentField objects, which requires iterative enumeration. Modify your code to inspect each field's ValueType and implement recursive logic for table traversal.

    If the above answer helped, please do not forget to "Accept Answer" as this may help other community members to refer the info if facing a similar issue. Your contribution to the Microsoft Q&A community is highly appreciated. 

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.