How to Read PDF file using PDFBox in Java

Reading PDF file using PDFBox API

In this example, We will show you sample program about, How to read PDF file using PDFBox in Java. The example program has been tested and shared in the same post.

Maven Dependency


Example Program

package com.dineshkrish;


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

 * @author Dinesh Krishnan

public class PDFReader {

	public static String read(final File pdfFile) {

		String text = null;
		PDDocument document = null;
		try {
			document = PDDocument.load(pdfFile);

			PDFTextStripperByArea stripper = new PDFTextStripperByArea();


			PDFTextStripper pdfTextStripper = new PDFTextStripper();

			text = pdfTextStripper.getText(document);

		} catch (InvalidPasswordException e) {

		} catch (IOException e) {

		return text;
	public static void main(String[] args) {

		final String fileName = "input.pdf";
		File pdfFile = new File(fileName);



Oct 06, 2017 1:24:05 PM org.apache.pdfbox.pdmodel.font.PDCIDFontType2 <init>
INFO: OpenType Layout tables used in font ABCDEE+Calibri are not implemented in PDFBox and will be ignored
“The real 
opportunity for 
success lies 
within the 
person and not 
in the job” 


1. Apache PDF Examples
2. Apache PDFBox

Hello, folks, I am a founder of I love Java and Open source technologies, If you find my tutorials are useful, please consider making donations to these charities.