<?php


// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {

	//Page header
	public function Header() {
global $logo_img;
global $ad_img;
global $footer_img;
global $logo;
global $ad;
global $cover;
global $cover_img;

if(isset($logo) && $logo!=0){		

		// Logo
		if (count($this->pages) === 2) {
		$image_file = K_PATH_IMAGES.$logo_img;
		$this->Image($image_file, 10, 10, 190, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		// Set font
		$this->SetFont('helvetica', 'B', 20);}
		
		
		if(isset($ad) && $ad!=0){
		if (count($this->pages) === 3) {
		$img_file = K_PATH_IMAGES.$ad_img;
        $this->Image($img_file, 0, 25, 0, 250, 'JPG', '', '', false, 300, 'C', false, false, 0);
		}
		}
		
		
		if(isset($cover) && $cover!=0){
		if (count($this->pages) === 1) {
		$img_file = K_PATH_IMAGES.$cover_img;
        $this->Image($img_file, 0, 25, 0, 250, 'JPG', '', '', false, 300, 'C', false, false, 0);
		}
		}
		
}
		}

	// Page footer
	public function Footer() {
global $footer_img;
global $logo;
		
		if(isset($logo) && $logo!=0){
if (count($this->pages) === 2) {
	// Position at 15 mm from bottom
		$this->SetY(-15);
		
		// Set font
		$this->SetFont('helvetica', 'I', 8);
		// Page number
		$this->Cell(0, 10, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
		$image_file = K_PATH_IMAGES.$footer_img;
		$this->Image($image_file, 10, 250, 190, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
		
	}

	
	}
	}
	
	
}

// 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('i2d Technologies');
$pdf->SetTitle($doc_title.$rec_id);
$pdf->SetSubject($doc_sub);
$pdf->SetKeywords($doc_keywords);

// 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->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);
}

// set font
$pdf->SetFont('helvetica', '', 9);


// create some HTML content

$pdf->AddPage();

// create some HTML content




/// PART 2

$html = ''.$inv_header.'';

$html .='
'.$opening_letter.''.$price_tables.'
';


$pdf->AddPage();

// output the HTML content
$pdf->writeHTML(utf8_encode($html), true, 0, true, 0);



   
if(isset($ad) && $ad!=0){
$pdf->AddPage();
}	
// reset pointer to the last page
$pdf->lastPage();

$file=".$file_title."."-".$refno."-".$dated1.".pdf";

// ---------------------------------------------------------

if($case=="1"){//Close and output PDF document
ob_end_clean();
$pdf->Output($file , 'I');}

if($case=="2"){
	// force print dialog
$js = 'print(true);';

// set javascript
$pdf->IncludeJS($js);
ob_end_clean();
//Close and output PDF document
$pdf->Output($file , 'I');
	
}



//============================================================+
// END OF FILE
//============================================================+


/////////////////////////// function ends /////////////////////////////////
















?>