Java pdf reader Example | PDFBox Java pdf reader - onlinetutorialspoint

PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
JAVAEXCEPTIONSCOLLECTIONSSWINGJDBC
EXCEPTIONS
COLLECTIONS
SWING
JDBC
JAVA 8
SPRING
SPRING BOOT
HIBERNATE
PYTHON
PHP
JQUERY
PROGRAMMINGJava ExamplesC Examples
Java Examples
C Examples
C Tutorials
aws
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.
Lets see how to work with PDFBox in java application. To work with PDFBox we need to have the pdfbox dependency.
We should include the below maven dependency in pom.xml
[xml]
<dependency>
      <groupId>org.apache.pdfbox</groupId>
      <artifactId>pdfbox</artifactId>
      <version>2.0.6</version>
</dependency>
[/xml]
I am going to read the below pdf from Java application.
[java]
package com.onlinetutorialspoint.pdfbox;
import java.io.File;
import java.io.IOException;
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"))) {
            document.getClass();
            if (!document.isEncrypted()) {
                PDFTextStripper tStripper = new PDFTextStripper();
                String pdfFileInText = tStripper.getText(document);
                String lines[] = pdfFileInText.split("\\r?\\n");
                
                for (String line : lines) {
                    System.out.println(line);
                }
            }
        } catch (InvalidPasswordException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
[/java]
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
 
PDFBox by Apache
Happy Learning 🙂

PDFBox – How to generate Encrypted pdf in Java
count number of lines characters and words in a file Java
Java – How to read CSV file and Map to Java Object
Java – How to Convert InputStream to String
JAXB XML to Java Object Conversion Example
JAXB Java Object to XML Conversion Example
Apache Solr- Delete Documents from Solr using SolrJ
Java How to create Jar File ?
Java Swing JLabel Example
Apache Solr – How to Add Documents to Solr using SolrJ
Java Class Example Tutorials
How HashMap Works In Java
Comparable in Java
ArrayList in Java
Java MD5 Encryption Example

PDFBox – How to generate Encrypted pdf in Java
count number of lines characters and words in a file Java
Java – How to read CSV file and Map to Java Object
Java – How to Convert InputStream to String
JAXB XML to Java Object Conversion Example
JAXB Java Object to XML Conversion Example
Apache Solr- Delete Documents from Solr using SolrJ
Java How to create Jar File ?
Java Swing JLabel Example
Apache Solr – How to Add Documents to Solr using SolrJ
Java Class Example Tutorials
How HashMap Works In Java
Comparable in Java
ArrayList in Java
Java MD5 Encryption Example
 


Δ
 Install Java on Mac OS
 Install AWS CLI on Windows
 Install Minikube on Windows
 Install Docker Toolbox on Windows
 Install SOAPUI on Windows
 Install Gradle on Windows
 Install RabbitMQ on Windows
 Install PuTTY on windows
 Install Mysql on Windows
 Install Hibernate Tools in Eclipse
 Install Elasticsearch on Windows
 Install Maven on Windows
 Install Maven on Ubuntu
 Install Maven on Windows Command
 Add OJDBC jar to Maven Repository
 Install Ant on Windows
 Install RabbitMQ on Windows
 Install Apache Kafka on Ubuntu
 Install Apache Kafka on Windows
 Java8 – Install Windows
 Java8 – foreach
 Java8 – forEach with index
 Java8 – Stream Filter Objects
 Java8 – Comparator Userdefined
 Java8 – GroupingBy
 Java8 – SummingInt
 Java8 – walk ReadFiles
 Java8 – JAVA_HOME on Windows
 Howto – Install Java on Mac OS
 Howto – Convert Iterable to Stream
 Howto – Get common elements from two Lists
 Howto – Convert List to String
 Howto – Concatenate Arrays using Stream
 Howto – Remove duplicates from List
 Howto – Filter null values from Stream
 Howto – Convert List to Map
 Howto – Convert Stream to List
 Howto – Sort a Map
 Howto – Filter a Map
 Howto – Get Current UTC Time
 Howto – Verify an Array contains a specific value
 Howto – Convert ArrayList to Array
 Howto – Read File Line By Line
 Howto – Convert Date to LocalDate
 Howto – Merge Streams
 Howto – Resolve NullPointerException in toMap
 Howto -Get Stream count
 Howto – Get Min and Max values in a Stream
 Howto – Convert InputStream to String