Home  >  Article  >  Backend Development  >  php imagick库处理pdf问题

php imagick库处理pdf问题

WBOY
WBOYOriginal
2016-06-23 14:01:561915browse

PHP

Fatal error: Uncaught exception 'ImagickException' with message 'unable to open image `papers/1375680721.pdf': No such file or directory @ error/blob.c/OpenBlob/2622' in C:\xampp\htdocs\fc\editpaper.php:38 Stack trace: #0 
C:\xampp\htdocs\fc\editpaper.php(38): Imagick->readimage('papers/13756807...') #1 C:\xampp\htdocs\fc\editpaper.php(108): pdf2png('papers/13756807...', 'papers/', 0) #2 C:\xampp\htdocs\fc\editpaper.php(211): anli->insert('') #3 {main} thrown in C:\xampp\htdocs\fc\editpaper.php on line 38

报如下错误
function pdf2png($PDF,$toPath,$page){   	if(!extension_loaded('imagick')){		echo "imagick";		return false;   	}   	if(!file_exists($PDF)){		echo "noexists";		return false;   	}	$IM = new imagick();   	$IM->setResolution(1000,2000);   	$IM->setCompressionQuality(100);   	$IM->readImage($PDF."[".$page."]");	foreach ($IM as $Key => $Var){		$Var->setImageFormat('png');       		$Filename = $toPath.time().'_'.$Key.'.png';       		if($Var->writeImage($Filename) == true){           			$Return[] = $Filename;       		}	}	return $Return;}

回复讨论(解决方案)

他说的很明确了,papers/1375680721.pdf 不存在

他说的很明确了,papers/1375680721.pdf 不存在 不是这个原因,文件是存在的

 'unable to open image `papers/1375680721.pdf': No such file or directory
“无法打开图像papers/1375680721.pdf”:没有这样的文件或目录

 'unable to open image `papers/1375680721.pdf': No such file or directory
“无法打开图像papers/1375680721.pdf”:没有这样的文件或目录
@ error/blob.c/OpenBlob/2622' 这个错误是什么意思?

 'unable to open image `papers/1375680721.pdf': No such file or directory
“无法打开图像papers/1375680721.pdf”:没有这样的文件或目录
if(!file_exists($PDF)){        echo "noexists";        return false;       }
如果文件真不存在,过不了这个判断的

看看是不是文件权限问题,把papers/1375680721.pdf,权限设成777

看看是不是文件权限问题,把papers/1375680721.pdf,权限设成777 也不是权限问题,我怀疑是imagemagick有问题,我打开imagemagick把pdf文件丢进去,提示

if(!file_exists($PDF)) 只是检查了 $PDF 指向的文件是否存在
而你打开 pdf 的语句是 $IM->readImage($PDF."[".$page."]");
显然 $PDF 和 $PDF."[".$page."]" 不是一回事
你的这个写法是从哪里看来的?请给出出处!
我搜索到的相关代码中都没有见到这个写法
如果说 $PDF."[".$page."]" 是表示 $PDF 的第 $page 也得话,那么若 $page 所表示的页不存在的话,是否也应该报错呢?

我没有 imagick 环境,无法测试。只是按常理推导

Windows系统下运行,还需要装一个安装软件ghostscript;下载地址:http://downloads.ghostscript.com/public/gs904w32.exe  ; 祝你成功。



 'unable to  open image `papers/1375680721. pdf': No such file or directory
“无法打开图像papers/1375680721.pdf”:没有这样的文件或目录
if(!file_exists($PDF)){        echo "noexists";        return false;       }
如果文件真不存在,过不了这个判断的

要不,你看下这个帖子吧,好像也是类似的问题

http://stackoverflow.com/questions/4637251/unable-to-open-image-error-when-using-imagemagicks-filename-references

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn