"); //============================================================+ // File name : example_010.php // Begin : 2008-03-04 // Last Update : 2013-05-14 // // Description : Example 010 for TCPDF class // Text on multiple columns // // Author: Nicola Asuni // // (c) Copyright: // Nicola Asuni // Tecnick.com LTD // www.tecnick.com // info@tecnick.com //============================================================+ /** * Creates an example PDF TEST document using TCPDF * @package com.tecnick.tcpdf * @abstract TCPDF - Example: Text on multiple columns * @author Nicola Asuni * @since 2008-03-04 */ // Include the main TCPDF library (search for installation path). require_once('../extensions/ki_changerequest/templates/tcpdf/tcpdf.php'); /** * Extend TCPDF to work with multiple columns */ class MC_TCPDF extends TCPDF { /** * Print chapter * @param $num (int) chapter number * @param $title (string) chapter title * @param $file (string) name of the file containing the chapter body * @param $mode (boolean) if true the chapter body is in HTML, otherwise in simple text. * @public */ public function PrintChapter($num, $title, $file, $mode=false) { // disable existing columns $this->resetColumns(); // print chapter title $this->ChapterTitle($num, $title); // set columns $this->setEqualColumns(4,57); // print chapter body $this->ChapterBody($file, $mode); } /** * Set chapter title * @param $num (int) chapter number * @param $title (string) chapter title * @public */ public function ChapterTitle($num, $title, $width) { $this->SetFont('helvetica', '', 14); $this->SetFillColor(200, 220, 255); $this->Cell($width, 6, $title, 0, 1, '', 1); $this->Ln(4); } /** * Print chapter body * @param $file (string) name of the file containing the chapter body * @param $mode (boolean) if true the chapter body is in HTML, otherwise in simple text. * @public */ public function ChapterBody($file, $mode=false) { $this->selectColumn(); // get esternal file content $content = $file; // set font $this->SetFont('times', '', 9); $this->SetTextColor(50, 50, 50); // print content if ($mode) { // ------ HTML MODE ------ $this->writeHTML($content, true, false, true, false, 'J'); } else { // ------ TEXT MODE ------ $this->Write(0, $content, '', 0, 'J', true, 0, false, true, 0); } $this->Ln(); } } // end of extended class // --------------------------------------------------------- // EXAMPLE // --------------------------------------------------------- // create new PDF document $pdf = new MC_TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false); // set document information $pdf->SetCreator(PDF_CREATOR); $pdf->SetAuthor('Nicola Asuni'); $pdf->SetTitle('TCPDF Example 010'); $pdf->SetSubject('TCPDF Tutorial'); $pdf->SetKeywords('TCPDF, PDF, example, test, guide'); $header_logo = 'alteram_logo.png'; // set default header data $pdf->SetHeaderData($header_logo, PDF_HEADER_LOGO_WIDTH, 'Time Sheet Management', 'Change Request Form'); // 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->SetHeaderMargin(PDF_MARGIN_HEADER); $pdf->SetFooterMargin(PDF_MARGIN_FOOTER); // 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); } //GET COMPANIES FROM DATABASE $column_company_name = ""; $query = "select k.knd_name as 'company_name' from kimai15_knd k where k.knd_trash = 0 order by k.knd_name"; $result = mysqli_query($con, $query); if (mysqli_num_rows($result) != 0) { while ($row = mysqli_fetch_array($result)) { $column_company_name .= '" . $row['company_name'] . "
" . "\n"; } } //GET PROJECTS FROM DATABASE $column_project_name = ""; $query = "select DISTINCT right(p.pct_name,CHAR_LENGTH(p.pct_name) - 8 ) as 'project_name' from kimai15_pct p where p.pct_trash = 0 order by project_name"; $result = mysqli_query($con, $query); if (mysqli_num_rows($result) != 0) { while ($row = mysqli_fetch_array($result)) { $column_project_name .= '" . $row['project_name'] . "
" . "\n"; } } //GET DIVISIONS FROM DATABASE $column_division_name = ""; $query = "select DISTINCT left(p.pct_name,3) as 'division_name' from kimai15_pct p where p.pct_trash = 0 order by division_name"; $result = mysqli_query($con, $query); if (mysqli_num_rows($result) != 0) { while ($row = mysqli_fetch_array($result)) { $column_division_name .= '" . $row['division_name'] . "
" . "\n"; } } //GET TASKS FROM DB $column_task_name = ""; $query = "select e.evt_name as 'task_name' from kimai15_evt e where e.evt_trash = 0 order by task_name"; $result = mysqli_query($con, $query); if (mysqli_num_rows($result) != 0) { while ($row = mysqli_fetch_array($result)) { $column_task_name .= '" . $row['task_name'] . "
" . "\n"; } } // ADD PAGE $pdf->AddPage('P'); //ADD FORM $pdf->setFormDefaultProp(array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 200), 'strokeColor'=>array(255, 128, 128))); $pdf->SetFont('helvetica', '', 12); // First name $pdf->Cell(35, 5, 'First name:'); $pdf->TextField('firstname', 50, 5); $pdf->Ln(10); // Last name $pdf->Cell(35, 5, 'Last name:'); $pdf->TextField('lastname', 50, 5); $pdf->Ln(10); $pdf->writeHTMLCell(51, 7, 49, 25, '', 1, 0, 0, false, 'L', true); $pdf->writeHTMLCell(51, 7, 49, 35, '', 1, 0, 0, false, 'L', true); $pdf->Ln(10); //ADD First Column //$pdf->resetColumns(); $pdf->setEqualColumns(3, 57, 0); $pdf->selectColumn(); $pdf->ChapterTitle(0,"Company Name", 60); $pdf->ChapterBody($column_company_name, true); //Second Column $pdf->resetColumns(); $pdf->setEqualColumns(3, 57, 45); $pdf->selectColumn(1); $pdf->ChapterTitle(0,"Project Name",60); $pdf->ChapterBody($column_project_name, true); //Third Column $pdf->resetColumns(); $pdf->setEqualColumns(3, 57, 45); $pdf->selectColumn(2); $pdf->ChapterTitle(0,"Division", 60); $pdf->ChapterBody($column_division_name, true); // ADD PAGE $pdf->AddPage('L'); // PRINT SECOND CHAPTER $pdf->PrintChapter(2, 'Task List', $column_task_name, true); // --------------------------------------------------------- //Close and output PDF document $pdf->Output('example_010.pdf', 'I'); //============================================================+ // END OF FILE //============================================================+