How to Convert a PDF file to text in Python

Using the WhatsMate PDF-to-Text REST API



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

Here’s how:

  1. Copy the following source code to your Python script.
  2. Specify the URL of your online PDF document on line 10.
  3. Replace the Client ID and Secret on lines 5 and 6 if you have your own credentials.
  4. Install the Requests library because the sample script depends on it: pip install requests
  5. Make your script executable: chmod 755 extract-pdf-text-sync.py
  6. Run the script to see the result: ./extract-pdf-text-sync.py

If your PDF file is larger than 1 MB, you will need to call the asynchronous API instead. See an example in Python.

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 to use the API seriously.

Want to extract PDF text in another programming language? Check out the PDF-to-Text API page.