简体   繁体   中英

FPDF cell places text somewhere

I have read already a lot of cases here but nothing of the suggested solutions worked for me so therefore I am asking for some hints/help. I use FPDI/FPDF with a method to place text in cells, in short it is:

public function placeTextCell($font, $fontSize, $x, $y, $red, $green, $blue, $text, $align) {
        $this->pdf->SetFont($font, '', $fontSize);
        $this->pdf->SetTextColor($red, $green, $blue);
        $this->pdf->SetXY($x,$y);
        $this->pdf->Cell(0,8,$text,0,0,$align);
    }

I am calling this method several times like:

$this->placeTextCell('crazy-font',8,5,30,255,255,255,'the text','R');
$this->placeTextCell('crazy-font',8,5,35,255,255,255,'the text','R');
$this->placeTextCell('crazy-font',8,5,40,255,255,255,'the text','R');
.... same with different 'y' coordinate

The problem is, that it works nearly for all cells, some cells are dislocated like:

             the text
             the text
        the text
    the text
             the text

I played around with calling Ln() but it doesn't do anything. I really have no clue at them moment. Does anybody have an idea why this happens?

Solved, trim did it. Funny thing, all strings were trimmed before so I'm wondering where the whitespaces come from...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM