如何通过PHP或imagemagick检测多页PDF?
问题描述:
For instance, when I uploaded a file to the temp folder on server, are there any way to scan through the folder and check whether a specific file is multi page or not?
Some code like:
$files = scandir ('$tempSrc');
foreach ($files as $pdf) {
$isMulti = //exec some command or call php function (if any?);
echo $isMulti;
}
例如,当我将文件上传到服务器上的temp文件夹时,有没有办法扫描文件夹 并检查特定文件是否是多页? p>
一些代码如: p>
$ files = scandir('$ tempSrc' );
Nachach($ files as $ pdf){
$ isMulti = //执行某些命令或调用php函数(如果有的话)?;
echo $ isMulti;
}
code> pre >
div>
答
You can use http://php.net/manual/en/class.imagick.php php class.
$files = scandir ('$tempSrc');
foreach ($files as $pdf) {
$im = new Imagick();
$im->pingImage($pdf);
echo $isMulti = ($im->getNumberImages() > 1) ? true : false;
}