Recently, as a senior Azure developer, I got a requirement on how to extract text from a PDF image. We will start by discussing a very important example: how to extract bill details from a PDF image using Azure Cognitive Services.
How to extract text from a PDF image
In real-time scenarios, we will encounter many situations where, instead of manually reading the bill, we will have to read the bill details from an image, and we may need to auto-populate these details in a form. Nowadays, we do not do anything manually in every case. We want to implement automation everywhere. We want to automate every process nowadays.
Microsoft helps us provide the Azure Cognitive Service OCR to deal with this scenario. OCR stands for Optical Character Recognition.
Read Text From Images
As we know, using the Azure Cognitive Service, a developer can easily implement an AI feature without any expertise in AI and ML. The developer’s dream comes true. A developer can easily implement the AI features by just calling the Azure Cognitive Service API. Very little effort is involved, and developers can save lots of time to achieve such excellent functionality, i.e., AI.
As part of this functionality development, we will try to extract the date and bill details from the image.
So, before starting the actual development, we should know the Prerequisites needed for this development activity.
Prerequisites
- You must have a valid Azure Subscription or Account. If you don’t have one yet, create an Azure Free Account now.
- Visual Studio 2019 needs to be installed on your Machine. If you don’t have it on your local machine or dev machine, Install Visual Studio 2019 now.
Create Azure Cognitive Service using Azure Portal
To extract text from a PDF image, follow the below steps
1. Log in to the Azure Portal (https://portal.azure.com/)
2. Once you log in to the Azure Portal, you need to search for Cognitive Services. Then click on the search result as shown below

One more way to get the same options: From the left navigation, you can also click on the + Create a resource and search for Cognitive Services. Then click on the search result as shown below

3. The next step is, to click on the Create button as highlighted in the below window.

4. Provide the below details on the Create Cognitive Services window
- Subscription: You must choose the valid subscription you want to use here.
- Resource Group: For this option, you need to choose your existing Resource Group if you have one. If you don’t have an existing Resource Group, you can create a new one by clicking the Create New link.
- Region: Provide the Region for your Azure Cognitive Services.
- Name: Here, provide a unique name for your Azure Cognitive Services.
- Pricing tier: Select the pricing tier that best suits your business needs. Then, click the View full pricing details link to verify the pricing details for your reference.
- Select the two checkboxes below to accept the terms and conditions.
Finally, click on the Review + Create button as highlighted below.

Now, it will check whether all the information you entered is correct. Once it finds that all the details are correct, it will show you Validation Passed. Now, you can see the Create button is enabled. Click on the Create button, as highlighted below, to create the Cognitive Service.

Now, you can see your deployment is completed successfully without any issues. Click on the Go to Resource button to navigate to the Azure Cognitive service you have created.

You can see the new Cognitive service once you click the Go to Resource button.
On the Cognitive service page, click on the Keys and Endpoint option from the left navigation. Now, you can see the Key1 and ENDPOINT values; keep both values and keep them with you, as we will use those values in our code in the following steps. Click on the highlighted copy button to copy those values.

Creating Console App (.NET Core) Visual Studio 2019
The next step is creating the console App (.NET Core) using Visual Studio 2019. Assuming that you have already installed Visual Studio 2019. Let’s start creating the console App (.NET Core).
Open Visual Studio 2019 and click on the Create a New Project button
Select the Console App (.NET Core) as the project template and click Next.

On the Configure your new project window, provide a name for the Project, click Provide the location where you want to save your project, and click the Create button.
