---
layout: post
title: How to Convert a PDF file to text in PHP
subtitle: Using the WhatsMate PDF-to-Text REST API
published: true
last_modified_at: 2017-06-12T00:00:00+08:00
---

This article shows you how to extract text from an online PDF document in `PHP`.


Here's how:

1. Copy the following source code to your PHP script. <script src="https://gist.github.com/whatsmate/eb7730ab28c0f29011ebb241d42d0d49.js"></script>
2. Specify the URL of your online PDF document on line 8.
3. Replace the Client ID and Secret on lines 3 and 4 if you have your own credentials.
4. Visit the PHP page your just created to see the extracted text.


If your PDF file is larger than 1 MB, you will need to call the asynchronous API instead. See an <a href="https://github.com/whatsmate/pdf-demos/tree/master/python">example in Python</a>.


The trial account only allows you to call the PDF-to-Text API up to 20 times for learning purpose. [Upgrade to a Premium plan](https://www.whatsmate.net/pdf-api-subscribe.html) to use the API seriously.


Want to extract PDF text in another programming language? Check out the [PDF-to-Text API](https://www.whatsmate.net/pdf-to-text-api.html) page.


<br>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-7383487179928477"
     data-ad-slot="6959057004"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<br>


Add PDF-to-text sample code for PHP
Add PDF-to-text sample code for PHP
