In this tutorial, you will learn php get number pages pdf file. let’s discuss about how to get number of pages in pdf file using php. you will learn php count number of pages in pdf. This post will give you simple example of php count pages in pdf. you will do the following things for 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...
Do you like below Tutorials ?
- Multidimensional Array Search By Value in PHP
- Laravel Install Font Awesome Icons Example
- How to Use Moment JS in Laravel?
- Angular 9 Get Environment Variables Example
- Angular Delete a Component From Cli Example
- How to Upload File from Local to Server using SSH?
- Angular Use CKEditor Example Tutorial
- How to Use Multiple Select Dropdown in Laravel?