AlesSvetina
AlesSvetina

Reputation: 463

Prevent new line in rows in mPDF

I am trying to make an A4 page with mPDF with 20 lines. It should always fit on one page with the same font size and line height. The text in each line can vary in length. If it's too long, I just want to strip it at the end. I tried with white-space:nowrap with no luck, the text keeps going in a new line. Tried with tables, divs, multiple elements.

My mpdf configuration:

$mpdf = new Mpdf([
  'mode' => 'utf-8',
  'format' => 'A4',
  'margin_left' => 0,
  'margin_right' => 0,
  'margin_top' => 0,
  'margin_bottom' => 0,
  'margin_header' => 0,
  'margin_footer' => 0
  ]);

My template:

<style>
    table {
        padding: 0 3%;
        margin: 0;
        overflow: hidden;
        width: 100%;
        white-space: nowrap;
    }
    table td {
        width: 100%;
        white-space: nowrap;
        font-size: 36px;
        line-height: 46px;
    }
</style>

<table autosize="1">
    {% for i in 1..20 %}
        <tr>
            <td>
                {{i}}.  Text of varying length (if it's short the rows are ok, but not if it's long)
            </td>
        </tr>
    {% endfor %}
</table>

Would appreciate any help of suggestions what I may be doing wrong. Thank you!

Upvotes: 0

Views: 481

Answers (0)

Related Questions