PDF generator (PDF line color)
PDF generator (PDF line color)
Hello people,
I have a situation where I can't think of a solution as a beginner, can you please advise me? Here is live: http://live.datatables.net/habujijo/3/
It colors the table's background color according to what data a particular column contains.
The problem is that when I use the button to generate a PDF, the colors disappear.
The goal is to make the table in the PDf look the same color as the table in the HTML before clicking the PDF button.
Is there any way to add them there too?
Thank you very much for the advice.
Replies
There's no simple way to do it, I'm afraid. This example shows how to colour rows in the PDF. You would need to do something similar, but only colour the rows/cells that match the colouring in the table.
Colin
I send bad live, here is working preview: http://live.datatables.net/xuveguxa/1/edit
@colin
I knew it was going to be complicated ... :-(
I'll leave it here if someone happens to think of something.
I guess you could create a JS script that reads the rows of the table and automatically generates based on what the rows of the class have what you write:
doc.content [1] .table.body [0] .forEach (function (h) {h.fillColor = getclassby ('#example', 0);});
doc.content [1] .table.body [1] .forEach (function (h) {h.fillColor = getclassby ('#example', 1);});
doc.content [1] .table.body [2] .forEach (function (h) {h.fillColor = getclassby ('#example', 2);});
etc ...
Is that a good idea?
But HTML look like:
<tr class="even red">
<tr class="odd green">
<tr class="even orange">
etc ...
The easiest way would be to use the code I posted, then read through the doc and if the string matches, change it. It would need that conditional check to get the colours correct.
Colin
Is there anyone willing to write me that line if (cellContents = "London") {colorRow = red "} so that it really works? I have zero skill on javascript and I can't figure it out. Thanks.
Please tell me the price, I won't bother you for free.
Here you go - this looks like it's doing what you want: http://live.datatables.net/cicocuyo/1/edit
And thank you for the offer of payment, we're always grateful for any support,
Colin
That looks good, maybe it will work for me. Thanks a lot. I will consider the support and I will probably choose a package. Thanks.