This page serves as a guide for using the Pdfcrowd API to convert images to PDF in PHP applications.
The API is designed for easy use and straightforward integration.
Below are PHP examples to help you quickly get started with the API.
Explore our additional examples for more insights.
<?phprequire"pdfcrowd.php";try{// create the API client instance$client=new\Pdfcrowd\ImageToPdfClient("your_username","your_apikey");// run the conversion and write the result to a file$client->convertFileToFile("/path/to/logo.png","logo.pdf");}catch(\Pdfcrowd\Error$why){error_log("Pdfcrowd Error: {$why}\n");throw$why;}?>
<?phprequire"pdfcrowd.php";try{// create the API client instance$client=new\Pdfcrowd\ImageToPdfClient("your_username","your_apikey");// run the conversion and write the result to a file$client->convertUrlToFile("https://pdfcrowd.com/static/images/logo.png","logo.pdf");}catch(\Pdfcrowd\Error$why){error_log("Pdfcrowd Error: {$why}\n");throw$why;}?>
<?phprequire"pdfcrowd.php";try{// create the API client instance$client=new\Pdfcrowd\ImageToPdfClient("your_username","your_apikey");// run the conversion and write the result to a file$client->convertRawDataToFile(file_get_contents("/path/to/logo.png"),"logo.pdf");}catch(\Pdfcrowd\Error$why){error_log("Pdfcrowd Error: {$why}\n");throw$why;}?>
Authentication
Error Handling
It is recommended that you implement error handling to catch errors the API
may return. Effective error handling is vital as it ensures application
stability and provides clearer diagnostics. See the example code below for
guidance on implementing error handling, and refer to this list of
status codes for more information.
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");}
Troubleshooting
If you are receiving an error, refer to the
API Status Codes for more information.
Utilize
setDebugLog() and getDebugLogUrl()
to obtain detailed information about the conversion process, including
load errors, load times, browser console output, etc.