This page describes how to use the Pdfcrowd online API to convert PDF to HTML
in PHP.
The API is user-friendly and can be integrated into your application with just a few lines of code.
Here are PHP examples for quickly getting started with the API.
See more examples.
<?phprequire"pdfcrowd.php";try{// create the API client instance$client=new\Pdfcrowd\PdfToHtmlClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// run the conversion and write the result to a file$client->convertFileToFile("/path/to/logo.pdf","logo.html");}catch(\Pdfcrowd\Error$why){error_log("Pdfcrowd Error: {$why}\n");throw$why;}?>
<?phprequire"pdfcrowd.php";try{// create the API client instance$client=new\Pdfcrowd\PdfToHtmlClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// run the conversion and write the result to a file$client->convertUrlToFile("https://pdfcrowd.com/static/pdf/apisamples/invoice.pdf","invoice.html");}catch(\Pdfcrowd\Error$why){error_log("Pdfcrowd Error: {$why}\n");throw$why;}?>
<?phprequire"pdfcrowd.php";try{// create the API client instance$client=new\Pdfcrowd\PdfToHtmlClient("demo","ce544b6ea52a5621fb9d55f8b542d14d");// run the conversion and write the result to a file$client->convertRawDataToFile(file_get_contents("/path/to/hello_world.pdf"),"logo.html");}catch(\Pdfcrowd\Error$why){error_log("Pdfcrowd Error: {$why}\n");throw$why;}?>
Authentication
The credentials to access the API are your Pdfcrowd username and the API key.
You can try out the API without registering using the following demo
credentials:
It is recommended that you implement error handling to catch errors
that the API may return, see the example code below. A list of status
codes and their description can be found
here.
try{// call the API }catch(\Pdfcrowd\Error$why){// print the errorerror_log("Pdfcrowd Error: {$why}\n");// print the error codeerror_log("Pdfcrowd Error Code: {$why->getCode()}\n");// print the error messageerror_log("Pdfcrowd Error Message: {$why->getMessage()}\n");}