Home > Java > Extracting text from PDF in Java using apache PDFBox

Extracting text from PDF in Java using apache PDFBox

 What does Apache PDFBox offer:

  1. Apache PDFBox is an open-source Java library that allows to work with PDF documents programmatically.
  2. It provides a wide range of features for creating, manipulating, and extracting data from PDF files.
  3. PDFBox supports various operations, including text extraction, image extraction, metadata extraction, and more.

Setting up Apache PDFBox:

To get started, you need to set up Apache PDFBox in your Java project.

  • You can download the latest version of PDFBox from the Apache PDFBox website (pdfbox.apache.org) and include the necessary JAR files in your project’s classpath.
  • Use maven to include the necessary dependencies in your project’s build configuration. Here is the Maven dependency for PDFBox:

         <dependency>

          <groupId>org.apache.pdfbox</groupId>

           <artifactId>pdfbox</artifactId>

           <version>2.0.28</version>

         </dependency>

Code for Extracting Text from PDF:

PDDocument document = PDDocument.load(new File(“input.pdf”));

PDFTextStripper stripper = new PDFTextStripper();

String text = stripper.getText(document);

document.close();

Conclusion:

You can similarly try out PDFBox for image extraction, metadata extraction from the PDF.

This Article is TAGGED in , , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">