The idea is that through a simple search form, you can return the requested search by searching several PDFs of a directory, that search engine has to search within the pdf that are text, generally I do everything in PHP, but if I have to use Javascript, there's no problem. I did something similar with PHP strpos looking at a plain txt, but if I do that with PDF it does not work because it is binary.
Well, I almost got what I want, only now the search engine has some words that can not be found, the code looks like this:
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<form action="" method="post">
<input type="text" name="buscar">
<input type="submit" name="Submit" value="Buscar">
</form>
<?php
if(isset($_POST['Submit'])) {
include_once('class.pdf2text.php');
$directorio = opendir("./pdf"); //ruta actual
while ($archivo = readdir($directorio)) //obtenemos un archivo y luego otro sucesivamente
{
$url = 'pdf/'.$archivo;
$a = new PDF2Text();
$a->setFilename($url);
$a->decodePDF();
$pdf = utf8_encode($a->output());
$larCharsNoAble = array("Ñ","á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","À","Ã","Ì","Ò","Ù","Ù","à ","è","ì","ò","ù","ç","Ç","â","ê","î","ô","û","Â","Ê","ÃŽ","Ô","Û","ü","ö","Ö","ï","ä","«","Ò","Ã","Ä","Ë");
$larCharsAble = array("N","a","e","i","o","u","A","E","I","O","U","n","N","A","E","I","O","U","a","e","i","o","u","c","C","a","e","i","o","u","A","E","I","O","U","u","o","O","i","a","e","U","I","A","E");
$texto = str_replace($larCharsNoAble, $larCharsAble, $pdf);
$cadena_solicitada = $_POST['buscar'];
$larCharsNoAble = array("Ñ","á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","À","Ã","Ì","Ò","Ù","Ù","à ","è","ì","ò","ù","ç","Ç","â","ê","î","ô","û","Â","Ê","ÃŽ","Ô","Û","ü","ö","Ö","ï","ä","«","Ò","Ã","Ä","Ë");
$larCharsAble = array("N","a","e","i","o","u","A","E","I","O","U","n","N","A","E","I","O","U","a","e","i","o","u","c","C","a","e","i","o","u","A","E","I","O","U","u","o","O","i","a","e","U","I","A","E");
$post = str_replace($larCharsNoAble, $larCharsAble, $cadena_solicitada);
$posicion_coincidencia = stripos($texto, $post);
if ($posicion_coincidencia == true) {
echo 'Se ha encontrado "'.$post.'"" en el archivo <a href="'.$url.'">'.$archivo.'</a><br>';
}
}
}
?>