PDF.co Web API - Barcode Reader API - PHP - Read Barcode From Uploaded File - ByteScout

PDF.co Web API – Barcode Reader API – PHP – Read Barcode From Uploaded File

  • Home
  • /
  • Articles
  • /
  • PDF.co Web API – Barcode Reader API – PHP – Read Barcode From Uploaded File

PDF.co Web API – Barcode Reader API – PHP – Read Barcode From Uploaded File

read-barcode.php

[text]




Barcode Reader Results

Status code: ” . $status_code . “

“;
echo “

” . $result . “

“;
}
}
else
{
// Display CURL error
echo “Error: ” . curl_error($curl);
}
}
else
{
// Display service reported error
echo “

Status code: ” . $status_code . “

“;
echo “

” . $result . “

“;
}

curl_close($curl);
}
else
{
// Display CURL error
echo “Error: ” . curl_error($curl);
}

function ReadBarcodes($apiKey, $barcodeTypesToFind, $uploadedFileUrl, $pages)
{
// Prepare URL for `Barcode Reader` API call
$url = “https://api.pdf.co/v1/barcode/read/from/url” .
“?types=” . join(“,”, $barcodeTypesToFind) .
“&pages=” . $pages .
“&url=” . $uploadedFileUrl;

// Create request
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER, array(“x-api-key: ” . $apiKey));
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

// 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 ($json[“error”] == false)
{
// Display decoding results
$barcodes = $json[“barcodes”];
foreach ($barcodes as $barcode)
{
echo “

Found barcode:

“;
echo “

Type: ” . $barcode[“TypeName”] . “

“;
echo “

Value: ” . $barcode[“Value”] . “

“;
echo “

Document Page Index: ” . $barcode[“Page”] . “

“;
echo “

Rectangle: ” . $barcode[“Rect”] . “

“;
echo “

Confidence: ” . $barcode[“Confidence”] . “

“;
echo “
“;
}
}
else
{
// Display service reported error
echo “

Error: ” . $json[“message”] . “

“;
}
}
else
{
// Display request error
echo “

Status code: ” . $status_code . “

“;
echo “

” . $result . “

“;
}
}
else
{
// Display CURL error
echo “Error: ” . curl_error($curl);
}
}

?>



[/text]


  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next