Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.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 TypeError:pdf.fromHTML不是使用jspdf将html转换为pdf的函数_Javascript_Java_Pdf_Jspdf - Fatal编程技术网

Javascript TypeError:pdf.fromHTML不是使用jspdf将html转换为pdf的函数

Javascript TypeError:pdf.fromHTML不是使用jspdf将html转换为pdf的函数,javascript,java,pdf,jspdf,Javascript,Java,Pdf,Jspdf,我正在尝试使用jsPDF将jsp代码转换为PDF文件。但它给了我 TypeError:pdf.fromHTML不是函数。 我已经从下载了jspdf zip。 我的代码是: <html> <head> <title>Exporting table data to pdf Example</title> <script type="text/javascript" src="https://code.jquery.com/jquery-2

我正在尝试使用jsPDF将jsp代码转换为PDF文件。但它给了我 TypeError:pdf.fromHTML不是函数。 我已经从下载了jspdf zip。 我的代码是:

 <html>
<head>

<title>Exporting table data to pdf Example</title>


<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script>
<script src="jsPDF/jspdf.js"></script>
<script src="jsPDF/main.js"></script>



<script type="text/javascript">
    $(document).ready(function() {

        $("#exportpdf").click(function() {
            var pdf = new jsPDF('p', 'pt', 'ledger');
            // source can be HTML-formatted string, or a reference
            // to an actual DOM element from which the text will be scraped.
            source = $('#yourTableIdName')[0];

            // we support special element handlers. Register them with jQuery-style 
            // ID selector for either ID or node name. ("#iAmID", "div", "span" etc.)
            // There is no support for any other type of selectors 
            // (class, of compound) at this time.
            specialElementHandlers = {
                // element with id of "bypass" - jQuery style selector
                '#bypassme' : function(element, renderer) {
                    // true = "handled elsewhere, bypass text extraction"
                    return true
                }
            };
            margins = {
                top : 80,
                bottom : 60,
                left : 60,
                width : 522
            };
            // all coords and widths are in jsPDF instance's declared units
            // 'inches' in this case
            pdf.fromHTML(source, // HTML string or DOM elem ref.
            margins.left, // x coord
            margins.top, { // y coord
                'width' : margins.width, // max width of content on PDF
                'elementHandlers' : specialElementHandlers
            },

            function(dispose) {
                // dispose: object with X, Y of the last line add to the PDF 
                //          this allow the insertion of new lines after html
                pdf.save('fileNameOfGeneretedPdf.pdf');
            }, margins);
        });

    });
</script>



</head>
<body>
<div id="yourTableIdName">
    <table style="width: 1020px;font-size: 12px;" border="1">
        <thead>
            <tr align="left">
                <th>Country</th>
                <th>State</th>
                <th>City</th>
            </tr>
        </thead>


        <tbody>

            <tr align="left">
                <td>India</td>
                <td>Telangana</td>
                <td>Nirmal</td>
            </tr>
<tr align="left">
                <td>India</td>
                <td>Telangana</td>
                <td>Nirmal</td>
            </tr><tr align="left">
                <td>India</td>
                <td>Telangana</td>
                <td>Nirmal</td>
            </tr><tr align="left">
                <td>India</td>
                <td>Telangana</td>
                <td>Nirmal</td>
            </tr><tr align="left">
                <td>India</td>
                <td>Telangana</td>
                <td>Nirmal</td>
            </tr><tr align="left">
                <td>India</td>
                <td>Telangana</td>
                <td>Nirmal</td>
            </tr><tr align="left">
                <td>India</td>
                <td>Telangana</td>
                <td>Nirmal</td>
            </tr>
        </tbody>
    </table></div>

    <input type="button" id="exportpdf" value="Download PDF">


</body>

</html>

将表格数据导出为pdf示例
$(文档).ready(函数(){
$(“#导出PDF”)。单击(函数(){
var pdf=新的jsPDF(“p”、“pt”、“分类账”);
//源可以是HTML格式的字符串或引用
//到实际的DOM元素,文本将从该元素中删除。
source=$('#yourTableIdName')[0];
//我们支持特殊的元素处理程序。用jQuery风格注册它们
//ID或节点名称的ID选择器。(“#iAmID”、“div”、“span”等)
//不支持任何其他类型的选择器
//(类,指化合物)此时。
SpecialElementHandler={
//id为“bypass”的元素-jQuery样式选择器
“#绕过我”:函数(元素、渲染器){
//true=“在别处处理,绕过文本提取”
返回真值
}
};
边距={
排名:80,
底数:60,
左:60,,
宽度:522
};
//所有坐标和宽度都以jsPDF实例声明的单位表示
//在本例中为“英寸”
fromHTML(源代码,//HTML字符串或DOM元素参考。
margins.left,//x坐标
margins.top,{//y坐标
“宽度”:margins.width,//PDF上内容的最大宽度
“elementHandlers”:specialElementHandlers
},
功能(处置){
//dispose:将最后一行的X,Y添加到PDF中的对象
//这允许在html之后插入新行
保存('fileNameOfGeneretedPdf.pdf');
},利润率);
});
});
国家
陈述
城市
印度
泰兰加纳
尼马尔
印度
泰兰加纳
尼马尔
印度
泰兰加纳
尼马尔
印度
泰兰加纳
尼马尔
印度
泰兰加纳
尼马尔
印度
泰兰加纳
尼马尔
印度
泰兰加纳
尼马尔

您加载的文件错误

有了Javascript库,就有了原始的源文件,然后就有了准备分发的编译文件。因此,每当您查看这样一个库,并且希望找到要包含的文件时,通常都会签入dist/目录。因此,您只需要包含
jspdf.debug.js
jspdf.min.js

存储库中包含的示例是了解如何包含和使用库的好方法。在这里查看基本示例:


只需使用以下依赖项即可

<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.debug.js"></script>

确保不包含任何其他会覆盖jspdf.debug.js文件的jspdf.js文件。包括多个版本也会导致问题