dede
dede

Reputation: 841

How to render html tags/to generate dynamic tables using html-pdf

I want to generate a table from node.js to be printed in pdf format using html-pdf library but unfortunately my code won't work. The problem is because the html-pdf won't execute html tags. It execute the tags as string instead.

var tableBody = '';
for (i = 1; i < data.lenght; i++);
{
     tableBody = tableBody + '<tr>' +
                '<td>' + data[i].full_name + '</td>' +
                '<td>' + data[i].age + '</td>' +
                '<td>' + data[i].address + '</td>' +
             '</tr>';
 }
pdfParam.tableBody = tableBody;

then in html file, my code just like this.

<table>
  <tbody>
      {{tableBody}}
  </tbody>
</table>

Is there a way to solve this? Any answers and comments are really appreciated.

Upvotes: 0

Views: 556

Answers (1)

Miguel Rodriguez
Miguel Rodriguez

Reputation: 26

I used your code and it served me very well, I only made a couple of changes:

var tableBody = '';
for (i = 1; i < data.lenght; i++)(drop this semicolon)
{
     tableBody = tableBody + '<tr>' +
                '<td>' + data[i].full_name + '</td>' +
                '<td>' + data[i].age + '</td>' +
                '<td>' + data[i].address + '</td>' +
             '</tr>';
 }
(drop this param)

in the var content (html):

only ${tableBody} in the right place...

Upvotes: 1

Related Questions