【问题标题】:NO linebreaks in the PDF generated by JSPDFJSPDF 生成的 PDF 中没有换行符
【发布时间】:2013-07-09 11:24:22
【问题描述】:

我使用 jspdf 生成一个 pdf,其中包含我网页上表格的数据,表格中的某些条目更长,因此它没有完整显示这些单元格的内容,它只是显示那些特定单元格的内容尽可能多地显示在一行中,其余内容被丢弃。 pdf 文档的下一行包含下一个单元格数据。谁能帮忙??

我的代码:

$("#button3").click(function(){
    var limit = 5000;
    var count = 0;
    arr = new Array();
    $("td").each(function () {
        t = $(this).text();
        if(count <= limit){
        arr.push(t);
        count ++;
       }
    });
    var table = $("#example2").text();
    var pdf = new jsPDF();

    pdf.setFontSize(11); 
    pdf.text(20, 20,arr);
    pdf.save('message.pdf');

});

【问题讨论】:

标签: jquery jspdf


【解决方案1】:

以防万一它对任何人有帮助:

如果您需要动态添加新行,您希望访问 doc.splitTextToSize 返回的数组,然后在遍历每一行时添加更多垂直空间:

var y = 0, lengthOfPage = 500, text = [a bunch of text elements];

//looping thru each text item
for(var i = 0, textlength = text.length ; i < textlength ; i++) {

    var splitTitle = doc.splitTextToSize(text[i], lengthOfPage);

    //loop thru each line and output while increasing the vertical space
    for(var c = 0, stlength = splitTitle.length ; c < stlength ; c++){

        doc.text(y, 20, splitTitle[c]);
        y = y + 10;

    }

}

【讨论】:

    猜你喜欢
    • 2014-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 2017-05-27
    • 1970-01-01
    相关资源
    最近更新 更多