Menu

#1123 When last character of line won't fit in remaining space at start of "Write()", line is cropped

v1.0_(example)
open
nobody
None
1
2016-05-12
2016-05-12
No

My client's code, writing hundreds of pages of PDF, has revealed a bug in TCPDF.

A short, simplified snippet follows.

$pdf->Write($h=0.2, $txt='Apple Pie', $link='', $fill=FALSE, $align='L', $ln=FALSE);
$pdf->Write($h=0.2, $txt=', portions: 1', $link='', $fill=FALSE, $align='L', $ln=FALSE);
$pdf->Write($h=0.2, $txt=', container: paper', $link='', $fill=FALSE, $align='L', $ln=TRUE);

The bug is this: On the third call to "Write", in some cases the comma - the first character in the text - is considered to "not fit" in the remaining width available, and the entire Write function returns without doing anything, rather than wrapping to a new line.

The code inside the 'Write' function that causes this bug is the following, near the top of the function:

    if ((!$firstline) AND (($chrwidth > $wmax) OR ($maxchwidth > $wmax))) {
        // the maximum width character do not fit on column
        return '';
    }

This 'return' statement is very rarely reached - but when it is, it causes a bug; my client's PDF is all messed up.

Simply by commenting out the 'return', the PDF is generated fine.

This is a clear bug in TCPDF, so I thought I'd post a bug ticket.

Thanks for the great library!

Dan N

Discussion


Log in to post a comment.