title: mPDF - No PDF generated when called from within another function
body: <p>I have a mail_merge function (using cakephp) which when called directly from the browser e.g.
  domain.com/contacts/mail_merge will generate the PDF and save it to the server as needed with the database mapped fields.</p>
  
  <p>When however I try to call this mail_merge function from another function. e.g. $this->mail_merge($cond, 1); The PDF won't generate. The database fields are still coming though to the mail_merge function so it's not this issue. Any idea why this might be happening? I have updated my code below to now include a simple generated txt file with the code I am trying to put onto the PDF and this works so there is simply something about mPDF that won't generate a PDF when called from a function.</p>
  
  <p>Thanks</p>
  
  <p>My mail_merge function is as follows:</p>
  
  <pre><code>// FUNCTION GENERATE MAIL MERGE - mPDF
  // --------------------------------------------------------------&gt;
  function mail_merge($conditions=NULL, $mail_merge_id=1)
  {
      // REMOVE THE STANDARD LAYOUT
      // ------------------------------------------------------&gt;
      $this-&gt;layout = null;
  
      // GET THE CONTACTS
      // -------------------------------------------------------------&gt;
      $contacts = $this-&gt;Contact-&gt;Card-&gt;find('all', array(
                                                    'limit' =&gt; 10, 
                                                    //'fields' =&gt; $fields,
                                                  'contain' =&gt; array('Contact', 'Prospect', 'SaleDetail'),
                                                    'conditions' =&gt; $conditions
                                                    ));
      $this-&gt;set('contacts', $contacts);
  
      // GE THE CONTENTS
      // ------------------------------------------------------------&gt;
      $this-&gt;loadModel('MailMerge');
      $content = $this-&gt;MailMerge-&gt;find('first', array(
                                                  'conditions' =&gt; array('MailMerge.id' =&gt; $mail_merge_id),
                                                  'fields' =&gt; array('MailMerge.description')
                                                  ));
      $this-&gt;set('content', $content);
  
      // initializing mPDF
      // ---------------------------------------------------------------------------&gt;
      $this-&gt;Mpdf-&gt;init();
  
      // 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);
  
      // setting filename of output pdf file
      // ---------------------------------------------------------------------------&gt;
      $thefilename = "mail_merge_".date("d.m.Y_His").".pdf";
      $this-&gt;Mpdf-&gt;setFilename(APP. WEBROOT_DIR . "/files/csv_exports/" . $thefilename); 
  
      // setting output to I, D, F, S
      // ---------------------------------------------------------------------------&gt;
      $this-&gt;Mpdf-&gt;setOutput('F');
  
      // TEMP - CREATE TXT FILE ON THE SERVER
      // ------------------------------------------------------------------------&gt;
      $thefilenametxt = "mail_merge_".date("d.m.Y_His").".txt";
      $ourFileHandle = fopen(APP. WEBROOT_DIR . "/files/csv_exports/" . $thefilenametxt, 'w');
      fwrite($ourFileHandle, $thebody); 
      fclose($ourFileHandle); 
  
      return $thefilename;
  
  } // END MAIL MERGE
  </code></pre>