Skip to content

Commit 48a9f7e

Browse files
committed
Fixed some issues again.
1 parent da25b2a commit 48a9f7e

1 file changed

Lines changed: 35 additions & 25 deletions

File tree

jspdf.plugin.cell.js

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
fontName = this.internal.getFont().fontName;
5454
fontSize = this.internal.getFontSize();
5555
fontStyle = this.internal.getFont().fontStyle;
56-
var px2pt = 1.545454545454545454545454, text = $('<font id="jsPDFCell" style="font-family: ' + fontName + ';font-size:' + fontSize + 'pt;font-style: ' + fontStyle + ';">' + txt + '</font>').appendTo('body'),
56+
var px2pt = 1.545454545454545454545454, text = $('<font id="jsPDFCell" style="font-family: ' + fontName + ';font-size:' + fontSize + 'pt;font-style: ' + fontStyle + ';" hidden>' + txt + '</font>').appendTo('body'),
5757
dimentions = { w: text.width() / px2pt, h: text.height() / px2pt};
5858
text.remove();
5959
return dimentions;
@@ -70,27 +70,37 @@
7070
pages = 1;
7171
};
7272

73-
/* sample
73+
/* sample how to make a table
7474
7575
var doc = new jsPDF('p', 'pt');
76-
var i, j = 0;
76+
var i, j, k;
7777
doc.cellInitialize();
78-
for (i = 0; i <= 100; i++ ){
79-
doc.cell(10, 40, 100, 20, 'Cell '+j, i);
80-
j++;
81-
doc.cell(10, 40, 100, 20, 'Cell '+j, i);
82-
j++;
83-
doc.cell(10, 40, 100, 20, 'Cell '+j, i);
84-
j++;
85-
doc.cell(10, 40, 100, 20, 'Cell '+j, i);
86-
j++;
78+
for (i = 1,k = 1; i <= 100; i++ ){
79+
for (j = 1; j <= 4; j++) {
80+
doc.cell(10, 40, 100, 20, 'Cell '+k, i);
81+
k++;
82+
}
8783
}
8884
doc.save('Test.pdf');
89-
90-
*/
85+
var doc2 = new jsPDF('p', 'pt');
86+
var i, j = 0;
87+
doc2.cellInitialize();
88+
for (i = 1,k = 1; i <= 100; i++ ){
89+
doc2.cell(10, 40, 100, 20, 'Cell '+k, i);
90+
k++;
91+
doc2.cell(10, 40, 150, 20, 'Cell '+k, i);
92+
k++;
93+
doc2.cell(10, 40, 90, 20, 'Cell '+k, i);
94+
k++;
95+
doc2.cell(10, 40, 150, 20, 'Cell '+k, i);
96+
k++;
97+
}
98+
doc2.save('Test.pdf');
99+
100+
*/
91101

92102
jsPDFAPI.cell = function (x, y, w, h, txt, ln) {
93-
if ((((ln * h) + y + h) / pages) >= this.internal.pageSize.height && pages === 1) {
103+
if ((((ln * h) + y + (h * 2)) / pages) >= this.internal.pageSize.height && pages === 1) {
94104
this.cellAddPage();
95105
this.setLastCellPosition(undefined, undefined, undefined, undefined, undefined);
96106
if (this.getMaxLn() === 0) {
@@ -103,16 +113,16 @@
103113
var curCell = this.getLastCellPosition(),
104114
dim = this.getTextDimentions(txt);
105115
if (curCell.x !== undefined && curCell.ln === ln) {
106-
x = curCell.x + w;
107-
}
108-
if (curCell.y !== undefined && curCell.y === y) {
109-
y = curCell.y;
110-
}
111-
if (curCell.h !== undefined && curCell.h === h) {
112-
h = curCell.h;
113-
}
114-
if (curCell.ln !== undefined && curCell.ln === ln) {
115-
ln = curCell.ln;
116+
x = curCell.x + curCell.w;
117+
if (curCell.y !== undefined && curCell.y === y) {
118+
y = curCell.y;
119+
}
120+
if (curCell.h !== undefined && curCell.h === h) {
121+
h = curCell.h;
122+
}
123+
if (curCell.ln !== undefined && curCell.ln === ln) {
124+
ln = curCell.ln;
125+
}
116126
}
117127
this.rect(x, (y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))), w, h);
118128
this.text(txt, x + 3, ((y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))) + h - 3));

0 commit comments

Comments
 (0)