Menu

Oddities (bug?) with MultiCell, $ln = 0 and page breaks

Help
cpw
2014-12-07
2014-12-11
  • cpw

    cpw - 2014-12-07

    Hi,

    I stumbled upon some odd behaviour on page breaks when stacking MultiCells horizontally by setting $ln = 0.

    Example:

    require('./tcpdf/tcpdf.php');
    
    $pdf = new TCPDF($orientation = "P", $unit = "mm", $format = "A4", $unicode = true, $encoding = 'UTF-8', $diskcache = false, $pdfa = false);
    
    $pdf->SetPrintHeader(false);
    $pdf->SetPrintFooter(false);
    
    $pdf->SetDisplayMode(100, "OneColumn");
    
    $pdf->setCellMargins(0,0,0,0);
    
    $pdf->AddPage("P", "A4");
    
    $pdf->setCellPadding(2);
    $pdf->SetDrawColor(0, 0, 128);
    
    $text = "Line\nLine\nLine\nLine\nLine\nLine\nLine\nLine\nLine\nLine\nLine\nLine\nLine\nLine\nLine";
    
    $pdf->SetFont("helvetica","B","39");
    $pdf->MultiCell($width = 0, $height = 0, $text, $border = 1, $align = "L", $fill=false, $ln = 1, $x=70, $y='');
    
    $pdf->SetFont("helvetica","B","20");
    $pdf->MultiCell($width = 51, $height = 0, "Some big text", $border = 0, $align = "L", $fill=false, $ln = 0);
    $pdf->SetFont("helvetica","B","10");
    $pdf->MultiCell($width = 35, $height = 0, "Some small text", $border = 0, $align = "L", $fill=false, $ln = 0);
    $pdf->SetFont("helvetica","B","5");
    $pdf->MultiCell($width = 22, $height = 0, "Some very small text", $border = 0, $align = "L", $fill=false, $ln = 1);
    
    /*
    $pdf->SetFont("helvetica","B","20");
    $pdf->Cell($width = 51, $height = 0, "Some big text", $border = 0,  $ln = 0);
    $pdf->SetFont("helvetica","B","10");
    $pdf->Cell($width = 35, $height = 0, "Some small text", $border = 0,  $ln = 0);
    $pdf->SetFont("helvetica","B","5");
    $pdf->Cell($width = 22, $height = 0, "Some very small text", $border = 0,  $ln = 1);
    */
    
    $pdf->Output();
    

    This should stack "Some big text", "Some small text" and "Some very small text" in their set font sizes (20, 10 and 5) horizontally by using $ln = 0. If a page break occurs right before that, it still should look like that, only be put on the following page.

    My example contains a page break - "Some very small text" is still on page 1 with the correct font size, "Some big text" and "Some small text" are on page 2, both having font size 20.

    If you remove one of the "\nLine"s from the first text String, there's no page break and everything is fine.

    Also using "Cell" instead of "MultiCell" (the part commented out) won't show this odd behaviour, but that's only a solution when you can be sure that the contents of the cell(s) definitely won't contain line breaks.

    Any ideas?

     
  • cpw

    cpw - 2014-12-11

    OK, I found a workaround for stacking stuff horizontally in a "page-break-safe" way by using an HTML table in writeHTMLCell(). In my case right now this works fine, although there are features like valign missing, which do work with a MultiCell.

    So I'm still curious what causes this odd MultiCell behaviour on page breaks.

     

Log in to post a comment.