Created
May 12, 2017 13:18
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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