Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Document AI with OCR Processor

2 views
Skip to first unread message

Dhanaraj Sonawane

unread,
Oct 17, 2022, 12:47:32 PM10/17/22
to
I need code level details for implementing Document AI in Console Application(C#).

It will very help full for me.

Actually i have snippet code for Document AI in c# , but its not working.

Code is share for reference.
try
{


//Generate a document
string pdfFilePath = "C:\\Dhanaraj\\- - - - - PD-INVOICES-PDDemo.pdf";
var bytes = Encoding.UTF8.GetBytes(pdfFilePath);


//string pdfFilePath = "path-as-before";
//var bytes = File.ReadAllBytes(pdfFilePath);
//ByteString content = ByteString.CopyFrom(bytes);

ByteString content = ByteString.CopyFrom(bytes);

// Create client
DocumentProcessorServiceClient documentProcessorServiceClient = await DocumentProcessorServiceClient.CreateAsync();
// Initialize request argument(s)
ProcessRequest request = new ProcessRequest
{
ProcessorsName = ProcessorName.FromProjectLocationProcessor("mindful-silo-351415", "us", "a072a02fe917a81b"),
SkipHumanReview = false,
InlineDocument = new Google.Cloud.DocumentAI.V1.Document(),
RawDocument = new RawDocument(),
};

request.RawDocument.MimeType = "application/pdf";
request.RawDocument.Content = content;

// Make the request
ProcessResponse response = await documentProcessorServiceClient.ProcessDocumentAsync(request);

Google.Cloud.DocumentAI.V1.Document docResponse = response.Document;

Console.WriteLine(docResponse.Text);

}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}


Thanks in advance.

0 new messages