4

I try to generate a PDF with TCPDF 5.9.141, but valign doesn't seem to work. It's in a CakePHP 2.0 function, but I don't think it matters. According to the documentation everything is valid in my code:

  • Vertical alignment of text (requires $maxh = $h > 0)
  • This feature works only when $ishtml=false
  • and the cell must fit in a single page.
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);

$pdf->SetFont('helvetica', '', 7);
$pdf->AddPage();
$pdf->MultiCell($w=20, $h=15, $txt='teszt', $border='1', $align='C', $fill=false, $x=1, $y=1, $reseth=true, $strech=0, $ishtml=false, $autopadding=true, $maxh=15,  $valign='M', $fitcell=true);
$pdf->Output('cimkelista.pdf', 'I');

Does anyone have any suggesions?
Thanks in advance!

David Szlovak
  • 61
  • 1
  • 1
  • 3
  • Not that it makes a difference to the problem, but why are you assigning all those variables in the call to `MultiCell`? Do you really need them? – DaveRandom Dec 19 '11 at 15:14
  • 1
    No, I don't all of them. I just wanted to be sure that it's not a problem of parameter passing. – David Szlovak Dec 19 '11 at 16:10

3 Answers3

6

You need to set the maxh parameter to something for it to work, and not the default value of zero. Using the same value as the cell height seems to work best.

joseph_morris
  • 705
  • 6
  • 13
2

The code above is based on the documentation, but the examples don't use that many parameters, so here is a working function call:

$pdf->MultiCell($w=20, $h=15, $txt='teszt', $border='TL', $align='C', $fill=0, 1, $x=$startx, $y=$starty, $reseth=true, $strech=0, $ishtml=false, $autopadding=true, $maxh=13, $valign='M');
David Szlovak
  • 61
  • 1
  • 1
  • 3
2

Are you sure it's not suppost to be:

$pdf->MultiCell(20, 15, 'teszt', '1', 'C', false, 1, 1, true, 0, false, true, 15,  'M', true);

Haven't used tcpdf in a while, but that should be a good first step

This is also based on fpdf, where the multicell only has:

MultiCell(float w, float h, string txt [, mixed border [, string align [, boolean fill]]])
Abe Petrillo
  • 2,368
  • 23
  • 34