简体   繁体   English

jspdf不产生PDF

[英]jspdf not producing a PDF

So I've been working on trying to convert an HTML file produced to a PDF. 因此,我一直在尝试将生成的HTML文件转换为PDF。 I have been looking at JSPDF and come up with the following code but when I hit submit nothing happens, I can see no error in my browser debug. 我一直在查看JSPDF并提供以下代码,但是当我单击“提交”时,没有任何反应,在浏览器调试中看不到任何错误。

        <!DOCTYPE html>  <html lang="en"><head>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js"></script>
    <script>
    var doc = new jsPDF(); 
    var specialElementHandlers = { 
        '#editor': function (element, renderer) { 
            return true; 
        } 
    };
    $('#submit').click(function () { 
        doc.fromHTML($('#content').html(), 15, 15, { 
            'width': 522, 
                'elementHandlers': specialElementHandlers 
        }); 
        doc.save('Logbook Summary.pdf'); 
    });

    </script>

    <div id="content"> 

     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><title>Logbook Summary</title>    

    </head> 
Test text here

</div> <div id="page"></div>

<button id="submit">Export to  PDF</button>

 </html> 

Any help would be appreciated, I am sure I am missing something simple here. 任何帮助将不胜感激,我敢肯定,我在这里缺少一些简单的东西。

Sorted 已排序

This is because I defined my "doc" variable outside of my click event. 这是因为我在点击事件之外定义了“ doc”变量。

Sorted it from this thread: 从此线程对其进行排序:

Export HTML page to PDF on user click using JavaScript 使用JavaScript在用户单击时将HTML页面导出为PDF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM