1

I have a problem trying to export an HTML table to PDF with all the canvas it has.

The thing is, i can export the canvas as an image to the PDF but i cant seem to do the same with the tables.

Here is the code:

echo '<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.3/jspdf.min.js"></script>';    
    echo"<script>
                download.addEventListener('click', function () {
                    var imgData = document.getElementsByTagName('canvas')[0].toDataURL('image/png', 1.0);
                    var imgData2 = document.getElementsByTagName('canvas')[1].toDataURL('image/png', 1.0);

                    var imgData_table = document.getElementsByTagName('table')[0].toDataURL('image/png', 1.0);

                    var pdf = new jsPDF('p', 'px', 'a4');

                    var i = new Image();

                    var pageHeight = pdf.internal.pageSize.height;
                    var pageWidth = pdf.internal.pageSize.width;

                    console.log(pageHeight + ', ' + pageWidth);

                    i.src = imgData; 

                    setTimeout(function(){
                        pdf.addImage(imgData_table, 'png', 0, 0,);
                        pdf.addPage();
                        //console.log(i.width + ', ' + i.height);
                        pdf.addImage(imgData2, 'png', 0, 0,);
                        pdf.addPage();
                        pdf.addImage(imgData, 'png', 0,0);
                        pdf.save('download.pdf');
                    },600);




                }, false);

            </script>";

            echo "<div class='col-sm-6'>
                <button id='download'>download</button>
            </div>
            ";

Does anyone knows what can be done in this case? Thanks!

Vidal
  • 2,306
  • 2
  • 11
  • 27
Start PDV
  • 19
  • 4
  • Try this example: https://stackoverflow.com/questions/23035858/export-html-table-to-pdf-using-jspdf using pdf.fromHTML() – Pawel Feb 26 '19 at 19:02
  • yes, it just fills 15 pages of blank content (the pdf reader doesn't reads it i think) – Start PDV Feb 27 '19 at 14:30

0 Answers0