How to Convert a PDF file to text in Java

Using the WhatsMate PDF-to-Text REST API



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

Here’s how:

  1. Copy the following source code to a Java file named SyncPdfTextExtractor.java.
  2. Specify the URL of your online PDF document on line 20.
  3. Replace the Client ID and Secret on lines 10 and 11 if you have your own credentials.
  4. Compile the Java file: javac SyncPdfTextExtractor.java
  5. Execute the class to see the extracted text: java SyncPdfTextExtractor

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

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.