This page describes how to use our cloud-based API to convert PDF to text in Java. The API is user-friendly and can be integrated into your application with just a few lines of code.
The Java API client library provides easy access to the Pdfcrowd API. No third-party libraries are required.
Download pdfcrowd-5.13.0-java.zip, unzip it and copy pdfcrowd-5.13.0.jar to your CLASSPATH.We also offer other installation options such as Maven or GitHub.
The credentials to access the API are your Pdfcrowd username and the API key. You can try out the API without registering using the following demo credentials:
demo
ce544b6ea52a5621fb9d55f8b542d14d
To get your personal API credentials, you can start a free API trial or buy the API license.
Refer to the PDF to Text Java Reference for a description of all API methods.
Here are a few Java examples to get you started quickly with the API. See more examples.
import com.pdfcrowd.*; import java.io.*; public class ApiTest { public static void main(String[] args) throws IOException, Pdfcrowd.Error { try { // create the API client instance Pdfcrowd.PdfToTextClient 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) { // report the error System.err.println("Pdfcrowd Error: " + why); // rethrow or handle the exception throw why; } catch(IOException why) { // report the error System.err.println("IO Error: " + why); // rethrow or handle the exception throw why; } } }
import com.pdfcrowd.*; import java.io.*; public class ApiTest { public static void main(String[] args) throws IOException, Pdfcrowd.Error { try { // create the API client instance Pdfcrowd.PdfToTextClient 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) { // report the error System.err.println("Pdfcrowd Error: " + why); // rethrow or handle the exception throw why; } catch(IOException why) { // report the error System.err.println("IO Error: " + why); // rethrow or handle the exception throw why; } } }
import com.pdfcrowd.*; import java.io.*; import java.nio.file.Files; import java.nio.file.Paths; public class ApiTest { public static void main(String[] args) throws IOException, Pdfcrowd.Error { try { // create the API client instance Pdfcrowd.PdfToTextClient client = new Pdfcrowd.PdfToTextClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // run the conversion and write the result to a file client.convertRawDataToFile(Files.readAllBytes(Paths.get("/path/to/hello_world.pdf")), "invoice.txt"); } catch(Pdfcrowd.Error why) { // report the error System.err.println("Pdfcrowd Error: " + why); // rethrow or handle the exception throw why; } catch(IOException why) { // report the error System.err.println("IO Error: " + why); // rethrow or handle the exception throw why; } } }