Print or export pdf a column with php picture
Print or export pdf a column with php picture
Hi,
My problem :
I use pi_barcode to generate barcode in php :
...
$Final[$i]['ImageCB'] = '<IMG src="ImageCodeBarre.php?codage=EAN&code='.$Final[$i]['CodeBarre'].'&text=oui">';
...
After I use DataTable to generate the table ( $Final ) and i can see the picture in chrome. But where i use the datatable print button or Pdf, no picture in the output ( only other column printed ). I try src="image/test.png" but nothing ...
Thanks
This question has an accepted answers - jump to answer
Answers
Print, and the other export options, strip HTML, including image tags, leaving only the text. You can use the
stripHtml
option of thebuttons.exportData()
method (which you can pass through theexportOptions
of theprint
button type. Or you could use a custom formatter.Allan
i try :
function LancerDataTable(id) {
$(document).ready( function() {
var table = $('#'+id).DataTable( { "language": { "url": "include/DataTable.fr_FR.txt" },
"paging": false,
"order": [],
dom: 'Bfrtip',
buttons: [
{ extend: 'print', title: 'Impression', exportOptions: { columns: ':visible' } },
{ extend: 'pdfHtml5', title: 'PDF', download: 'open', exportOptions: { columns: ':visible' } },
{ extend: 'copyHtml5', exportOptions: { columns: ':visible' } },
{ extend: 'csvHtml5', title: 'CSV', exportOptions: { columns: ':visible' } },
{ extend: 'excelHtml5', title: 'Excel', exportOptions: { columns: ':visible' } },
{ extend: 'columnVisibility', text: 'Toutes', visibility: true },
{ extend: 'colvis', text: 'Visibilité' }
]
} );
table.buttons.exportData( {
stripHtml: false
} );
} );
};
with in php file :
print 'LancerDataTable(\'ListeArticle\'); ';
and nothing ... have you an exemple ?
Regards
Sorry - I misread your original message as "print" rather than "pdf".
At the moment there is no built in option to show a column of images. It is possible to include images in the PDF as shown here, but you would need to base64 encode every image to be able to include it. It is possible, but I'm afraid it isn't easy.
Allan
It possible to code Image in base64 with php
$base64 = base64_encode( url of the picture );
After my php array is like :
$Final[$i]['ImageCB'] = 'data:image/png;base64,iVBORw0KGgoAAAANS ...
And i can show it in html but not in "print" and not in "pdf". Have you a solution ?
For me, one solution with "print" or "pdf" is good. just one ...
Regards
Guy
I don't have an example of how to do it with the PDF export. I could put one together under the Quick Support 180 option. It would basically be a modification of the example I give you above which modifies the document to include the images in the document.
I doubt it would perform particularly well I'm afraid. pdfmake is already fairly slow and base64 encoding every image on the client-side would be fairly slow.
Allan
Ok, thanks for your help ( so quickly ! )
Regards
Guy
so you say pdfmake is slow. so why are you using pdfmake as a pdf exporter?
the images are not shown when not using the doc.content.splice option without it, the image wont shown. Like when use to have 3 columns on the header and in the left side i would have a logo of my school. but the logo is not showing and its encoded already. haixt so frustrated about this.
Any other suggestions? It was the best open source option I could find at the time. Others either were buggy, not free or didn't support tables. I'd welcome any suggestions for another library as development on pdfmake appears to have stalled.
Allan