Java code// 搜索pdf
public List searchPdfFile(String keyword,List items) throws IOException {
File f = new File("/sdcard/LPR/lpr_pdf/");// 这是对应文件名
File[] fileList = f.listFiles();
PDDocument document = null;
for(File filePdf : fileList)
{
Toast.makeText(EntAppSea.this, filePdf.getName(),
Toast.LENGTH_LONG).show();
PDFTextStripper stripper = new PDFTextStripper();
document = PDDocument.load(filePdf);
int pageNum = document.getNumberOfPages();
Toast.makeText(EntAppSea.this, String.valueOf(pageNum),
Toast.LENGTH_LONG).show();
for(int i=1;i<=pageNum;i++)
{
stripper.setStartPage(i);
stripper.setEndPage(i+1);
String pdfStr = stripper.getText(document);
if(pdfStr.indexOf(keyword)>-1)
{
items.add(filePdf.getName()+"第"+i+"页");
}
}
}
return items;
}