-1

i create a PDF using mPDF version 5.5. The HTML includes a table with this HTML code:

<tr>
    <td width="184">
        <p dir="RTL" align="center"><strong>Programming</strong></p>
    </td>
    <td width="378">
        <p dir="RTL" align="center"><strong>No Cost</strong></p>
    </td>
</tr>

The HTML seems to look fine when i show it but when printing to PDF, the mPDF ignores the align="center" and aligning it to the left.

How can i make the align="center" work in mPDF?

casraf
  • 21,085
  • 9
  • 56
  • 91
Rodniko
  • 4,926
  • 20
  • 69
  • 93

3 Answers3

1

"Block elements (e.g. DIV or P) are not supported inside tables. The content is displayed, but any CSS properties which apply to block elements are ignored (e.g. borders, padding, margins etc)."

Source: https://mpdf.github.io/about-mpdf/limitations.html

Moongazer
  • 452
  • 4
  • 18
0

It would work if you used css instead of the align attribute. instead select that element in css and use the css property: text-align: center; Maybe use inline css: <p style="background-color: red;">Hello</p>

ca1c
  • 1,111
  • 10
  • 23
  • I'm sorry but it didn't work too. i don't have access to css from the HTML Editor i use (before passing to mPDF). as i said above, in the editor it looks as centered already (without the css). it's just when i use mPDF to create the PDF, the center aligning inside table cells doesn't work. i also updated to 6.0 version. it doesnt work still. – Rodniko Dec 06 '16 at 04:44
  • Use inline css then @Rodniko – ca1c Dec 06 '16 at 04:45
0

You can set a different alignment for inner table element by wrapping content in another table

<tr>
  <td style="text-align: center;">
    Centered
    <table>
      <tbody>
        <tr>
          <td style="text-align: left;">Aligned left</td>
        </tr>
      </tbody>
    </table>
  </td>
Michal Majernik
  • 395
  • 1
  • 3
  • 11