0

I am using mpdf to generate pdf file using output buffering. There is no problem of generating pdfs outside the function. The problem is, it couldn't generate a pdf inside a function. No pdf file is generated. The data to be included in the pdf is image files in the foreach loop below.

include("search/mpdf/mpdf.php");
function generatecont ($firstdate, $seconddate, $allfiles) {
  echo '<div class="displayoutput" style="display:none;">';
  echo "<a href='data/pdf/".$_GET["parameter"].'-'.$firstdate .'-'. $seconddate. '.pdf' ."'>Download PDF </a>"; 
 //include("search/mpdf/mpdf.php");
  global $html;
  global $mpdf;
  $mpdf=new mPDF();
  ob_start(); 
  foreach ($allfiles as $filesfound) {  
      echo '<h1 class="displaytitle">'.strtoupper(substr(basename($filesfound), 0,-4)). '</h1>';
      echo '<div class="visualize">'.'<img src="'. $filesfound. '"></div>';
  }
  $html = ob_get_contents();
  ob_get_flush();
  $mpdf->WriteHTML($html);
  $mpdf->Output('data/pdf/'.$_GET["parameter"].'-'.$firstdate .'-'. $firstdate. '.pdf','F');
  echo '</div>';
}
5
  • Could you clarify your question? What is the issue? What is showing up onscreen? What is the function generatecont() supposed to return? Commented Oct 18, 2014 at 4:16
  • Thank you. I have updated my question. The function is supposed to generate the pdf and other contents. Is it clear now? Commented Oct 18, 2014 at 5:29
  • I would check permissions as a start, and any output/log messages. Also, the link generated in the first part uses $seconddate but the file being saved near the end uses $firstdate twice. So the file being generated is not the same as the file being linked. Commented Oct 18, 2014 at 23:19
  • Very nice observation! It is solved now when I corrected the file name to be generated. Thank you! Please post it as an answer. Commented Oct 19, 2014 at 0:15
  • Good to know. Thanks! Have added it now. Commented Oct 19, 2014 at 0:21

1 Answer 1

1

I would check permissions as a start, and any output/log messages. Also, the link generated in the first part uses $seconddate but the file being saved near the end uses $firstdate twice. So the file being generated is not the same as the file being linked.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.