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
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
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With