Domanda

I have to generate Pdf of images. 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". Can anybody helps me in this or simply point out what's wrong with this code.

È stato utile?

Soluzione

You probably do not have required permissions. Look if file is_readable and if not try chmod it. You can also always change file permissions on your windows.

Edit1: Change your code:

$numPaths = count($paths);
for($i=0; $i < $numPaths; $i++) {
.. 
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top