Для определения количества страниц в PDF документе считываем файл построчно и ищем управляющую конструкция /Count число
$filename = 'файл.pdf';
$fp = fopen($filename, 'r');
if ($fp) {
$count = 0;
while(!feof($fp)) {
$line = fgets($fp,255);
if (preg_match('|/Count [0-9]+|', $line, $matches)){
preg_match('|[0-9]+|', $matches[0], $matches2);
if ($count < $matches2[0]) {
$count = trim($matches2[0]);
}
}
}
fclose($fp);
echo "Страниц: {$count}";
}
Ссылки
Источник: https://www.kobzarev.com/programming/php-the-number-of-pages-in-a-pdf-document/