Print or export pdf a column with php picture

Print or export pdf a column with php picture

gd974gd974 Posts: 4Questions: 1Answers: 0

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

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    Print, and the other export options, strip HTML, including image tags, leaving only the text. You can use the stripHtml option of the buttons.exportData() method (which you can pass through the exportOptions of the print button type. Or you could use a custom formatter.

    Allan

  • gd974gd974 Posts: 4Questions: 1Answers: 0

    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

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    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

  • gd974gd974 Posts: 4Questions: 1Answers: 0
    edited June 2016

    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

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin
    Answer ✓

    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

  • gd974gd974 Posts: 4Questions: 1Answers: 0

    Ok, thanks for your help ( so quickly ! )

    Regards
    Guy

  • chrizzy14chrizzy14 Posts: 9Questions: 3Answers: 0

    so you say pdfmake is slow. so why are you using pdfmake as a pdf exporter?

  • chrizzy14chrizzy14 Posts: 9Questions: 3Answers: 0

    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.

  • allanallan Posts: 61,744Questions: 1Answers: 10,111 Site admin

    so why are you using pdfmake as a pdf exporter?

    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

This discussion has been closed.