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



## thomas6188 (Jan 6, 2011)

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


```
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


----------



## quicklyjava (Oct 7, 2012)

You can also refer to the tutorial series here covering different features of iText:

PDF Generation in Java: iText Tutorial - QuicklyJava



thomas6188 said:


> 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 :
> 
> ...


----------

