PDF to Text - PHP Guide

This page serves as a guide for using the Pdfcrowd API to extract text from PDF in PHP applications. The API is designed for easy use and straightforward integration.

Installation

Download pdfcrowd-6.1.0-php.zip, unzip it and require pdfcrowd.php in your code.

Check out other installation options such as Composer or GitHub.

Quick Start

Below are PHP examples to help you quickly get started with the API. Explore our additional examples for more insights.

php require "pdfcrowd.php"; try  // create the API client instance $client = new \Pdfcrowd\PdfToTextClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file $client->convertFileToFile("/path/to/invoice.pdf", "invoice.txt"); > catch(\Pdfcrowd\Error $why)  error_log("Pdfcrowd Error: $why>\n"); throw $why; > ?> 
php require "pdfcrowd.php"; try  // create the API client instance $client = new \Pdfcrowd\PdfToTextClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file $client->convertUrlToFile("https://pdfcrowd.com/static/pdf/apisamples/invoice.pdf", "invoice.txt"); > catch(\Pdfcrowd\Error $why)  error_log("Pdfcrowd Error: $why>\n"); throw $why; > ?> 
php require "pdfcrowd.php"; try  // create the API client instance $client = new \Pdfcrowd\PdfToTextClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file $client->convertRawDataToFile(file_get_contents("/path/to/hello_world.pdf"), "invoice.txt"); > catch(\Pdfcrowd\Error $why)  error_log("Pdfcrowd Error: $why>\n"); throw $why; > ?> 

Authentication

To access the API, you will need to use your Pdfcrowd username and API key. For initial testing, you may use the following demo credentials without registering:

To obtain your personal API credentials, consider starting a free API trial or purchasing the API license.

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 error error_log("Pdfcrowd Error: $why>\n"); // print the error code error_log("Pdfcrowd Error Code: $why->getCode()>\n"); // print the error message error_log("Pdfcrowd Error Message: $why->getMessage()>\n"); >

Troubleshooting

API Method Reference

Refer to the PDF to Text PHP Reference for a description of all API methods.