We are moved to new domain
Click -> www.ehowtonow.com
Friday, 26 May 2017

Read PDF file using iText 5

This example explain about how to read PDF file using iText 5 PDF Library.
To read PDF file we need iText 5 jar. Download iText Jars from iText Website or Maven Repository

Maven Dependency



    com.itextpdf
    itextpdf
    5.5.11

 
ReadPDF.java
package com.javatutorialcorner.itextpdf;

import java.io.IOException;

import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfTextExtractor;

public class ReadPDF {
 public static final String DEST = "C:/JTC/HelloWorld.pdf";

 public static void main(String[] args) {

  PdfReader pdfReader;

  try {

   pdfReader = new PdfReader(DEST);

   int pageCount = pdfReader.getNumberOfPages();
   System.out.println("Page Count : " + pageCount);

   // extract page 1
   String textFromPDF = PdfTextExtractor.getTextFromPage(pdfReader, 1);

   System.out.println(textFromPDF);

   pdfReader.close();

  } catch (IOException e) {
   e.printStackTrace();
  }

 }
}

Output
Page Count : 1
This example explain about how to create PDF file using iText 5 PDF Library. - Java Tutorial
Corner


Shop and help us

Flipkart Offer Snapdeal offer Amazon.in offer Amazon.com offer
  • Blogger Comments
  • Facebook Comments
  • Disqus Comments

0 comments:

Post a Comment

Item Reviewed: Read PDF file using iText 5 Rating: 5 Reviewed By: eHowToNow