请将表单识别器 SDK NuGet 更新到版本 v3.1.0-beta.4 以查看发票行项目。调用 SDK 并获取订单项详细信息的示例代码如下:
FormRecognizerClient client = new FormRecognizerClient(new Uri(YOUR_FR_URL), new Azure.AzureKeyCredential(YOUR_FR_KEY));
using (FileStream stream = new FileStream(@"SampleInvoice.pdf", FileMode.Open))
{
RecognizeInvoicesOptions options = new RecognizeInvoicesOptions() { IncludeFieldElements = true };
var oper = await client.StartRecognizeInvoices(stream, options).WaitForCompletionAsync();
var rawResponse = oper.GetRawResponse();
rawResponse.ContentStream.Position = 0;
using (var reader = new StreamReader(oper.GetRawResponse().ContentStream))
{
Console.WriteLine($"Raw output:");
Console.WriteLine(reader.ReadToEnd());
}
foreach (var invoice in oper.Value)
{
foreach (FormField field in invoice.Fields.Values)
{
Console.WriteLine($"Field {field.Name}: ");
Console.WriteLine($" Value: {field.ValueData?.Text}");
if (field.Name == "Items")
{
var count = 0;
foreach (var lineField in field.Value.AsList())
{
count++;
Console.WriteLine($" LineItem {count}: ");
foreach (var (lineFieldName, lineFieldValue) in lineField.Value.AsDictionary())
{
Console.WriteLine($" LineField: {lineFieldName}");
Console.WriteLine($" Value: {lineFieldValue.ValueData?.Text}");
}
}
}
}
}
}