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));
}
}
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.
- pdfbox-1.8.5.jar
- fontbox-1.8.5.jar
- The above tow JAR files must be added to the referenced libraries.
Comments
Post a Comment