TCPDF: why is the position of a multicell inherited from another element?

Viewed 227

I an using TCPDF to create a PDF output. At the left of the page, I'd like a couple of cells or blocks on top of each other with rotated text. If the text is larger than the width (or actual height, when rotated), the text should be cut off.

I can make a unrotated box in a certain size at a certain position by doing this:

$roleheight=160/count($rolenames);
$x=4;
$y=18;
$w=$roleheight;
$h=20;
$text="The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog, The quick brown fox jumps over the lazy dog";
$pdf->MultiCell($w,$h,"",0,"J",true,0,4,18,true,0,false,true,5,'T',false);
$pdf->StartTransform();
$pdf->Rect($x, $y, $w, $h, 'CNZ');
$pdf->writeHTMLCell($w, $h, $x, $y, $text,0,0,false,true,"",false);
$pdf->StopTransform();

I can make a rotated box at a certain size by doing this:

$pdf->StartTransform();
$pdf->Rotate(90);
$pdf->MultiCell($w,$h,$text,0,"J",true,0,$x,$y-50,true,0,false,true,5,'T',false);
$pdf->StopTransform();

But the second box does not honor my position, and the first box cannot be rotated.

I tried adding $pdf->Rotate(90); to the first box before the Rect, between Rect and writeHTMLCell and after writeHTMLCell, but no luck

I tried alter the $x and $y of the second box, by adding or substracting a number (e.g. 100), but that places the box at a very unexpected location.

If I outcomment the FIRST box, the second box won't appear either. So somehow the position of box 2 is inherited from box 1. But how and why?

1 Answers

I still don't why the Multicell is having parameters X and Y, while those do not set the X- and Y-positions. I do have to add a SetXY in front of the multicell. Furthermore, I don't know why I have to add a +10 at the x and the y to place the boxes at the correct locations. But this did the trick:

$roleheight=160/count($rolenames);
$x=4;
$y=18;
$y=$y-$roleheight-2;
for ($i=0;$i<count($rolenames);$i++)
{
    $x=($x+$roleheight)-$roleheight;
    $y=($y+$roleheight)+1;
    $w=$roleheight;
    $h=20;
    $pdf->SetXY($x+10, $y+10);
    $pdf->StartTransform();
    $pdf->Rotate(90);
    $pdf->MultiCell($w,$h,$rolenames[$i],0,"L",true,0,$x,$y,true,0,false,false,5,'T',false);
    $pdf->StopTransform();

}
Related