Read Different Barcode Types in C# using PDF.co
In this tutorial, you'll learn how to read various barcode types from a PDF using the PDF.co Barcode Reader Web API in C#.
PDF.co provides powerful tools for PDF processing, such as searching, merging, filling forms, and barcode reading. This guide will walk you through the steps to create a C# console application that extracts barcode data from a PDF.
Create New Project
First, open your terminal or command prompt and run the following command to create a new C# console project inside an "app" folder:
dotnet new console -o app
![Create New Project](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F88cb6ab5aef1eb560cff420c6a8dca8fbe658a9d-1328x489.jpg&w=3840&q=75)
Open VSCode
Type cd app
to go to the folder and enter code .
to open VSCode.
![Open VSCode](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F511d952f7e4c07212ff19a5b85bda35602daeff3-1242x677.jpg&w=3840&q=75)
Add Source Code
Copy the Read Barcode from URL (Async) in C# source code from the PDF.co Code Sample Repository.
Add Package
Add the Newtonsoft.Json package, which helps with JSON handling, by running: dotnet add package Newtonsoft.Json
![Add Package](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F4dd629cb667d606a9704d3b516dbcbcca8386a5d-1489x828.jpg&w=3840&q=75)
Add API Key
Now, let’s add our PDF.co API Key in line 31. You can get your API Key from the PDF.co dashboard.
![Add API Key](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F02e866a7ac1854aacf681a639b4338c774cc9aac-1360x238.jpg&w=3840&q=75)
Add Source File
In line 35, you can find the PDF URL. If you’d like to test your own file, replace the sample link with your file URL.
If you prefer to work with a file from your local machine, use this code sample instead: Upload File and Read Barcode (C#)
![Add Source File](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2F3e043037596fc26a50be7b5d3d8403f02a0c9766-1600x149.jpg&w=3840&q=75)
Specify Barcode Type
In line 39, enter one or more barcode types you want to decode. You can find the full list of barcode types here.
![Specify Barcode Type](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fdddca10f45aaebbb24d8a4c867d927ee94b01494-1600x203.jpg&w=3840&q=75)
Run Project
Execute the following command to run your C# console application: dotnet run
.
![Run Project](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fba9c2fe6555b1b34eaeb9f7ab5ee2746335a0895-1452x470.jpg&w=3840&q=75)
View the Decoded Barcode Values
Once the program runs, you will see the decoded barcode values displayed in the terminal.
![Decoded Barcode Values](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2F2niroq9z%2Fproduction%2Fa56f720c6377d3df4e68530cf83f83c9dbb98d26-1394x918.jpg&w=3840&q=75)
In this tutorial, you learned how to read different Barcode types from a PDF in C# using PDF.co Barcode Reader Web API. You also learned how to:
- Create a new C# project
- Install and use the Newtonsoft.Json package
- Add an API key and customize barcode reading settings
Now you're ready to integrate barcode reading into your C# applications!