title: CakePHP controller to save a image as pdf
body: <p>I have a CakePHP controller that is taking a URL and turning it into a PDF by first turning it into an image. The PDF is being generated properly via TCPDF, but it is only displaying it. How can I save the PDF file on the server instead of just displaying it?  </p>
  
  <pre><code>&lt;?php
  App::import('Vendor', 'TestPdf.tcpdf', array('file'=&gt;'tcpdf'.DS.'tcpdf.php'));
  
  $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  $pdf-&gt;SetMargins(0, 0, 0);
  $pdf-&gt;SetAutoPageBreak(false);
  $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  
  foreach($pages as $page)
  {
      $pdf-&gt;AddPage();
      $pdf-&gt;setJPEGQuality("100");
      $pdf-&gt;Image($page, 0, 0, 210, 0, 'PNG', '', '', false, 300);
  }
  
  
  $pdf-&gt;Output('example_001.pdf', 'I');
  </code></pre>