How to create watermark image in pdf exported in datatable
How to create watermark image in pdf exported in datatable
I am using datatables to display data in table format and have given export option , to export data into csv , pdf . Now i want to add a watermark image into pdf that gets downloaded from button in data table.
Here is code i tried but it didnt work for me,
var table = $('#holiday').DataTable( {
"dom": '<"nav" B>lfrtip',
"buttons": [
'excelHtml5',
'csvHtml5',
{
extend: 'pdfHtml5',
customize: function ( doc ) {
doc.content.splice( 1, 0, {
margin: [ 20, 20, 20, 20 ],
alignment: 'center',
image:'data:image/png;base64,abcdddd'
}] });
I also tried using watermark in place of image , but i didnt get result. Please help me regarding this. Thanks in advance
This question has an accepted answers - jump to answer
Answers
Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.
Information on how to create a test page, if you can't provide a link to your own page can be found here.
Thanks,
Allan
Thanks. I have created js bin test demo. There is no data in table but i have added image that will appear in pdf file when exported. Now my worry is that the image that appears at top in pdf file , i want it to appear as watermark image at center of file. Is that possible using data Table export options ?
Link : https://jsbin.com/riliku/edit?html,js,output
Oh I see - the issue isn't that you can't get an image into the file, its that you want it in the background as a true water mark? For that you would need to refer to the pdfmake documentation to see how their API can be used to do such a thing. I'm afraid I don't know what the answer is there.
Allan
I think they have added watermark option.
https://github.com/bpampuch/pdfmake/pull/492
so this works for me. I am using pdfmake v0.1.27
customize: function ( doc ) {
doc.watermark = {text: 'watermark text', color: 'blue', opacity: 0.1};
}