dszdiavv474681 2019-02-26 18:31 采纳率: 0%
浏览 482

如何将HTML表格保存为PDF格式的图像

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!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法