title: How to convert a multi-page PDF to images using ImageMagick for PHP?
body: <p>I want to convert the pdf file into images. I am using ImageMagick for image conversion in cakePHP.  </p>
  
  <p>When I take a PDF with a single page, its gets converted into image but the problem is when I take a PDF with multiple pages, then only the last page of the document is getting converted to image, instead of all pages.  </p>
  
  <p>How can I fix this?</p>
  
  <p>This is the code I have.</p>
  
  <pre><code> public function convertToImage() {  
       $this-&gt;layout = "ajax";
  
          $uploadfile=APP.WEBROOT_DIR.DS.'files'.DS.$this-&gt;request-&gt;data['f'];
          $uploaddir=APP.WEBROOT_DIR.DS.'files'.DS.'images'.DS;
          $im = new imagick();
          $im-&gt;setResolution(80,80);
          $im-&gt;readimage($uploadfile);//."[0]");
          $im-&gt;setImageFormat('jpeg');
          $image_name = $this-&gt;request-&gt;data['f'].".jpg";
          $imageprops = $im-&gt;getImageGeometry();
          if ($imageprops['width'] &lt;= 1275 &amp;&amp; $imageprops['height'] &lt;= 1650) {
              // don't upscale
           } else {
               $im-&gt;resizeImage(1275,1650, imagick::FILTER_LANCZOS, 0.9, true);
           }
  
  
          $im-&gt;writeImage($uploaddir .$image_name);
          $im-&gt;clear();
          $im-&gt;destroy();exit;
   }  
  </code></pre>