Azure AI Document Intelligence
An Azure service that turns documents into usable data. Previously known as Azure Form Recognizer.
1,625 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
var client = new FormRecognizerClient(new Uri(endPoint), credential);
Stream stream = file.OpenReadStream();
var options = new RecognizeInvoicesOptions() { Locale = parserServiceLocale, Pages = { pageNumber.ToString() }, IncludeFieldElements = true };
RecognizeInvoicesOperation operation = await client.StartRecognizeInvoicesAsync(stream, options);
Hi @Ashik Chittari,
Does the gif below is you want ?
Here is the sample code:
using Azure.AI.FormRecognizer.DocumentAnalysis;
using Azure;
using Microsoft.AspNetCore.Mvc;
using Azure.AI.FormRecognizer;
using Azure.AI.FormRecognizer.Models;
namespace signalr_iwa.Controllers
{
public class TestController : Controller
{
private readonly IWebHostEnvironment _host;
public TestController(IWebHostEnvironment host) {
_host = host;
}
private async Task WriteSseEventAsync(HttpResponse response, string data)
{
await response.WriteAsync($"data: {data}\n\n");
await response.Body.FlushAsync();
}
public async Task formrecognizer() {
string endpoint = "https://myformrecognizer.cognitiveservices.azure.com/";
string apiKey = "0631fa0****0f63723";
var credential = new AzureKeyCredential(apiKey);
var client = new FormRecognizerClient(new Uri(endpoint), credential);
string invoicePath = Path.Combine(_host.WebRootPath, "pdf", "sample-invoice.pdf");
using var stream = new FileStream(invoicePath, FileMode.Open);
var options = new RecognizeInvoicesOptions()
{
IncludeFieldElements = true
};
var operation = client.StartRecognizeInvoices(stream, options);
Response<RecognizedFormCollection> operationResponse = operation.WaitForCompletionAsync().Result;
RecognizedFormCollection recognizedInvoices = operationResponse.Value;
var response = Response;
response.Headers.Add("Content-Type", "text/event-stream; charset=utf-8");
foreach (var recognizedForm in recognizedInvoices)
{
Console.WriteLine($"Form type: {recognizedForm.FormType}");
foreach (var field in recognizedForm.Fields)
{
if (field.Value.ValueData != null) {
Console.WriteLine($"Field name: {field.Key}, Value: {field.Value.ValueData.Text}, Confidence: {field.Value.Confidence}");
await WriteSseEventAsync(response, $"Field name: {field.Key}, Value: {field.Value.ValueData.Text}, Confidence: {field.Value.Confidence}");
//await Task.Delay(800);
}
}
}
}
}
}
I save the pdf file under the wwwroot.
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Jason