Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FPDF SetX and SetY call order bug?

Tags:

php

fpdf

It seems like the order of SetX() and SetY() does matter. As you can see, the second cell-box in the example is located at following coordinates: X:10.00125/Y:80. Actually it should be at x=80. Setting Y-coordinate first fixes the problem. Is it a bug? PHP version used is 5.3.28.

<?php
require('./fpdf/fpdf.php');
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);

$pdf->SetY(50);
$pdf->SetX(80);
$pdf->Cell(0,5,'Coordinates: X:'.$pdf->GetX().'/Y:'.$pdf->GetY(), 1); 

$pdf->SetX(80);
$pdf->SetY(80);
$pdf->Cell(0,5,'Coordinates: X:'.$pdf->GetX().'/Y:'.$pdf->GetY(), 1); 

$pdf->Output();
?>
like image 483
Thorsten Avatar asked Apr 16 '14 12:04

Thorsten


1 Answers

This is obvious. Look at the source or the manual:

function SetY($y)
{
    // Set y position and reset x
    $this->x = $this->lMargin;
    if($y>=0)
        $this->y = $y;
    else
        $this->y = $this->h+$y;
}

So this seems to be no bug. x is reset to the left-margin, what you already noticed. You could use SetXY($x, $y) instead.

I think they wanted to have SetY to be used for placing the next paragraph, so its always aligned to the left side.

like image 107
Lars M. Avatar answered Nov 15 '22 00:11

Lars M.