PDF.co Web API - PDF To HTML API - PHP - Convert PDF To HTML From Uploaded File - ByteScout

PDF.co Web API – PDF To HTML API – PHP – Convert PDF To HTML From Uploaded File

  • Home
  • /
  • Articles
  • /
  • PDF.co Web API – PDF To HTML API – PHP – Convert PDF To HTML From Uploaded File

PDF.co Web API – PDF To HTML API – PHP – Convert PDF To HTML From Uploaded File

pdf-to-html.php

[text]




PDF To HTML Extraction 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 PdfToHtml($apiKey, $uploadedFileUrl, $pages, $plainHtml, $columnLayout)
{
// Create URL
$url = “https://api.pdf.co/v1/pdf/convert/to/html” .
“?url=” . $uploadedFileUrl .
“&pages=” . $pages .
“&simple=” . $plainHtml .
“&columns=” . $columnLayout;

// 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)
{
$resultFileUrl = $json[“url”];

// Display link to the file with conversion results
echo “

Conversion Result:

” . $resultFileUrl . “

“;
}
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);
}

?>



[/text]


  Click here to get your Free Trial version of the SDK

Tutorials:

prev
next