ro ko
ro ko

Reputation: 2986

TCPDF disregards width of earlier td if current td has long text

I came across a weird problem when trying to use TCPDF to create pdf off of my html. I am using

$pdf->writeHTML($myHTML, true, 0, true, 0);

to write my html content and within the pdf enter image description here

<tr>
    <td style="width: 2%"></td>
    <td style="width: 48%;text-align: left;">
        <?php echo $text; ?>            
        <br />
        <table>
            <tr>
                <td style="width:10px;"></td>
                <td style="font-size: 22px;"><?php echo $comment;?></td>
            </tr>
        </table>            
    </td>
    <td style="width: 8%;"><?php echo $dur?></td>
    <td style="width: 8%;"><?php echo ''; ?></td>
    <td style="width: 12%;"><?php echo $xyz; ?></td>
    <td style="width: 11%;"><?php echo Price(); ?></td>
    <td style="width: 11%;"><?php echo new_Price() : ''; ?></td>
</tr>

Here we can see in image, When the text in the cell is longer than width; line breaks, and disregards the td with width 2% in this case before "Successful".

Same goes for another text below in $comment, before "nothing" it disregards the td.

how can I make it all align properly.

Upvotes: 2

Views: 5934

Answers (2)

SarcasmMooch
SarcasmMooch

Reputation: 26

I know this is an old question, but I recently had a similar problem.

TCPDF shows spaces and indents used for code structuring which are in TDs as spaces.

One solution is not to use spaces and indents for structuring, but this can be pretty messy, so I get rid of all double spaces and then write the pdf.

$html =  preg_replace('/\s\s+/', '', $html);
$pdf->writeHTML($html, true, false, true, false, '');

Upvotes: 0

ro ko
ro ko

Reputation: 2986

Still open for an answer

I still haven't been able to find a definite better answer. I am posting this answer incase someone else is facing the same problem and is looking for urgent solution.

<td style="width: 48%;text-align: left;">
    <?php echo wordwrap($text, '70',"<br \>\n &nbsp;&nbsp;&nbsp;"); ?>            
        <br />
        <table>
            <tr>
                <td style="width:10px;"></td>
                <td style="font-size: 22px;"><?php echo wordwrap($comment, '70',"<br \>\n &nbsp;&nbsp;&nbsp;"); ?></td>
            </tr>
        </table>
</td>

Upvotes: 1

Related Questions