Search in Pdf Store At system using Java in Selenium
Jars Used:
itextpdf-5.1.0.jar
Java Code:
String texttosearch="Account";
boolean searchResult=false;
PdfReader reader =new PdfReader("C:\\ruchi\\A1.pdf");
PdfReaderContentParser parser= new PdfReaderContentParser(reader);
TextExtractionStrategy strategy;
for(int i=1;i<=reader.getNumberOfPages();i++);
{
strategy =parser.processContent(i,new SimpleTextExtractionStrategy());
if(strategy.getResultantText().indexOf(textToSearch)>-1)
{
searchResult= true;
break;
}
}
if(searchResult)
{
System.out.println("Search SuccessFull!!!");
}
else
{
System.out.println("Search SuccessFull!!!");
}