Word break is not working in xhtml2pdf, when converted to pdf sentances are breaking mid word instead of end of word

49 Views Asked by At

Am using xhtml2pdf . The issue am facing is the sentences are breaking into next line in the middle of words

Eg:- enter image description here

Tried using word-wrap:break-word;-pdf-keep-with-next: true;overflow-wrap: break-word; Not working

<table class="card1 ">
  <thead>
    <tr>
      <th width="60%">DEDUCTIONS</th>
      <th>AMOUNT</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td style="word-wrap:break-word;-pdf-keep-with-next: true;"> Provident Fund Professional Tax Total Deductions Income Tax</td>
      <td class=" ">&#x20B9; 87,000</td>
    </tr>
    <tr>
      <td class=" ">
        <p style="word-wrap:break-word;-pdf-keep-with-next: true;">Income Tax Provident Fund Professional Tax Total Deductions</p>
      </td>
      <td class=" ">&#x20B9; 32,090</td>
    </tr>
    <tr>
      <td>Professional Tax</td>
      <td>&#x20B9; 87,000</td>
    </tr>
  </tbody>
  <tfoot>
    <tr>
      <td class=" ">Total Deductions</td>
      <td class=" ">&#x20B9; 1,29,328</td>
    </tr>
  </tfoot>
</table>

1

There are 1 best solutions below

1
Rainy sidewalks On

give it a try with overflow-wrap: break-word instead of word-wrap:break-word

   <table class="card1">
      <thead>
        <tr>
          <th width="60%">DEDUCTIONS</th>
          <th>AMOUNT</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td style="overflow-wrap: break-word; -pdf-keep-with-next: true;">Provident Fund Professional Tax Total Deductions Income Tax</td>
          <td class="">&#x20B9; 87,000</td>
        </tr>
        <tr>
          <td class="">
            <p style="overflow-wrap: break-word; -pdf-keep-with-next: true;">Income Tax Provident Fund Professional Tax Total Deductions</p>
          </td>
          <td class="">&#x20B9; 32,090</td>
        </tr>
        <tr>
          <td>Professional Tax</td>
          <td>&#x20B9; 87,000</td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <td class="">Total Deductions</td>
          <td class="">&#x20B9; 1,29,328</td>
        </tr>
      </tfoot>
    </table>

please go through the following

Overflow-wrap vs Word-break

Though overflow-wrap and word-break behave similarly there are differences between them. The overflow-wrap property breaks the word if it cannot be placed on the line without overflowing regardless of the language used. The word-break property is used for non-English languages and specifies wraps between letters of languages like Chinese, Japanese, and Korean.

also word-wrap-and-overflow-wrap-break-word-and-break-all and difference-between-overflow-wrap-and-word-break .