In this article, we will learn how we can count pages in PDF


Example

create index.php file and put the following code


index.php

<?php
//create function to count pages
function pdfPageCounter($file) {
    $pdfC = file_get_contents($pdf);
    $num = preg_match_all("/\/Page\W/", $pdfC, $pdf);
    return $num;
}

//call the function and echo it
echo pdfPageCounter("dummy.pdf");


?>

pdfPageCounterror function will help you to get the number of pages from the PDF file. Code has been 100% tested & it will work for you.