如何在pdf文件中下载html页面

时间:2017-02-13 14:55:43

标签: javascript jquery pdf jspdf html-to-pdf

我已经编写了一些java脚本代码,以便下载html页面,因为excel工作正常,但我不知道如何处理pdf文件下载的javascript代码。

希望提前感谢一点帮助

  function fnExcelReport() {
    // formatting for the headers
    var tab_text = "<table border='2px'><tr bgcolor='#EE7000'>";
    var textRange;
    var j = 0;
    // grab the table data
    tab = document.getElementById('PrintSummaryTable'); // id of table
    //for each row in the table
    for (j = 0 ; j < tab.rows.length ; j++) {

        tab_text = tab_text + tab.rows[j].innerHTML + "</tr>";
    }

    tab_text = tab_text + "</table>";

    var ua = window.navigator.userAgent;
    var msie = ua.indexOf("MSIE ");

    if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))      // If Internet Explorer
    {
        txtArea1.document.open("txt/html", "replace");
        txtArea1.document.write(tab_text);
        txtArea1.document.close();
        txtArea1.focus();
        sa = txtArea1.document.execCommand("SaveAs", true, "Say Thanks to Sumit.xls");
    }
    else                 //other browser not tested on IE 11
        sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));

    return (sa);
}

<button id="btnExport" onclick="fnExcelReport();"> EXPORT TO EXCEL </button>

0 个答案:

没有答案