0

Im generating a pdf using jspdf which contains the data of a table on my webpage, some entries in table are longer and so it is not displaying the contents of those cells in full, it is just displaying the content of those particular cells as much as it can display in one line and remaining content is dropped. next line of pdf document contain next cells data. Can anyone help??

My code:

$("#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');

});
user1386654
  • 51
  • 3
  • 9

1 Answers1

1

Just in case it helps anyone:

If you need to dynamically add new lines you want to access the array returned by doc.splitTextToSize and then add more vertical space as you go through each line:

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;

    }

}