Skip to content

Instantly share code, notes, and snippets.

@paoga87
Created May 12, 2017 13:18
Show Gist options
  • Save paoga87/4e3ae2b83979206c89ae7e80788a2418 to your computer and use it in GitHub Desktop.
Save paoga87/4e3ae2b83979206c89ae7e80788a2418 to your computer and use it in GitHub Desktop.
Example of an automated sign-in sheet, providing users' information and generating a PDF automatically (when user requests it), using the mpdf PHP library
//MySQL queries and other code to generate the $users array ommited
//==============================================================
//==============================================================
//==============================================================
$todayDate = date('m.d.y');
$fileName = 'Sign-In Sheet ' .$todayDate . '.pdf';
include("mpdf60/mpdf.php");
$mpdf=new mPDF('c', 'Letter', 0, '', 0, 0, 0, 0, 0, 0);
$mpdf->SetDisplayMode('fullpage');
$mpdf->AddPage();
$mpdf->WriteHTML($html1);
$mpdf->SetHTMLFooter('<div class="myFooter">Page {PAGENO} of {nb}</div>');
//In order to use php dynamically, we need to capture the html output
ob_start();
echo '<div id="page">';
$i = 1;
foreach ($users as $user){ //
echo '<div id="innerpage">';
echo '<div class="altAttendees">' .$users[$i] . '</div>'; //output the users' information from the array
echo '</div>';
if ($i % 3 == 0){
echo '<pagebreak />';
}
$i++;
}
echo '</div>';
$html = ob_get_contents();
ob_end_clean();
$stylesheet = file_get_contents('css/styles_pdf.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($html);
$mpdf->AddPage();
$mpdf->WriteHTML('<div id="page"></div>');
$mpdf->AddPage();
$mpdf->WriteHTML('<div id="page"></div>');
$mpdf->Output($fileName, 'I'); //When Save As, a pre-assigned filename will be generated with today's date
exit;
//==============================================================
//==============================================================
//==============================================================
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment