PDF.co Web API - PDF Optimization API - PHP - Optimize PDF Asynchronously - ByteScout

PDF.co Web API – PDF Optimization API – PHP – Optimize PDF Asynchronously

  • Home
  • /
  • Articles
  • /
  • PDF.co Web API – PDF Optimization API – PHP – Optimize PDF Asynchronously

PDF.co Web API – PDF Optimization API – PHP – Optimize PDF Asynchronously

optimize-pdf-async.php

[text]




Cloud API asynchronous “Optimize PDF” job example (allows to avoid timeout errors).

” . date(DATE_RFC2822) . “: ” . $status . “

“;

if ($status == “Finished”)
{
// Display link to the file with conversion results
echo “

Conversion Result:

” . $resultFileUrl . “

“;
break;
}
else if ($status == “InProgress”)
{
// Pause for a few seconds
sleep(3);
}
else
{
echo $status . “
“;
break;
}
}
while (true);
}
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);
}

// Cleanup
curl_close($curl);

function CheckJobStatus($jobId)
{
$status = null;

// Create URL
$url = “https://api.pdf.co/v1/job/check?jobid=” . $jobId;

// Create request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
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)
{
$status = $json[“Status”];
}
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);
}

// Cleanup
curl_close($curl);

return $status;
}

?>



[/text]


  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next