jspdf脚本有问题

问题描述 投票:0回答:1

我已在我的网站上添加此jspdf脚本以下载pdf。但是我收到此错误。

        Uncaught TypeError: Cannot read property '1' of undefined
            at f.renderParagraph (jspdf.min.js:202)
            at f.setBlockBoundary (jspdf.min.js:202)
            at k (jspdf.min.js:202)
            at k (jspdf.min.js:202)
            at k (jspdf.min.js:202)
            at jspdf.min.js:202
            at l (jspdf.min.js:202)
            at Image.i.onerror.i.onload (jspdf.min.js:202)

这在某些页面上会发生,而其他页面则可以。我在下面添加了我正在使用的代码。我不确定是否与我的代码或jspdf有关。

    //Code I am using: 
        <script type="text/javascript">
        function HTMLtoPDF(){
        var pdf = new jsPDF('p', 'pt', 'letter');
        source = $('#HTMLtoPDF')[0];
        specialElementHandlers = {
            '#bypassme': function(element, renderer){
                return true
            }
        }
        margins = {
                top: 50,
                left: 60,
                right:60,
                width: 545
            };
        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('Download.pdf');
                    }
            )
        }

        </script>
        <button type="button" onclick="HTMLtoPDF()" style=" height: 40px; width: 154px; background-color: #008800; color: #ffffff; font-size: 150%;">Download PDF </button>

        <script src = "https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.5.3/jspdf.min.js"> </script>
        <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
jspdf
1个回答
0
投票
script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.3.2/jspdf.min.js"></script>
  <script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>    
<script type="text/javascript">
$(document).ready(function() {
var str_pdf = $("#HTMLtoPDF").html();
var regex = /<br\s*[\/]?>/gi;
$("#HTMLtoPDF").html(str_pdf.replace(regex, '<p data-empty="true"><br></p>'));
});
function HTMLtoPDF(){
    var pdf = new jsPDF('p', 'pt', 'a4');
    source = $('#HTMLtoPDF')[0];
    specialElementHandlers = {
        '#bypassme': function (element, renderer) {
            return true
        }
    };
    margins = {
        top: 30,
        bottom: 30,
        left: 40,
        width: 522
    };
    pdf.fromHTML(
    source, 
    margins.left, 
    margins.top, { 
        'width': margins.width, 
        'elementHandlers': specialElementHandlers
    },

    function (dispose) {
        pdf.save('Download.pdf');
    }, margins);
}
</script>

<!-- these js files are used for making PDF -->
© www.soinside.com 2019 - 2024. All rights reserved.