title: Render a View without loading in the browser - cakephp
body: <p>I am wondering if it is possible to render an action's view without loading in the browser?</p>
  
  <p>I'm using a cakephp component that used mPDF to generate PDF files. The component works well if you load the action and view in a browser but when I want to generate and save the pdf to the drive it doesn't seem to kick in, I'm assuming it's because the view isn't loaded property.</p>
  
  <p>The component I am using is: <a href="https://github.com/segy/Mpdf" rel="nofollow">https://github.com/segy/Mpdf</a></p>
  
  <p>So basically I have a function called mail_merge which generates a pdf using the mentioned component, I need to call the mail_merge function from another function within the same controller to generate the pdf but without loading in the browser. </p>
  
  <p>Thanks</p>
  
  <p>UPDATE:</p>
  
  <p>I worked out how to set the view as a variable and then write it to the pdf in the function.</p>
  
  <p>ADDED THIS:</p>
  
  <pre><code>// RENDER THE VIEW AND SET AS A VARIABLE TO WRITE THE HTML
  // ---------------------------------------------------------------------------&gt;
  $response = $this-&gt;render('mail_merge');
  $thebody = $response-&gt;body();
  $this-&gt;Mpdf-&gt;WriteHTML($thebody);
  </code></pre>
  
  <p>Unfortunately my PDF still won't generate so I guess the issue is something else.</p>