首页 > 解决方案 > 使用 php 和 pdf 解析器库在大文件夹中搜索 pdf 文件内容

问题描述

我正在使用 pdf 解析器在包含大量 pdf 文件的文件夹中搜索,以便在 pdf 文件内容中进行搜索。该代码仅适用于最多 3 个小尺寸文件:

$keyword = "Calibri";  //the keyword is dynamic

$dir = new DirectoryIterator('C:\wamp\www\pdfdemos\cv');
$parser = new \Smalot\PdfParser\Parser();
foreach ($dir as $file) {
    if($file->isFile() && $file->getExtension() =='pdf'){
        if ($file->getFilename() =="." || $file->getFilename() =="..") {
            continue;
        }else{
            echo "File name: ".$file->getFilename()."<br />";
            $pdf= $parser->parseFile('C:\wamp\www\pdfdemos/cv/'.$file->getFilename());
            $pages  = $pdf->getPages();
            $text = $pdf->getText();

            if(stripos(strtolower($text), $keyword)) {
                         echo "Keyword Matches";
                         echo "<br/><hr />";
                      }else{
                           echo "Keyword Not Matches";
                           unset($text);
                     }
        }
    }                                               

}

该代码最多可处理三个文件,否则我会收到消息“无法访问此站点”。我在本地工作,我正在使用 wamp 服务器 - 我正在使用 pdf 解析器库:https ://pdfparser.org 请帮助

标签: phpfilepdfsearchpdfparser

解决方案


推荐阅读