Test in a live environment
Test in production without watermarks.
Works wherever you need it to.
Reading a PDF document in Java can be an integral part of any project, ranging from business applications to data analytics. With the IronPDF library, it has become easier than ever before to integrate PDF processing capabilities in your Java projects.
fromFile
methodextractAllText
Method to Read Text from the Opened PDFIrotPDF Java PDF Library Overview is the perfect solution for Software Developers who need to produce high-quality, capture-ready PDFs quickly from HTML. The library also provides powerful document manipulation tools that enable dynamic control over page layout and formatting in IronPDF, content, and formatting.
Let's see how to read a PDF file stored at a path in a Java program using the IronPDF library.
The first step is to install IronPDF using Maven, more details can be found in the IronPDF Installation Guide.
Here are the steps to install IronPDF in a Maven project:
In the pom.xml
file, add the IronPDF library dependency in the dependencies
section.
<dependency>
<groupId>com.ironsoftware</groupId>
<artifactId>com.ironsoftware</artifactId>
<version>2024.11.4</version>
</dependency>
pom.xml
file and let Maven download and install the IronPDF library.Once the installation is complete, you should be able to import and use the IronPDF's following classes and Apache Tika parsers in your project.
Here is the code which you can use to read the new file with or without tabular boundaries using the IronPDF library.
import com.ironsoftware.ironpdf.*;
import java.io.IOException;
import java.nio.file.Paths;
public class Test {
public static void main(String[] args) throws IOException {
PdfDocument pdf = PdfDocument.fromFile(Paths.get("C:\\sample.pdf"));
String text = pdf.extractAllText();
System.out.println(text);
}
}
In this program, the PdfDocument class in IronPDF
is used to read the contents of a PDF file. The first line of the program imports the required classes from the IronPDF library. The second line imports the IOException
class from the Java standard library.
The program defines a public class named Test
. Inside the class, there is a public static
method named main
that takes an array of strings as an argument.
The main
method uses the fromFile method of PdfDocument in IronPDF
method of the PdfDocument
class to load a PDF file located at "C:\sample.pdf". This method returns a PdfDocument
object that represents the PDF file.
Once the PDF file is loaded, the program calls the [extractAllText method of PdfDocument in IronPDF
](/java/object-reference/api/com/ironsoftware/ironpdf/PdfDocument.html#extractAllText()) method of the PdfDocument
class to extract all the text from the PDF file. This method returns a String
that contains all the text in the PDF file.
The extracted text is then stored in a String
variable named "text". This variable can be used to process or display the contents of the PDF file.
Finally, the program prints the extracted text to the console using the System.out.println
method.
Program Output
IronPDF is a great solution for reading PDF files within the same path or multiple different paths in Java, as it offers high performance and many features that make developing PDFs easily. Its syntax is straightforward and user-friendly. Its API allows developers to quickly craft the code that they need for their projects.
Explore IronPDF Licensing Options plans start from just $749, making it accessible to extract content for those on a budget. Overall, IronPDF provides an excellent option for any Java developer looking to work with PDFs in their Java applications programming.
9 .NET API products for your office documents