Skip to content

Commit 4c9c0ec

Browse files
committed
Automatically add new pages if .text() would overflow - closes #119
1 parent 7da6aac commit 4c9c0ec

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

jspdf.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ var jsPDF = (function(global) {
968968
angle = flags;
969969
flags = null;
970970
}
971-
var xtra = '',mode = 'Td';
971+
var xtra = '',mode = 'Td', todo;
972972
if (angle) {
973973
angle *= (Math.PI / 180);
974974
var c = Math.cos(angle),
@@ -992,6 +992,10 @@ var jsPDF = (function(global) {
992992
while (len--) {
993993
da.push(ESC(sa.shift()));
994994
}
995+
var linesLeft = Math.ceil((pageHeight - y) * k / (activeFontSize * lineHeightProportion));
996+
if (0 <= linesLeft && linesLeft < da.length + 1) {
997+
todo = da.splice(linesLeft-1);
998+
}
995999
text = da.join(") Tj\nT* (");
9961000
} else {
9971001
throw new Error('Type of text must be string or Array. "' + text + '" is not recognized.');
@@ -1011,6 +1015,12 @@ var jsPDF = (function(global) {
10111015
'\n' + xtra + f2(x * k) + ' ' + f2((pageHeight - y) * k) + ' ' + mode + '\n(' +
10121016
text +
10131017
') Tj\nET');
1018+
1019+
if (todo) {
1020+
this.addPage();
1021+
this.text( todo, x, activeFontSize * 1.7 / k);
1022+
}
1023+
10141024
return this;
10151025
};
10161026

0 commit comments

Comments
 (0)