Jspdf-autotable: Is it possible to read inline style tag?

Created on 4 Jan 2019  路  8Comments  路  Source: simonbengtsson/jsPDF-AutoTable

Currently when my cell content contains <br> tag, it will recognize and start a new line.
However when the cell content contains <b> or <i> tags, it won't recognize.
I tried to change the js file from innerText to innerHTML:

            if (cell.raw && cell.raw instanceof HTMLElement) {
                cell.text = (cell.raw.innerHTML || '').trim();
            }

but it will display the<b> tag instead of showing bold text.
May I ask is there any way to let the plugin read these tags?
Thanks a lot!
My question is similar to #412

Most helpful comment

I am sorry but I don't understand how can I use these tools to get two different styles in the same cell. It seems to me that the style will override the whole cell content.

For example if I have a text:
Lorem ipsum dolor sit amet, <b>consectetur</b> adipiscing elit.
<i style="color:red;">Suspendisse in finibus libero.</i>

Do you mind to further illustrate a bit more of how can I do this? :(

All 8 comments

Yes, would have to draw the text yourself in the didDrawCell.

May I ask how can I draw some additional text with different formatting using didDrawCell?
For example I want: Some normal text and some bold text
After creating the table, I tried to include this in the option:

didDrawCell: function(data) {
    if (data.cell.colSpan==2) {
        data.cell.text="Custom styling hooks";
        data.cell.styles.fontStyle = 'bold';
    }
},

It didn't work. I tried looking into the examples but I still don't really get it. May I ask how should I use didDrawCell to do this?

In the didDrawCell the text is already drawn. Try willDrawCell.

If you want to change cell content you can use didParseCell

I am sorry but I don't understand how can I use these tools to get two different styles in the same cell. It seems to me that the style will override the whole cell content.

For example if I have a text:
Lorem ipsum dolor sit amet, <b>consectetur</b> adipiscing elit.
<i style="color:red;">Suspendisse in finibus libero.</i>

Do you mind to further illustrate a bit more of how can I do this? :(

If anyone is still looking for answer the following links might help.

mix bold & html inside a cell in table SO

mix bold & html github

@simonbengtsson can you please provide some example of such willDrawCell? Is it really somehow possible to mix bold and not bold text in one cell without editing source code of the lib?

It's also unclear to me how to achieve that with willDrawCell. I'm trying to get "normal text and bold text within the same cell"

Was this page helpful?
0 / 5 - 0 ratings