In this tutorials I am going to show you how to work with java pdf reader. To read the pdf document from Java application, here I am going to use PdfBox.

PDFBox is an open source Java tool to work with pdf documents, provided by Apache.

Java pdf reader :

Lets see how to work with PDFBox in java application. To work with PDFBox we need to have the pdfbox dependency.

pdfbxox maven :

We should include the below maven dependency in pom.xml




Java pdf reader Example :

I am going to read the below pdf from Java application.

Java pdf reader Example


package com.onlinetutorialspoint.pdfbox;


import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.encryption.InvalidPasswordException;
import org.apache.pdfbox.text.PDFTextStripper;

public class PdfReader {

    public static void main(String[] args) {
        try (PDDocument document = PDDocument.load(new File("C:\\Desktop\\sample.pdf"))) {
            if (!document.isEncrypted()) {

                PDFTextStripper tStripper = new PDFTextStripper();
                String pdfFileInText = tStripper.getText(document);
                String lines[] = pdfFileInText.split("\\r?\\n");
                for (String line : lines) {

        } catch (InvalidPasswordException e) {
        } catch (IOException e) {


Output :

If a country is to be corruption free and become a nation of beautiful minds, I strongly feel there
are three key societal members who can make a difference. They are the father, the mother and
the teacher.

A. P. J. Abdul Kalam


Reference :

PDFBox by Apache

Happy Learning 🙂