PHP Count Number of Pages in PDF File
In this post, i will give you simple example of how to get number of pages in pdf file using php. If you need to get number of pages in pdf using php then i will help you php count number of pages in pdf.
Sometime, we just need to count how many pages are there in pdf file and show it for our admin pane or front-end. So i will give you very simple example of getting calculate number of pages in pdf file using core php. you can also use in php, laravel, codeigniter framework too.
In this example we will create countPages() and it will take a one argument as path of pdf file. so just see bellow example for your solution.
Make Sure you have itsolutionstuff_file.pdf file in your pdf folder.
Example:
<?php
$path = 'pdf/itsolutionstuff_file.pdf';
$totoalPages = countPages($path);
echo $totoalPages;
function countPages($path) {
$pdftext = file_get_contents($path);
$num = preg_match_all("/\/Page\W/", $pdftext, $dummy);
return $num;
}
?>
Output:
7
I hope it can help you...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- PHP Get All Array Keys Starting with Certain String Example
- How to Convert XML File to Array in PHP?
- PHP Move File from One Folder to Another Example
- How to Partially Hide Email Address in PHP?
- How to Get Difference Between Two Dates in PHP?
- Laravel 6 Generate PDF File Tutorial
- How to Remove Multiple Keys from PHP Array?
- Laravel 11 Merge Multiple PDF Files Example
- PHP MySQL DataTables Server-side Processing Example
- Convert HTML to PDF in PHP with Dompdf Example
- PHP Capture Screenshot of Website from URL Example
- How to Convert Object into Array in PHP?
- How to Count Number of Files in a Directory in PHP?
- How to Remove Null Values from Array in PHP?