|
53 | 53 | fontName = this.internal.getFont().fontName; |
54 | 54 | fontSize = this.internal.getFontSize(); |
55 | 55 | 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'), |
57 | 57 | dimentions = { w: text.width() / px2pt, h: text.height() / px2pt}; |
58 | 58 | text.remove(); |
59 | 59 | return dimentions; |
|
70 | 70 | pages = 1; |
71 | 71 | }; |
72 | 72 |
|
73 | | - /* sample |
| 73 | + /* sample how to make a table |
74 | 74 | |
75 | 75 | var doc = new jsPDF('p', 'pt'); |
76 | | - var i, j = 0; |
| 76 | + var i, j, k; |
77 | 77 | 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 | + } |
87 | 83 | } |
88 | 84 | 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 | + */ |
91 | 101 |
|
92 | 102 | 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) { |
94 | 104 | this.cellAddPage(); |
95 | 105 | this.setLastCellPosition(undefined, undefined, undefined, undefined, undefined); |
96 | 106 | if (this.getMaxLn() === 0) { |
|
103 | 113 | var curCell = this.getLastCellPosition(), |
104 | 114 | dim = this.getTextDimentions(txt); |
105 | 115 | 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 | + } |
116 | 126 | } |
117 | 127 | this.rect(x, (y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))), w, h); |
118 | 128 | this.text(txt, x + 3, ((y + (h * Math.abs(this.getMaxLn() * pages - ln - this.getMaxLn()))) + h - 3)); |
|
0 commit comments