danfickle / openhtmltopdf

An HTML to PDF library for the JVM. Based on Flying Saucer and Apache PDF-BOX 2. With SVG image support. Now also with accessible PDF support (WCAG, Section 508, PDF/UA)!
https://danfickle.github.io/pdf-templates/index.html
Other
1.93k stars 359 forks source link

overflow/white-space #910

Open VILLAN3LL3 opened 1 year ago

VILLAN3LL3 commented 1 year ago

Here's my css for a table cell:

    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;

The HTML:

<td colspan="3">
  <span style="display: inline-block; min-width: 33.77%;">29010180A735</span>
  <span>Some very large text which doesn't fit into the cell</span>
</td>

Opening the HTML in the browser results in

  1. image

I know that openhtmltopdf doesn't support text-overflow: ellipsis (GitHub issue). When I remove it, the HTML looks like this in the browser:

  1. 2023-02-13_13h22_32

But after converting to pdf with openhtmltopdf the result is as follows:

  1. 2023-02-13_13h23_09

What am I doing wrong? How can I at least achieve 2.?

Example code to reproduce the issue in the openhtmltopdf sandbox:

<html>
  <head>
    <meta charset="UTF-8"/>
    <title>Lohnabrechnung</title>
    <style>
      table {
        table-layout: fixed;
        width: 50%;
      }
      td {
        border: 1px solid red;
      }
    </style>
  </head>
  <body>
    <table>
      <colgroup>
         <col style="width: 26%;"/>
         <col style="width: 28%;"/>
         <col style="width: 23%;"/>
         <col style="width: 23%;"/>
      </colgroup>
      <tr>
        <td style="overflow: hidden; white-space:nowrap;"  colspan="3">
          <span style="display: inline-block; min-width: 33.77%;">29010180A735</span> <!-- No line break intended here! -->
          <span>Some very large text which doesn't fit into the cell</span> 
        </td>
        <td>Another cell</td>
      </tr>
    </table>
  </body>
</html>