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>';
}
$seconddatebut the file being saved near the end uses$firstdatetwice. So the file being generated is not the same as the file being linked.