<?php
//These are comming in from a HTML form
$SelectConfList = $_POST['SelectConfList'];
$FormData1 = $_POST['FormData1'];
$HoursWorkDone = $_POST['FormData2'];
$Date = $_POST['Date'];
$Location = $_POST['Location'];
$Time = $_POST['Time'];
$username = "Database_UserName";
$password = "Database_Password";
$DataBaseVar= 0;
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
$DataBaseVar= 0;
//start of Database connection
//here we pull out the data here for printing in the
//pdf pages
try {
$conn = new PDO('mysql:host=localhost;dbname=Your_Database_Name', $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$ConfirmedAttended = "yes";
$stmt = $conn->prepare('select FirstName,LastName,ConfirmedAttended from Anseo where name = "'. $SelectConfList . '" AND ConfirmedAttended = "'. $ConfirmedAttended .'" ORDER BY lastname');
$stmt->execute(array('email' => $email));
$result = $stmt->fetchAll();
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
//End of Database connection
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
//Page header
public function Header() {
// Logo
$image_file = K_PATH_IMAGES.'LOGO.jpg';
// File x y w h type link align resize DPI palign
$this->Image($image_file, 10, 10, '56', '', 'JPG', '', 'N', false, 300, 'R', false, false, 0, false, false, false);
// Set font
$this->SetFont('helvetica', '', 8.5);
// Title
// Set some content to print
$html = <<<EOD
This is the header <br>
this is the second Part of the header
EOD;
// Print text using writeHTMLCell()
$this->writeHTMLCell(0, 0, '150', '', $html, 0, 1, 0, true, 'L', true);
}
//end Headder
// Page footer
public function Footer() {
// Position at 15 mm from bottom
$this->SetY(-40);
// Set font
$this->SetFont('helvetica', '', 8.5);
// Page number
// $this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
$htmlFooter = <<<EOD
This is the Footer
EOD;
// Print text using writeHTMLCell()
$this->writeHTMLCell(0, 0, '150', '', $htmlFooter, 0, 1, 0, true, 'L', true);
}
//end footer
} //End of Class MYPDF
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Test Author');
$pdf->SetTitle('Based on TCPDF Example 003');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// remove default header/footer
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
//$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetMargins(5, 5, 5);
$pdf->SetHeaderMargin(5);
$pdf->SetFooterMargin(5);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// ---------------------------------------------------------
// set font
$pdf->SetFont('times', 'BI', 12);
//Start of page generation
//Here we loop through the array that was
//created in the database so that we have a
//Data set to work with
foreach($result as $key => $value){
// add a page
$pdf->AddPage();
// print a block of text using Write()
//$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
// Set some content to print
$htmlText = <<<EOD
This is to Say that <br> <br>
EOD;
//we use the PHP function ucwords to make sure
//that the certs generated have proper formating
//this is a catch in case we have missed something
//in the form validation
$htmlText .=ucwords($value['FirstName']);
$htmlText .= " ";
$htmlText .=ucwords($value['LastName']);
$htmlText .= "<br>";
$htmlText .= <<<EOD
<br>
<br>
<br>
$FormData1 <br>
<br>
On $Date<br>
in $Location <br>
University College Cork <br>
$Time <br>
<br>
<br>
Has worked : $HoursWorkDone hours <br>
<br><br>
_____________________________________ <BR>
Signed
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '120', $htmlText, 0, 1, 0, true, 'C', true);
}
//End of page generation
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_003.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+