How to read PDF File Contents using Selenium WebDriver?

package pkg_selenium;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;
import org.openqa.selenium.WebDriver;

public class PDFReader {

public static WebDriver driver;

public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub

PDDocument pd;
pd = PDDocument.load(new File("D:\\selenium\\VS-1083_Certified Selenium Professional_Reading_Material.pdf"));
System.out.println("Total Number Of pages :"+pd.getNumberOfPages());

PDFTextStripper pdf = new PDFTextStripper();
System.out.println(pdf.getText(pd));



}

}


Note :-

  • Two JAR Files are required.
  1. pdfbox-1.8.5.jar
  2. fontbox-1.8.5.jar
  • The above tow JAR files must be added to the referenced libraries.

Comments

Popular posts from this blog

Encoding and Decoding in Selenium using Base64 Class of Java

Parallel Execution In TestNG Framework Using ThreadLocal Concept

How to handle calendar or date picker using dynamic XPATH?