View Single Post
  #14 (permalink)  
Old 02-22-10, 02:51 PM
adrianbj adrianbj is offline
Newbie Coder
 
Join Date: Feb 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
I actually went with a combined approach. Since I have exec disabled on my server I wanted to stick with a PHP based solution, so ended up with this:

Code:
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;
}
If it can't figure things out because there are no Count tags, then it uses the imagick php extension. The reason I do a two-fold approach is because the latter is quite slow.
Reply With Quote