简体   繁体   中英

jspdf didnot make a pdf of html div

I am using jsPDF to make a PDF of my div container.
that div container is the a invoice in landscape format.
When i click on save button following error is shown in alert box.

Error in function [object Object].: saveAs is not defined

javascript:

<script type="text/javascript" src="assets/jsPDF/jspdf.js"></script>
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.addimage.js"></script>
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.standard_fonts_metrics.js"></script> 
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.split_text_to_size.js"></script>               
<script type="text/javascript" src="assets/jsPDF/jspdf.plugin.from_html.js"></script>
<script type="text/javascript">
   $(document).ready(function(){ 
        var specialElementHandlers = {
        '#editor': function (element,renderer) {
            return true;
        }
    };
 $('#saveinvoicepdf').click(function () {
        var doc = new jsPDF();
        doc.fromHTML($('#projectInvoicebox').html(), 15, 15, {
            'width': 170,'elementHandlers': specialElementHandlers
        });
        doc.save('sample-file.pdf');
    });
});
  </script>

HTML:

<a id="saveinvoicepdf" class="btn btn-two btn-lg" title="Click to print the Invoice">Save as PDF</a>

Thanks.

我有同样的错误,并通过引用jspdf.min.js解决了它:

src="assets/jsPDF/dist/jspdf.js"

您必须包含对FileSaver.min.js的引用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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