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

thomas6188

Broken In
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
 
Last edited:

quicklyjava

Right off the assembly line
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
 
Top Bottom