Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/442.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何下载pdf文件中的html页面_Javascript_Jquery_Pdf_Jspdf_Html To Pdf - Fatal编程技术网

Javascript 如何下载pdf文件中的html页面

Javascript 如何下载pdf文件中的html页面,javascript,jquery,pdf,jspdf,html-to-pdf,Javascript,Jquery,Pdf,Jspdf,Html To Pdf,我已经编写了一些java脚本代码,以便将html页面下载到excel,这很好,但是我不知道如何使用javascript代码下载pdf文件 如果您能帮我一点忙,我将不胜感激 function fnExcelReport() { // formatting for the headers var tab_text = "<table border='2px'><tr bgcolor='#EE7000'>"; var textRange; v

我已经编写了一些java脚本代码,以便将html页面下载到excel,这很好,但是我不知道如何使用javascript代码下载pdf文件

如果您能帮我一点忙,我将不胜感激

  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>
函数fnExcelReport(){
//标题的格式设置
var tab_text=“”;
变量范围;
var j=0;
//抓取表格数据
tab=document.getElementById('PrintSummaryTable');//表的id
//对于表中的每一行
对于(j=0;j0 | |!!navigator.userAgent.match(/Trident.*rv \:11\./)//如果Internet Explorer
{
打开(“txt/html”,“replace”);
txtArea1.文档。写入(制表符文本);
txtArea1.document.close();
txtArea1.focus();
sa=txtArea1.document.execCommand(“SaveAs”,true,“Say than to Sumit.xls”);
}
else//其他浏览器未在IE 11上测试
sa=window.open('data:application/vnd.ms excel',+encodeURIComponent(制表符文本));
返回(sa);
}
导出到EXCEL

如果可以,请发布您的代码,无论如何,根据我的理解,您需要此
@Ryad code posted您可以使用jsdf将html页面转换为pdf。您可以在此处找到此库: