簡體   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