繁体   English   中英

将div保存到PDF时未定义jsPDF

[英]jsPDF is not defined when saving div to PDF

我正在尝试使用 jsPDF 保存具有特定 id 的 div 元素,但得到Uncaught ReferenceError: jsPDF is not defined 尝试了很多不同的方法来解决这个问题,包括 stackoverflow 上所有可用的解决方案,但没有一个有效。

这是 div 元素的样子(它是一个根据用户选择自动填充的表格,我删除了大多数选项以减少此示例的行数)。 下面是一个快速片段,可以让您了解正在发生的事情。 它仍然说 jsPDF 没有定义:

 $('#savePDF').click(function() { var pdf = new jsPDF('p', 'pt', 'letter'); source = $('#yourSummary'); specialElementHandlers = { '#bypassme': function (element, renderer) { return true } }; margins = { top: 80, bottom: 60, left: 40, width: 522 }; pdf.fromHTML( source, margins.left, margins.top, { 'width': margins.width, 'elementHandlers': specialElementHandlers }, function (dispose) { pdf.save('your-summary.pdf'); }, margins ); });
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://unpkg.com/jspdf@latest/dist/jspdf.umd.min.js"></script> <div id="yourSummary" class="modal-body"> <table id="yourExterior" class="table table-hover"> <h5>Exterior</h5> <tbody> <tr> <th scope="row">Body colour</th> <td id="sumBC"></td> </tr> </tbody> </table> </div> <button class="btn-primary" id="savePDF">Save configuration as PDF</button>

但是,一旦我在浏览器中按下按钮,就会出现以下错误:

Uncaught ReferenceError: jsPDF is not defined
at HTMLButtonElement.<anonymous> (main.js:34)
at HTMLButtonElement.dispatch (jquery-3.5.1.slim.min.js:2)
at HTMLButtonElement.v.handle (jquery-3.5.1.slim.min.js:2)

我做错了什么以及如何解决这个问题?

使用以前的版本
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"></script>

2.0.0 版本非常不同。
例如,您将使用 jspdf.jsPDF 而不是方法“jsPDF”,但您会看到新的错误。

暂无
暂无

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

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