|
81 | 81 | lastCellPos = { x: undefined, y: undefined, w: undefined, h: undefined, ln: undefined }; |
82 | 82 | pages = 1; |
83 | 83 | }; |
84 | | - |
85 | | - /* sample how to make a table |
86 | | - |
87 | | - var doc = new jsPDF('p', 'pt'); |
88 | | - var i, j, k; |
89 | | - doc.cellInitialize(); |
90 | | - for (i = 1,k = 1; i <= 100; i++ ){ |
91 | | - for (j = 1; j <= 4; j++) { |
92 | | - doc.cell(10, 40, 100, 20, 'Cell '+k, i); |
93 | | - k++; |
| 84 | + |
| 85 | + jsPDFAPI.cell = function (x, y, w, h, txt, ln) { |
| 86 | + if(this.printingHeaderRow !== true && this.lnMod !== 0){ |
| 87 | + ln = ln + this.lnMod; |
94 | 88 | } |
95 | | - } |
96 | | - doc.save('Test.pdf'); |
97 | | - var doc2 = new jsPDF('p', 'pt'); |
98 | | - var i, j = 0; |
99 | | - doc2.cellInitialize(); |
100 | | - for (i = 1,k = 1; i <= 100; i++ ){ |
101 | | - doc2.cell(10, 40, 100, 20, 'Cell '+k, i); |
102 | | - k++; |
103 | | - doc2.cell(10, 40, 150, 20, 'Cell '+k, i); |
104 | | - k++; |
105 | | - doc2.cell(10, 40, 90, 20, 'Cell '+k, i); |
106 | | - k++; |
107 | | - doc2.cell(10, 40, 150, 20, 'Cell '+k, i); |
108 | | - k++; |
109 | | - } |
110 | | - doc2.save('Test.pdf'); |
111 | | - |
112 | | - */ |
| 89 | + |
| 90 | + if ((((ln * h) + y + (h * 2)) / pages) >= this.internal.pageSize.height && pages === 1) { |
| 91 | + this.cellAddPage(); |
| 92 | + if(this.printHeaders && this.tableHeaderRow){ |
| 93 | + this.printHeaderRow(ln); |
| 94 | + this.lnMod++; |
| 95 | + ln++; |
| 96 | + } |
| 97 | + this.setLastCellPosition(undefined, undefined, undefined, undefined, undefined); |
| 98 | + if (this.getMaxLn() === 0) { |
| 99 | + this.setMaxLn(ln); |
| 100 | + } |
| 101 | + } else if (pages > 1 && this.getMaxLn() === ln / pages) { |
| 102 | + this.cellAddPage(); |
| 103 | + if(this.printHeaders && this.tableHeaderRow){ |
| 104 | + this.printHeaderRow(ln); |
| 105 | + this.lnMod++; |
| 106 | + ln++; |
| 107 | + } |
| 108 | + |
| 109 | + this.setLastCellPosition(undefined, undefined, undefined, undefined, undefined); |
| 110 | + } |
| 111 | + var curCell = this.getLastCellPosition(); |
| 112 | + |
| 113 | + if (curCell.x !== undefined && curCell.ln === ln) { |
| 114 | + x = curCell.x + curCell.w; |
| 115 | + if (curCell.y !== undefined && curCell.y === y) { |
| 116 | + y = curCell.y; |
| 117 | + } |
| 118 | + if (curCell.h !== undefined && curCell.h === h) { |
| 119 | + h = curCell.h; |
| 120 | + } |
| 121 | + if (curCell.ln !== undefined && curCell.ln === ln) { |
| 122 | + ln = curCell.ln; |
| 123 | + } |
| 124 | + } |
| 125 | + this.rect(x, (y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))), w, h); |
| 126 | + this.text(txt, x + 3, ((y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))) + h - 3)); |
| 127 | + this.setLastCellPosition(x, y, w, h, ln); |
| 128 | + return this; |
| 129 | + }; |
| 130 | + |
113 | 131 |
|
114 | 132 | /** |
115 | 133 | * Create a table from an {#Ext.data.Store} or a set of data. |
|
231 | 249 | this.printingHeaderRow = false; |
232 | 250 | }; |
233 | 251 |
|
234 | | - jsPDFAPI.cell = function (x, y, w, h, txt, ln) { |
235 | | - if(this.printingHeaderRow !== true && this.lnMod !== 0){ |
236 | | - ln = ln + this.lnMod; |
237 | | - } |
238 | | - |
239 | | - if ((((ln * h) + y + (h * 2)) / pages) >= this.internal.pageSize.height && pages === 1) { |
240 | | - this.cellAddPage(); |
241 | | - if(this.printHeaders && this.tableHeaderRow){ |
242 | | - this.printHeaderRow(ln); |
243 | | - this.lnMod++; |
244 | | - ln++; |
245 | | - } |
246 | | - this.setLastCellPosition(undefined, undefined, undefined, undefined, undefined); |
247 | | - if (this.getMaxLn() === 0) { |
248 | | - this.setMaxLn(ln); |
249 | | - } |
250 | | - } else if (pages > 1 && this.getMaxLn() === ln / pages) { |
251 | | - this.cellAddPage(); |
252 | | - if(this.printHeaders && this.tableHeaderRow){ |
253 | | - this.printHeaderRow(ln); |
254 | | - this.lnMod++; |
255 | | - ln++; |
256 | | - } |
257 | | - |
258 | | - this.setLastCellPosition(undefined, undefined, undefined, undefined, undefined); |
259 | | - } |
260 | | - var curCell = this.getLastCellPosition(); |
261 | | - |
262 | | - if (curCell.x !== undefined && curCell.ln === ln) { |
263 | | - x = curCell.x + curCell.w; |
264 | | - if (curCell.y !== undefined && curCell.y === y) { |
265 | | - y = curCell.y; |
266 | | - } |
267 | | - if (curCell.h !== undefined && curCell.h === h) { |
268 | | - h = curCell.h; |
269 | | - } |
270 | | - if (curCell.ln !== undefined && curCell.ln === ln) { |
271 | | - ln = curCell.ln; |
272 | | - } |
273 | | - } |
274 | | - this.rect(x, (y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))), w, h); |
275 | | - this.text(txt, x + 3, ((y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))) + h - 3)); |
276 | | - this.setLastCellPosition(x, y, w, h, ln); |
277 | | - return this; |
278 | | - }; |
279 | | - |
280 | 252 | })(jsPDF.API); |
0 commit comments