Aymkdn / html-to-pdfmake

This module permits to convert HTML to the PDFMake format
https://aymkdn.github.io/html-to-pdfmake/index.html
MIT License
560 stars 88 forks source link

Malformed table row when number of td do not match #135

Closed qasimmehdi closed 2 years ago

qasimmehdi commented 2 years ago

If the number of cells is less than previous rows there is an error Malformed table row, a cell is undefined. How can I fix it?

HTML:

<table>
  <tbody>
    <tr>
      <td>1000</td>
      <td>2000</td>
    </tr>
    <tr>
      <td>3000</td>
    </tr>
  </tbody>
</table>

JSON:

var dd = {
  "content": [
    {
      "nodeName": "TABLE",
      "marginBottom": 5,
      "borderCollapse": "collapse",
      "tableLayout": "fixed",
      "width": 468,
      "style": [
        "html-table"
      ],
      "table": {
        "body": [
          [
            {
              "text": "1000",
              "nodeName": "TD",
              "borderCollapse": "collapse",
              "tableLayout": "fixed",
              "style": [
                "html-td",
                "html-tr",
                "html-tbody",
                "html-table"
              ]
            },
            {
              "text": "2000",
              "nodeName": "TD",
              "borderCollapse": "collapse",
              "tableLayout": "fixed",
              "style": [
                "html-td",
                "html-tr",
                "html-tbody",
                "html-table"
              ]
            }
          ],
          [
            {
              "text": "3000",
              "nodeName": "TD",
              "borderCollapse": "collapse",
              "tableLayout": "fixed",
              "style": [
                "html-td",
                "html-tr",
                "html-tbody",
                "html-table"
              ]
            }
          ]
        ],
        "widths": [
          "auto",
          "auto"
        ],
        "heights": [
          "auto",
          "auto"
        ]
      }
    }
  ]
}
Aymkdn commented 2 years ago

You can fix it by providing a correct HTML code. It's already very difficult to deal with tables, so you'll have to provide the correct number of cells, either by doing:

<table>
  <tbody>
    <tr>
      <td>1000</td>
      <td>2000</td>
    </tr>
    <tr>
      <td colspan="2">3000</td>
    </tr>
  </tbody>
</table>

Or:

<table>
  <tbody>
    <tr>
      <td>1000</td>
      <td>2000</td>
    </tr>
    <tr>
      <td>3000</td>
      <td></td>
    </tr>
  </tbody>
</table>
no-response[bot] commented 2 years ago

This issue has been automatically closed because the requestor didn't provide any additional comment.