Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to center image in header (TCPDF)

Tags:

php

tcpdf

I have the code below and I am guessing what is the center of the page by eye. How would I center the image the proper way?

class MYPDF extends TCPDF {

        //Page header
        public function Header() {
                // Logo
                $image_file = K_PATH_IMAGES.'logo.png';
                $this->Image($image_file, 90, 5, 40, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);

                $style = array('width' => 0.5, 'cap' => 'butt', 'join' => 'miter', 'dash' => 0, 'color' => array(39, 137, 199));

                $this->Line($this->getPageWidth()-PDF_MARGIN_RIGHT, 25, PDF_MARGIN_LEFT, 25, $style);


        }
}

Thanks

like image 922
JohnWilks Avatar asked May 04 '11 15:05

JohnWilks


2 Answers

This should work:

// Image($file, $x='', $y='', $w=0, $h=0, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false)

$this->Image($image_file, 'C', 6, '', '', 'JPG', false, 'C', false, 300, 'C', false, false, 0, false, false, false);

You can find more information in the API: http://www.tcpdf.org/doc/code/classTCPDF.html#a714c2bee7d6b39d4d6d304540c761352

like image 175
benske Avatar answered Nov 12 '22 19:11

benske


You have a param $palign in Image()

(string) Allows to center or align the image on the current line. Possible values are:

  • L : left align
  • C : center
  • R : right align
  • empty string : left for LTR or right for RTL

With your image :

$this->Image($image_file, 90, 5, 40, '', 'PNG', '', 'T', false, 300, 'C', false, false, 0, false, false, false);
like image 36
fdehanne Avatar answered Nov 12 '22 18:11

fdehanne