aiddev
aiddev

Reputation: 1429

jspdf - last paragraph line is being cut

I'm using jspdf library for generating PDF file from html. It is really nice one. But I have an issue with last line on each page of the pdf.

Here is a DEMO and my javascript:

var pdf = new jsPDF();
$('#generatePdfBtn').click(function () {
    pdf.fromHTML($('#printableContent').html(), 15, 15, {
        'width': 400
    });
    pdf.save('myPdf.pdf');
});

When you generate a pdf by clicking on a button, you will see that at the end of the first page we have "pararaph 30" and normally on next page of pdf we should see next "pararaph 31" paragraph. But I don't see it and instead see "pararaph 32". Why last line is being lost? Any ideas please?

Upvotes: 3

Views: 5522

Answers (3)

Ruben Mesa Rodriguez
Ruben Mesa Rodriguez

Reputation: 31

Try this:

Open your jspdf.js or jspdf.debug.js local file and modify this:

this.pdf.internal.getVerticalCoordinateString(this.y), style.color, "Td");

Erasing style.color and save as:

this.pdf.internal.getVerticalCoordinateString(this.y), "Td");

Then it runs correctly on firefox and chrome. At least that worked for me and this is a solution until they fix that failure.

Upvotes: 3

David R
David R

Reputation: 15667

Well there is a trick, If you can determine, where you need to put the page break, then you can simply place a "" there to force it. In this way you can avoid the text from being chopped off.

Working DEMO: http://jsfiddle.net/nq361uoz/4/

Unfortunately, this is a known bug in jsPDF which is still in open status in the GitHub repository.

More info here: https://github.com/MrRio/jsPDF/issues/555

Hope this helps!

Upvotes: 1

Ivan  Reznikov
Ivan Reznikov

Reputation: 108

My guess it cut's the line as it is written not within the margins. Most simple way is to make a loop, that every 31th row is duplicated. Not the best solution, but the quickest.

Upvotes: 0

Related Questions