0

When creating a PDF in PHP (with TCPDF), I'm trying to position an image in the header, a small distance to the right of the left margin. However, the $x parameter is being completely ignored.

$img = file_get_contents('logo.png');
$pdf->Image('@'.$img,50,15,35,0,'PNG','','N',false,300,'L',false,false,0,false,false,false,false,[]);

The second parameter, 50, may as well be 0, 50 or 400: the image just won't move. If I change the 'L' for 'C', it goes to the middle of the page, but that's not what I want.

Am I missing something, or is it just a bug?

Rodrigo
  • 4,706
  • 6
  • 51
  • 94

1 Answers1

0

You need to create a fitbox before, then it will respect the X placing.

$img =file_get_contents('logo.png');
$fitbox = 'LT';
$pdf->Image('@'.$img,50,15,35,0,'PNG','','N',false,300,'L',false,false,0,$fitbox,false,false,false,[]);
Romeu Gamelas
  • 23
  • 1
  • 4
  • It's not working. With $x as 0, 50 or 500, the image simply won't move. – Rodrigo Jan 01 '19 at 23:44
  • Sorry if it didn't work. I came to your question facing the same problem, after adding the fitbox it worked. My actual code was the following: if(file_exists("$my_path/rsrc/flags/". strtolower($sender_place['country_code']) . ".png")){ $fitbox = "LT"; $pdf->Image("$my_path/rsrc/flags/". strtolower($sender_place['country_code']) . ".png",95,70.5,15,7.5,"PNG","","L",true,300,"T",false,false,1,$fitbox); } – Romeu Gamelas Jan 03 '19 at 00:23
  • It seems you change the position of 'L' and 'T'? $align only accepts one of T, M, B or N. $palign only accepts one of L, C, R or empty string. – Rodrigo Jan 03 '19 at 00:40
  • You're right, so it does nothing. Tried to give it M C and it totally displaced the element, still horizontal move was working, except it was using the original image size as box size. Changed back to empty char. – Romeu Gamelas Jan 03 '19 at 21:16