Word wrap in generated PDF (using jsPDF)?

后端 未结 6 2046
梦毁少年i
梦毁少年i 2020-12-01 06:06

what I\'m doing is using jsPDF to create a PDF of the graph I generated. However, I am not sure how to wrap the title (added by using the text() function). The length of the

6条回答
  •  误落风尘
    2020-12-01 06:31

    Auto-paging and text wrap issue in JSPDF can achieve with following code

     var splitTitle = doc.splitTextToSize($('#textarea').val(), 270);
        var pageHeight = doc.internal.pageSize.height;
        doc.setFontType("normal");
        doc.setFontSize("11");
        var y = 7;
        for (var i = 0; i < splitTitle.length; i++) {                
            if (y > 280) {
                y = 10;
                doc.addPage();
            }
            doc.text(15, y, splitTitle[i]);
            y = y + 7;
        }
        doc.save('my.pdf');
    

提交回复
热议问题