Barcode Reader#
Available Methods#
/barcode/read/from/url#
Read barcodes from images and PDF. Can read all popular barcode types from QR Code and Code 128, EAN to Datamatrix, PDF417, GS1 and many other barcodes.
Method: POST
Endpoint: /v1/barcode/read/from/url
Attributes#
Note
Attributes are case-sensitive and should be inside JSON for POST request, for example:
{
"url": "https://example.com/file1.pdf"
}
Attribute |
Description |
Required |
---|---|---|
|
URL to the source file. 1 |
yes |
|
HTTP auth user name if required to access source |
no |
|
HTTP auth password if required to access source |
no |
|
Specify page indices as comma-separated values or ranges to process (e.g. |
no |
|
Set the barcode type, must be in a |
no |
|
See Optical Marks Reader. Comma-separated list of object types to decode, must be in a
|
no |
|
Set |
no |
|
Use this parameter to set additional configurations for fine-tuning and extra options. Explore the Profiles section for more. |
no |
Supported Barcode Types#
The supported barcode types are as follows:
Name |
Type |
Character Set |
Length |
Notes |
---|---|---|---|---|
|
2D |
Numbers Only |
4 |
|
|
2D |
Full ASCII; FNC1 and ESI control codes |
Variable, Min 12 - Max 3832 |
|
|
Linear |
Numbers: 0-9; Symbols: - : . $ / + Start/Stop Characters: A, B, C, D, E, |
Variable |
|
|
Complex - see this guide. |
|||
|
Linear |
All ASCII characters and control codes |
Variable |
|
|
||||
|
Linear |
Uppercase letters A-Z; Numbers 0-9; Space - . $ / + % |
Variable |
|
|
Linear |
All ASCII characters and control codes |
Variable |
|
|
||||
|
||||
|
Linear |
Uppercase letters A-Z; Numbers 0-9; Space - . $ / + % |
||
|
2D |
All ASCII characters |
Variable |
|
|
||||
|
Linear |
Numbers Only |
13 + check digit +2 optional +5 optional |
|
|
Linear |
Numbers only |
Exact 2 Numbers |
|
|
Linear |
Numbers Only |
Exact 5 Numbers |
|
|
Linear |
Numbers Only |
7 + check digit |
|
|
Linear |
ASCII symbols |
128 ASCII symbols |
|
|
Linear |
String |
74 numeric or 41 alphabetic characters |
|
|
Linear |
String |
74 numeric or 41 alphabetic characters |
|
|
Linear |
Numbers Only |
Upto 14 digits |
Last digit must be checksum and will be verified |
|
Linear |
Numbers Only |
Upto 14 digits |
Last digit must be checksum and will be verified |
|
Linear |
Numbers Only |
Upto 14 digits |
Last digit must be checksum and will be verified |
|
Linear |
Numbers Only |
Expects 11 digits. User may enter 12th digit |
|
|
Linear |
Numbers Only |
Expects 12 digits. User may enter 13th digit |
|
|
Linear |
Numbers Only |
Expects 13 digits. User may enter 14th digit |
|
|
Linear |
Numbers Only |
Expects 7 digits. User may enter 8th digit |
|
|
Linear |
Numbers Only |
Upto 31 digits of data |
Tracking code should be exactly 20 digits long and Rounding code may be 0,5,9 or 11 digits long. Spaces and dots are allowed as separators. |
|
Linear |
Numbers Only |
EVEN if checksum is not to be added, ODD if checksum is to be added |
|
|
Linear |
Numbers Only |
Expects 13 digits. User may enter 14th digit which will be verified. |
|
|
2D |
All ASCII characters |
93 |
|
|
||||
|
2D |
String |
1850 characters or 2710 digits |
|
|
Linear |
Numbers Only |
Variable |
|
|
||||
|
Linear |
This symbology supports all 256 ASCII characters and 8-bit binary data. |
Variable |
|
|
Linear |
Decimal Numbers |
Number can be between 1 to 131070 |
|
|
Postal |
Numbers Only |
5 + check digit +4 optional +6 optional |
|
|
Linear |
Numbers Only |
Excatly 6 or 7 digits |
|
|
2D |
All ASCII characters |
Variable |
|
|
Postal |
Digits and characters from A to Z |
||
|
Postal |
All numeric digits (0-9). All uppercase letters (A-Z) |
Variable |
|
|
||||
|
Linear |
Numbers Only |
11 + check digit +2 optional +5 optional |
|
|
Linear |
Numbers Only |
UPC-E encodes 6 digits of numeric message data together with a number system digit and a check digit, for a total of 8 digits. |
|
|
Postal |
Query parameters#
No query parameters accepted.
Payload 3#
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"types": "QRCode,Code128,Code39,Interleaved2of5,EAN13",
"pages": "0",
"async": false
}
Response 2#
{
"barcodes": [
{
"Value": "abcdef123456",
"RawData": "",
"Type": 14,
"Rect": "{X=448,Y=23,Width=106,Height=112}",
"Page": 0,
"File": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"Confidence": 1,
"Metadata": "",
"TypeName": "QRCode"
},
{
"Value": "test123",
"RawData": "",
"Type": 2,
"Rect": "{X=111,Y=60,Width=255,Height=37}",
"Page": 0,
"File": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"Confidence": 0.90625155,
"Metadata": "",
"TypeName": "Code128"
},
{
"Value": "123456",
"RawData": "",
"Type": 4,
"Rect": "{X=111,Y=129,Width=306,Height=37}",
"Page": 0,
"File": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"Confidence": 0.7710818,
"Metadata": "",
"TypeName": "Code39"
},
{
"Value": "<FNC1>0112345678901231",
"RawData": "",
"Type": 2,
"Rect": "{X=111,Y=198,Width=305,Height=37}",
"Page": 0,
"File": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"Confidence": 0.9156459,
"Metadata": "",
"TypeName": "Code128"
},
{
"Value": "12345670",
"RawData": [
1,
2,
3,
4,
5,
6,
7,
0
],
"Type": 5,
"Rect": "{X=111,Y=267,Width=182,Height=0}",
"Page": 0,
"File": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"Confidence": 1,
"Metadata": "",
"TypeName": "I2of5"
},
{
"Value": "1234567890128",
"RawData": "",
"Type": 6,
"Rect": "{X=102,Y=336,Width=71,Height=72}",
"Page": 0,
"File": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"Confidence": 0.895925164,
"Metadata": "",
"TypeName": "EAN13"
}
],
"pageCount": 1,
"error": false,
"status": 200,
"remainingCredits": 99826192,
"credits": 35
}
CURL#
curl --location --request POST 'https://api.pdf.co/v1/barcode/read/from/url' \
--header 'x-api-key: *******************' \
--header 'Content-Type: application/json' \
--data-raw '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/barcode-reader/sample.pdf",
"types": "QRCode,Code128,Code39,Interleaved2of5,EAN13",
"pages": "0",
"async": false
}'
Optical Marks Reader#
Our barcode reader engine can also find the following marks and objects on scanned documents:
Checkboxes
Radioboxes
Vertical and horizontal lines
General segments (basically, all content types on the page).
Payload 3#
{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-to-html/sample.pdf",
"types": "Checkbox,UnderlinedField",
"async": false
}
Response 2#
{
"barcodes": [
{
"Value": "box",
"RawData": "",
"Type": 53,
"Rect": "{X=298,Y=437,Width=132,Height=6}",
"Page": 0,
"File": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-to-html/sample.pdf",
"Confidence": 1,
"Metadata": "",
"TypeName": "UnderlinedField"
}
],
"pageCount": 1,
"error": false,
"status": 200,
"duration": 860,
"remainingCredits": 98725528,
"credits": 35
}
CURL#
curl --location --request POST 'https://api.pdf.co/v1/barcode/read/from/url' \
--header 'x-api-key: *******************' \
--header 'Content-Type: application/json' \
--data-raw '{
"url": "https://pdfco-test-files.s3.us-west-2.amazonaws.com/pdf-to-html/sample.pdf",
"types": "Checkbox,UnderlinedField",
"async": false
}'
Code samples#
var https = require("https");
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
const API_KEY = "***********************************";
// Direct URL of source file to search barcodes in.
const SourceFileUrl = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/barcode-reader/sample.pdf";
// Comma-separated list of barcode types to search.
// See valid barcode types in the documentation https://developer.pdf.co
const BarcodeTypes = "Code128,Code39,Interleaved2of5,EAN13";
// Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
const Pages = "";
// Prepare request to `Barcode Reader` API endpoint
var queryPath = `/v1/barcode/read/from/url`;
// JSON payload for api request
var jsonPayload = JSON.stringify({
types: BarcodeTypes,
pages: Pages,
url: SourceFileUrl
});
var reqOptions = {
host: "api.pdf.co",
method: "POST",
path: queryPath,
headers: {
"x-api-key": API_KEY,
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(jsonPayload, 'utf8')
}
};
// Send request
var postRequest = https.request(reqOptions, (response) => {
response.on("data", (d) => {
// Parse JSON response
var data = JSON.parse(d);
if (data.error == false) {
// Display found barcodes in console
data.barcodes.forEach((element) => {
console.log("Found barcode:");
console.log(" Type: " + element.TypeName);
console.log(" Value: " + element.Value);
console.log(" Document Page Index: " + element.Page);
console.log(" Rectangle: " + element.Rect);
console.log(" Confidence: " + element.Confidence);
console.log("");
}, this);
}
else {
// Service reported error
console.log(data.message);
}
});
}).on("error", (e) => {
// Request error
console.error(e);
});
// Write request data
postRequest.write(jsonPayload);
postRequest.end();
import os
import requests # pip install requests
# The authentication key (API Key).
# Get your own by registering at https://app.pdf.co
API_KEY = "******************************************"
# Base URL for PDF.co Web API requests
BASE_URL = "https://api.pdf.co/v1"
# Direct URL of source file to search barcodes in.
SourceFileURL = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/barcode-reader/sample.pdf"
# Comma-separated list of barcode types to search.
# See valid barcode types in the documentation https://developer.pdf.co
BarcodeTypes = "Code128,Code39,Interleaved2of5,EAN13"
# Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
Pages = ""
def main(args=None):
readBarcodes(SourceFileURL)
def readBarcodes(uploadedFileUrl):
"""Get Barcode Information using PDF.co Web API"""
# Prepare requests params as JSON
# See documentation: https://developer.pdf.co
parameters = {}
parameters["types"] = BarcodeTypes
parameters["pages"] = Pages
parameters["url"] = uploadedFileUrl
# Prepare URL for 'Barcode Reader' API request
url = "{}/barcode/read/from/url".format(BASE_URL)
# Execute request and get response as JSON
response = requests.post(url, data=parameters, headers={ "x-api-key": API_KEY })
if (response.status_code == 200):
json = response.json()
if json["error"] == False:
# Display information
for barcode in json["barcodes"]:
print("Found barcode:")
print(f" Type: {barcode['TypeName']}")
print(f" Value: {barcode['Value']}")
print(f" Document Page Index: {barcode['Page']}")
print(f" Rectangle: {barcode['Rect']}")
print(f" Confidence: {barcode['Confidence']}")
print("")
else:
# Show service reported error
print(json["message"])
else:
print(f"Request error: {response.status_code} {response.reason}")
if __name__ == '__main__':
main()
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace PDFcoApiExample
{
class Program
{
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
const String API_KEY = "***********************************";
// Direct URL of source file (image or PDF) to search barcodes in.
const string SourceFileURL = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/barcode-reader/sample.pdf";
// Comma-separated list of barcode types to search.
// See valid barcode types in the documentation https://developer.pdf.co
const string BarcodeTypes = "Code128,Code39,Interleaved2of5,EAN13";
// Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
const string Pages = "";
static void Main(string[] args)
{
// Create standard .NET web client instance
WebClient webClient = new WebClient();
// Set API Key
webClient.Headers.Add("x-api-key", API_KEY);
// Prepare requests params as JSON
// See documentation: https://developer.pdf.co
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("url", SourceFileURL);
parameters.Add("type", BarcodeTypes);
parameters.Add("pages", Pages);
// Convert dictionary of params to JSON
string jsonPayload = JsonConvert.SerializeObject(parameters);
try
{
// URL of "Barcode Reader" endpoint
string url = "https://api.pdf.co/v1/barcode/read/from/url";
// Execute POST request with JSON payload
string response = webClient.UploadString(url, jsonPayload);
// Parse JSON response
JObject json = JObject.Parse(response);
if (json["error"].ToObject<bool>() == false)
{
// Display found barcodes in console
foreach (JToken token in json["barcodes"])
{
Console.WriteLine("Found barcode:");
Console.WriteLine(" Type: " + token["TypeName"]);
Console.WriteLine(" Value: " + token["Value"]);
Console.WriteLine(" Document Page Index: " + token["Page"]);
Console.WriteLine(" Rectangle: " + token["Rect"]);
Console.WriteLine(" Confidence: " + token["Confidence"]);
Console.WriteLine();
}
}
else
{
// Display service reported error
Console.WriteLine(json["message"].ToString());
}
}
catch (WebException e)
{
// Display request error
Console.WriteLine(e.ToString());
}
finally
{
webClient.Dispose();
}
Console.WriteLine();
Console.WriteLine("Press any key...");
Console.ReadKey();
}
}
}
package com.company;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import okhttp3.*;
import java.io.*;
import java.net.*;
public class Main
{
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
final static String API_KEY = "***********************************";
// Direct URL of source file to search barcodes in.
final static String SourceFileURL = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/barcode-reader/sample.pdf";
// Comma-separated list of barcode types to search.
// See valid barcode types in the documentation https://developer.pdf.co
final static String BarcodeTypes = "Code128,Code39,Interleaved2of5,EAN13";
// Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
final static String Pages = "";
public static void main(String[] args) throws IOException
{
// Create HTTP client instance
OkHttpClient webClient = new OkHttpClient();
// Prepare URL for `Barcode Reader` API call
String query = "https://api.pdf.co/v1/barcode/read/from/url";
// Make correctly escaped (encoded) URL
URL url = null;
try
{
url = new URI(null, query, null).toURL();
}
catch (URISyntaxException e)
{
e.printStackTrace();
}
// Create JSON payload
String jsonPayload = String.format("{\"types\": \"%s\", \"pages\": \"%s\", \"url\": \"%s\"}",
BarcodeTypes,
Pages,
SourceFileURL);
// Prepare request body
RequestBody body = RequestBody.create(MediaType.parse("application/json"), jsonPayload);
// Prepare request
Request request = new Request.Builder()
.url(url)
.addHeader("x-api-key", API_KEY) // (!) Set API Key
.addHeader("Content-Type", "application/json")
.post(body)
.build();
// Execute request
Response response = webClient.newCall(request).execute();
if (response.code() == 200)
{
// Parse JSON response
JsonObject json = new JsonParser().parse(response.body().string()).getAsJsonObject();
boolean error = json.get("error").getAsBoolean();
if (!error)
{
// Display found barcodes in console
for (JsonElement element : json.get("barcodes").getAsJsonArray())
{
JsonObject barcode = (JsonObject) element;
System.out.println("Found barcode:");
System.out.println(" Type: " + barcode.get("TypeName").getAsString());
System.out.println(" Value: " + barcode.get("Value").getAsString());
System.out.println(" Document Page Index: " + barcode.get("Page").getAsString());
System.out.println(" Rectangle: " + barcode.get("Rect").getAsString());
System.out.println(" Confidence: " + barcode.get("Confidence").getAsString());
System.out.println();
}
}
else
{
// Display service reported error
System.out.println(json.get("message").getAsString());
}
}
else
{
// Display request error
System.out.println(response.code() + " " + response.message());
}
}
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Cloud API asynchronous "Barcode Reader" job example (allows to avoid timeout errors).</title>
</head>
<body>
<?php
// Cloud API asynchronous "Barcode Reader" job example.
// Allows to avoid timeout errors when processing huge or scanned PDF documents.
// The authentication key (API Key).
// Get your own by registering at https://app.pdf.co
$apiKey = "***************************************";
// Direct URL of source file (image or PDF) to search barcodes in. Check another example if you need to upload a local file to the cloud.
// You can also upload your own file into PDF.co and use it as url. Check "Upload File" samples for code snippets: https://github.com/bytescout/pdf-co-api-samples/tree/master/File%20Upload/
$sourceFileUrl = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/barcode-reader/sample.pdf";
// Comma-separated list of barcode types to search.
// See valid barcode types in the documentation https://developer.pdf.co
$barcodeTypes = "Code128,Code39,Interleaved2of5,EAN13";
// Comma-separated list of page indices (or ranges) to process. Leave empty for all pages. Example: '0,2-5,7-'.
$pages = "";
// Prepare URL for `Barcode Reader` API call
$url = "https://api.pdf.co/v1/barcode/read/from/url";
// Prepare requests params
$parameters = array();
$parameters["types"] = $barcodeTypes;
$parameters["pages"] = $pages;
$parameters["url"] = $sourceFileUrl;
$parameters["async"] = true; // (!) Make asynchronous job
// Create Json payload
$data = json_encode($parameters);
// Create request
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey, "Content-type: application/json"));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
// Execute request
$result = curl_exec($curl);
echo $result . "<br/>";
if (curl_errno($curl) == 0)
{
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status_code == 200)
{
$json = json_decode($result, true);
if (!isset($json["error"]) || $json["error"] == false)
{
// URL of generated JSON file that will available after the job completion
$resultFileUrl = $json["url"];
// Asynchronous job ID
$jobId = $json["jobId"];
// Check the job status in a loop
do
{
$status = CheckJobStatus($jobId, $apiKey); // Possible statuses: "working", "failed", "aborted", "success".
// Display timestamp and status (for demo purposes)
echo "<p>" . date(DATE_RFC2822) . ": " . $status . "</p>";
if ($status == "success")
{
// Display link to JSON file with information about decoded barcodes
echo "<div>## Conversion Result:<a href='" . $resultFileUrl . "' target='_blank'>" . $resultFileUrl . "</a></div>";
break;
}
else if ($status == "working")
{
// Pause for a few seconds
sleep(3);
}
else
{
echo $status . "<br/>";
break;
}
}
while (true);
}
else
{
// Display service reported error
echo "<p>Error: " . $json["message"] . "</p>";
}
}
else
{
// Display request error
echo "<p>Status code: " . $status_code . "</p>";
echo "<p>" . $result . "</p>";
}
}
else
{
// Display CURL error
echo "Error: " . curl_error($curl);
}
// Cleanup
curl_close($curl);
function CheckJobStatus($jobId, $apiKey)
{
$status = null;
// Create URL
$url = "https://api.pdf.co/v1/job/check";
// Prepare requests params
$parameters = array();
$parameters["jobid"] = $jobId;
// Create Json payload
$data = json_encode($parameters);
// Create request
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array("x-api-key: " . $apiKey, "Content-type: application/json"));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
// Execute request
$result = curl_exec($curl);
if (curl_errno($curl) == 0)
{
$status_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($status_code == 200)
{
$json = json_decode($result, true);
if (!isset($json["error"]) || $json["error"] == false)
{
$status = $json["status"];
}
else
{
// Display service reported error
echo "<p>Error: " . $json["message"] . "</p>";
}
}
else
{
// Display request error
echo "<p>Status code: " . $status_code . "</p>";
echo "<p>" . $result . "</p>";
}
}
else
{
// Display CURL error
echo "Error: " . curl_error($curl);
}
// Cleanup
curl_close($curl);
return $status;
}
?>
</body> </html>
On Github#
Footnotes
- 1
Supports publicly accessible links from any source, including Google Drive, Dropbox, and PDF.co Built-In Files Storage. The PDF.co API only accepts URLs as file inputs, not direct file uploads. If your file is stored locally or not publicly accessible, you must upload it using the File Upload endpoints to get a publicly accessible URL. Note: If you experience intermittent Access Denied or Too Many Requests errors, please try adding
cache:
to enable built-in URL caching (e.g.,cache:https://example.com/file1.pdf
). For data security, you have the option to encrypt output files and decrypt input files. Learn more about user-controlled data encryption.- 2(1,2)
Main response codes as follows:
Code
Description
200
Success
400
Bad request. Typically happens because of bad input parameters, or because the input URLs can’t be reached, possibly due to access restrictions like needing a login or password.
401
Unauthorized
402
Not enough credits
445
Timeout error. To process large documents or files please use asynchronous mode (set the
async
parameter totrue
) and then check status using the /job/check endpoint. If a file contains many pages then specify a page range using thepages
parameter. The number of pages of the document can be obtained using the /pdf/info endpoint.Note
For more see the complete list of available response codes.
- 3(1,2)
PDF.co Request size: API requests do not support request sizes of more than
4
megabytes in size. Please ensure that request sizes do not exceed this limit.