DIGIT-ARC read-only archive · snapshot: July 23, 2026

Java Tutorial 1: Read a pdf file in Java using iText library

2 posts · originally from https://geek.digit.in/community/threads/java-tutorial-1-read-a-pdf-file-in-java-using-itext-library.135755/

T
thomas6188 Original post #1
Jan 6, 2011 at 10:18 AM
Hi,
This is a basic tutorial in java, that shows how to read a pdf file. For this we use a library called iText . Using iText library, we can perform various pdf operations that it supports.
In this section , we are dealing with calculating the no. of pages & extracting the contents of each individual page.The steps are given below :

Add the iText library, by adding iText.jar to the lib folder of the project.
Use the following code to extract the content

Code:
        PdfReader reader = new PdfReader(INPUTFILE);
        int n = reader.getNumberOfPages();
      
  String str=PdfTextExtractor.getTextFromPage(reader, 2); //Extracting the content from a particular page.
            System.out.println(str);
Note: This program extracts only the text part and not the images.

Hope this program helps you start with basic pdf editing. Do revert back for queries
Q
Oct 7, 2012 at 8:10 PM
You can also refer to the tutorial series here covering different features of iText:

PDF Generation in Java: iText Tutorial - QuicklyJava

Hi,
This is a basic tutorial in java, that shows how to read a pdf file. For this we use a library called iText . Using iText library, we can perform various pdf operations that it supports.
In this section , we are dealing with calculating the no. of pages & extracting the contents of each individual page.The steps are given below :

Add the iText library, by adding iText.jar to the lib folder of the project.
Use the following code to extract the content

Code:
        PdfReader reader = new PdfReader(INPUTFILE);
        int n = reader.getNumberOfPages();
      
  String str=PdfTextExtractor.getTextFromPage(reader, 2); //Extracting the content from a particular page.
            System.out.println(str);
Note: This program extracts only the text part and not the images.

Hope this program helps you start with basic pdf editing. Do revert back for queries