开发者

Imagemagick page count function with PDF version 1.5 onwards - PHP

I am running Apache/2.2.17 (Win32) PHP/5.3.0 in my Windows Vista PC. I have imagemagick configured. I have a php function to count pages in a PDF file as follows;

<?php
$filepath = "test.pdf";

function getNumPagesPdf($filepath){
    $fp = @fopen(preg_replace("/\[(.*?)\]/i", "",$filepath),"r");
    $max=0;
    while(!feof($fp)) {
            $line = fgets($fp,255);
            if (preg_match('/\/Count [0-9]+/', $line, $matches)){
                    preg_match('/[0-9]+/',$matches[0], $matches2);
          开发者_如何转开发          if ($max<$matches2[0]) $max=$matches2[0];
            }
    }
    fclose($fp);
    if($max==0){
        $im = new imagick($filepath);
        $max=$im->getNumberImages();
    }

    return $max;
}

echo getNumPagesPdf($filepath);
?>

The code works just file for PDF files up to PDF files having version 1.4. It is not working for PDF files having version 1.5 onwards.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜