<?php
error_reporting(0);
// Include the main TCPDF library (search for installation path).
$this->mypdf_class->tcpdf();

global $diamond_data;
$diamond_data = $diamond;

// echo "<pre>";print_r($diamond_data);exit;

class MYPDF extends TCPDF 
{
    //Page header
    public function Header() 
    {	
		$tbl_header = "";
		$this->writeHTML($tbl_header, true, false, false, false, '');	
    }

    // Page footer
    public function Footer() 
    {
    	global $diamond_data;

    	$dm_code = !empty($diamond_data) ? $diamond_data[0]['dm_code'] : "";
    	$dm_shape = !empty($diamond_data) ? $diamond_data[0]['dm_sh'] : "";
    	$dm_lab = !empty($diamond_data) ? $diamond_data[0]['dm_lab'] : "";
    	$dm_report_no = !empty($diamond_data) ? $diamond_data[0]['dm_report_no'] : "";
    	$dm_color = !empty($diamond_data) ? $diamond_data[0]['dm_col'] : "";
    	$dm_weight = !empty($diamond_data) ? $diamond_data[0]['dm_wt'] : "";
    	$dm_clarity = !empty($diamond_data) ? $diamond_data[0]['dm_cla'] : "";
		$dm_cut = !empty($diamond_data) ? $diamond_data[0]['dm_cut'] : "";
		$dm_polish = !empty($diamond_data) ? $diamond_data[0]['dm_pol'] : "";
		$dm_symetry = !empty($diamond_data) ? $diamond_data[0]['dm_sym'] : "";
		$dm_fluro = !empty($diamond_data) ? $diamond_data[0]['dm_fl'] : "";
		$dm_fancy_col = !empty($diamond_data) ? $diamond_data[0]['dm_fancy_col'] : "";

    	$tbl_footer = "";
    	$tbl_footer .= <<<EOD

    	<table width="80%" cellpadding="2" style="text-align:left;font-weight:bold;font-size:11px;">
			<tr>
				<td>$dm_code</td>
				<td>$dm_shape<br/><small>$dm_lab $dm_report_no</small></td>
				<td>$dm_color $dm_clarity</td>
			</tr><br/><br/><br/>
			<tr>
				<td>$dm_cut $dm_polish $dm_symetry $dm_fluro</td>
				<td></td>
				<td>$dm_weight</td>
			</tr>
		</table>
    	
		
EOD;
		$this->writeHTML($tbl_footer, true, false, false, false, '');
  
        // Set font
        $this->SetFont('helvetica', 'c', 8);
        // Page number
    }
}

// create new PDF document
// $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, array('481.5','600.75'), true, 'UTF-8', false);

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);

// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Imran Khan');
$pdf->SetTitle('Invoice Pdf');
$pdf->SetSubject('Invoice Pdf');
// $pdf->SetKeywords('TCPDF, PDF, example, test, guide');

// 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(30, PDF_MARGIN_TOP, 30);
$pdf->SetMargins(70,120, 10);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(50);

// $pdf->SetAutoPageBreak(TRUE , 35);


// 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);
}
$pdf->SetFont('Helvetica', 'c', 8);
$tbl = "";
$width = $pdf->pixelsToUnits(642.51); 
$height = $pdf->pixelsToUnits(801.25);

$resolution= array($width, $height);
$pdf->AddPage('P', $resolution);
// $pdf->AddPage();
$pdf->StartTransform();
$pdf->Rotate(90);



$dm_lab = !empty($diamond_data) ? $diamond_data[0]['dm_lab'] : "";
$dm_report_no = !empty($diamond_data) ? $diamond_data[0]['dm_report_no'] : "";
$dm_shape = !empty($diamond_data) ? $diamond_data[0]['dm_sh'] : "";
$dm_weight = !empty($diamond_data) ? $diamond_data[0]['dm_wt'] : "";
$dm_color = !empty($diamond_data) ? $diamond_data[0]['dm_col'] : "";

$dm_clarity = !empty($diamond_data) ? $diamond_data[0]['dm_cla'] : "";
$dm_cut = !empty($diamond_data) ? $diamond_data[0]['dm_cut'] : "";
$dm_polish = !empty($diamond_data) ? $diamond_data[0]['dm_pol'] : "";
$dm_symetry = !empty($diamond_data) ? $diamond_data[0]['dm_sym'] : "";
$dm_fluro = !empty($diamond_data) ? $diamond_data[0]['dm_fl'] : "";
$dm_fancy_col = !empty($diamond_data) ? $diamond_data[0]['dm_fancy_col'] : "";

$tbl .= <<<EOD

    	<table width="35%" cellpadding="1" style="font-size:9px;">
			<tr>
				<td>Lab</td>
				<td><b>$dm_lab</b></td>
			</tr>
			<tr>
				<td>Certificate No</td>
				<td><b>$dm_report_no</b></td>
			</tr>
			<tr>
				<td>Shape</td>
				<td><b>$dm_shape</b></td>
			</tr>
			<tr>
				<td>Weight</td>
				<td><b>$dm_weight</b></td>
			</tr>
			<tr>
				<td>Color</td>
				<td><b>$dm_color</b></td>
			</tr>
			<tr>
				<td>Clarity</td>
				<td><b>VVS2</b></td>
			</tr>
			<tr>
				<td>Cut Grade</td>
				<td><b>$dm_cut</b></td>
			</tr>
			<tr>
				<td>Polish</td>
				<td><b>$dm_polish</b></td>
			</tr>
			<tr>
				<td>Symetry</td>
				<td><b>$dm_symetry</b></td>
			</tr>
			<tr>
				<td>Fluorescence</td>
				<td><b>$dm_fluro</b></td>
			</tr>
			<tr>
				<td>Measurement</td>
				<td><b>6.04*6.07*3.72</b></td>
			</tr>
			<tr>
				<td>Total Depth</td>
				<td><b>61.5</b></td>
			</tr>
			<tr>
				<td>Table1</td>
				<td><b>59</b></td>
			</tr>
			<tr>
				<td>CR</td>
				<td><b>34.9 / 15</b></td>
			</tr>
			<tr>
				<td>PV</td>
				<td><b>41.2 / 43.5</b></td>
			</tr>
			<tr>
				<td>Identification</td>
				<td><b>$dm_fancy_col</b></td>
			</tr>
		</table>
    	
		
EOD;
$pdf->writeHTML($tbl, true, false, false, false, '');
$pdf->StopTransform();
// $pdf->writeHTML($tbl, true, false, false, false, 'C');

// ---------------------------------------------------------
$pdf->Output('Invoice.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+