简体   繁体   English

Zend_Pdf:问题与图像路径数组

[英]Zend_Pdf :Issues with array of image path

I have to generate Pdf of images. 我必须生成图像的Pdf。 I have tried the following code 我尝试了以下代码

  public function getPdf($paths)
 {
   try {
  $pdf = new Zend_Pdf(); 
  for($i=0; $i<5; $i++)
   {
   $page = new Zend_Pdf_Page(Zend_Pdf_Page::SIZE_A4);
    $image = Zend_Pdf_Image::imageWithPath($paths[$i]);  
    $page->drawImage($image, 20, 20, 50, 46);
    $pdf->pages[] = $page;
   }
   $pdf->save('document.pdf');
     echo 'SUCCESS: Document saved!';
    } catch (Zend_Pdf_Exception $e) {
     die ('PDF error: ' . $e->getMessage());  
     } catch (Exception $e) {
     die ('Application error: ' . $e->getMessage());    
    }
   }

Please note that $paths is an array which contains correct physical paths like C:/wamp/www/magento1.7/media/catalog/product/cache/1/small_image/9df78eab33525d08d6e5fb8d27136e95/p/o/portf1.jpg.... Now the problem is that it is not able to create Pdf and throws exception saying "PDF error: Cannot create image resource. File not found". 请注意$ paths是一个包含正确物理路径的数组,例如C:/wamp/www/magento1.7/media/catalog/product/cache/1/small_image/9df78eab33525d08d6e5fb8d27136e95/p/o/portf1.jpg ....现在的问题是,它无法创建Pdf,并引发异常,显示“ PDF错误:无法创建图像资源。找不到文件”。 Can anybody helps me in this or simply point out what's wrong with this code. 任何人都可以帮我这个忙,还是简单指出这段代码有什么问题。

You probably do not have required permissions. 您可能没有所需的权限。 Look if file is_readable and if not try chmod it. 查看文件is_可读性 ,如果不是,请尝试chmod You can also always change file permissions on your windows. 您也可以随时在Windows上更改文件权限。

Edit1: Change your code: 编辑1:更改您的代码:

$numPaths = count($paths);
for($i=0; $i < $numPaths; $i++) {
.. 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM