<?php
/**
* Esta función devuelve el número de páginas de un archivo pdf
* Tiene que recibir la ubicación y nombre del archivo
*/
function numeroPaginasPdf($archivoPDF)
{
$stream = fopen($archivoPDF, "r");
$content = fread ($stream, filesize($archivoPDF));
if(!$stream || !$content)
return 0;
$count = 0;
$regex = "/\/Count\s+(\d+)/";
$regex2 = "/\/Page\W*(\d+)/";
$regex3 = "/\/N\s+(\d+)/";
if(preg_match_all($regex, $content, $matches))
$count = max($matches);
return $count[0];
}
echo numeroPaginasPdf("file1.pdf");
echo "<br>".numeroPaginasPdf("img/file2.pdf");
?>
Comentarios sobre la versión: Versión 1.0 (4)
Además me gustaría aprender más sobre las expresiones por lo tanto cualquier información sobre ellas será bien recibida (me refiero a esto "/\/Count\s+(\d+)/")
Muchísimas Gracias.