Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read pdf using iText

Tags:

java

itext

I am getting problem to read pdf files using iText in java. I can read only one page but when I go to second page it gives exception.I want to read all the pages of any pdf file.

PdfTextExtractor parser =new PdfTextExtractor(new PdfReader("C:/Text.pdf"));
parser.getTextFromPage(3);

I am using these lines and at second line gives exception.

like image 723
Sunil Avatar asked Oct 28 '09 14:10

Sunil


1 Answers

  1. Try changing the file location. Sometimes OS does not allow file to be read from some system drives by other applications. Put somewhere in D: etc. I face this problem in Vista when reading files from desktop.

  2. I in fact ran the same two lines of code on one of my PDF and it did print the text. Also make sure you have sufficient pages in the PDF. (3 pages or more) or try with parser.getTextFromPage(1) etc. to get content from other pages.

like image 189
Kushal Paudyal Avatar answered Oct 01 '22 05:10

Kushal Paudyal