-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathProgram.cs
More file actions
49 lines (44 loc) · 2.05 KB
/
Program.cs
File metadata and controls
49 lines (44 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// coding: utf - 8
// --------------------------------------------------------------------------
// Copyright(c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
// --------------------------------------------------------------------------
using Azure;
using Azure.AI.DocumentIntelligence;
using Azure.Identity;
using Utility;
namespace AuthenticateWithUserAssignedManagedIdentity
{
internal class Program
{
static async Task Main(string[] args)
{
// The endpoint to your Document Intelligence resource.
// To obtain the parameter, please reference the document
// in (..\..\Doc\Prerequisites For Authentication With User-Assigned Managed Identity.md)
var docIntelligenceEndpoint = "<Azure Document Intelligence Endpoint>";
var client = new DocumentIntelligenceClient(new Uri(docIntelligenceEndpoint), new DefaultAzureCredential());
// sample file online
var url = "https://documentintelligence.ai.azure.com/documents/samples/prebuilt/w2-single.png";
var content = new AnalyzeDocumentContent
{
UrlSource = new Uri(url)
};
// To see the list of all the supported fields returned by service and its corresponding types for each supported model,
// access https://aka.ms/di-prebuilt please.
Operation<AnalyzeResult> operation = await client.AnalyzeDocumentAsync(WaitUntil.Completed, "prebuilt-tax.us.w2", content);
AnalyzeResult result = operation.Value;
// Extract DocumentField:
for (int i = 0; i < result.Documents.Count; i++)
{
Console.WriteLine($"Document {i}:");
AnalyzedDocument document = result.Documents[i];
foreach (var item in document.Fields)
{
Utils.ExtractValueFromDocumentField(item.Key, item.Value);
}
}
}
}
}