php imagick庫處理pdf問題

來源:互聯網
上載者:User
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

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.