<?php
  include('../barcode/php-barcode.php');
  require('../barcode/fpdf.php');
  
  $mDocumentRef = $_GET['documentreference'];
  // -------------------------------------------------- //
  //                      USEFUL
  // -------------------------------------------------- //
  
  class eFPDF extends FPDF
  {
// Page header
	function Header()
	{
// Logo
		$this->Image('../../../images/vel_logo_large.jpg',10,6,50);
// Arial bold 15
		$this->SetFont('Arial','B',15);
// Move to the right
		$this->Cell(100);
// Title
		$this->Cell(50,10,'Haulier Reference',0,0,'C');
// Line break
		$this->Ln(20);
	}

// Page footer
	function Footer()
	{
// Position at 1.5 cm from bottom
		$this->SetY(-15);
// Arial italic 8
		$this->SetFont('Arial','I',8);
// Page number
		$this->Cell(0,10,'Page '.$this->PageNo(),0,0,'C');
	}  
	  
    function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
    {
        $font_angle+=90+$txt_angle;
        $txt_angle*=M_PI/180;
        $font_angle*=M_PI/180;
    
        $txt_dx=cos($txt_angle);
        $txt_dy=sin($txt_angle);
        $font_dx=cos($font_angle);
        $font_dy=sin($font_angle);
    
        $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',$txt_dx,$txt_dy,$font_dx,$font_dy,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
        if ($this->ColorFlag)
            $s='q '.$this->TextColor.' '.$s.' Q';
        $this->_out($s);
    }
  }

  // -------------------------------------------------- //
  //                  PROPERTIES
  // -------------------------------------------------- //
  
//  $fontSize = 10;
//  $marge    = 10;   // between barcode and hri in pixel
  $x        = 200;  // barcode center
  $y        = 150;  // barcode center
  $height   = 20;   // barcode height in 1D ; module size in 2D
//  $width    = 0.50;    // barcode height in 1D ; not use in 2D
  $angle    = 0;   // rotation in degrees

  $fontSize = 8;
  $marge    = 5;   // between barcode and hri in pixel
//  $x        = 30;  // barcode center
//  $y        = 70;  // barcode center
//  $height   = 20;   // barcode height in 1D ; module size in 2D
  $width    = 1.50;    // barcode width in 1D ; not use in 2D
//  $angle    = 0;   // rotation in degrees  
  
  $code     = 'VANTEC'; // barcode text;)
  $type     = 'code39';
  $black    = '000000'; // color in hex
  
  if ($mHaulierRef != "")
	  $code = $mDocumentRef;
  // -------------------------------------------------- //
  //            ALLOCATE FPDF RESSOURCE
  // -------------------------------------------------- //
    
  $pdf = new eFPDF('P', 'pt');
  $pdf->AddPage();
  
  // -------------------------------------------------- //
  //                      BARCODE
  // -------------------------------------------------- //
  
  $data = Barcode::fpdf($pdf, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);
  
  // -------------------------------------------------- //
  //                      HRI
  // -------------------------------------------------- //
  $pdf->SetFont('Arial','B',$fontSize);
  $pdf->SetTextColor(0, 0, 0);
  $len = $pdf->GetStringWidth($data['hri']);
  Barcode::rotate(-$len / 2, ($data['height'] / 2) + $fontSize + $marge, $angle, $xt, $yt);
  $pdf->TextWithRotation($x + $xt, $y + $yt, $data['hri'], $angle);
//  $pdf->Text(150,50,"Haulier Reference");
//  $pdf->rect(10,10,100,100);
//  $pdf->image("../../images/vel_logo_large.jpg",11,11,90,90);
  
  $pdf->Output();
?>