pdfmake 0.3.0-beta.10 → 0.3.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -204,9 +204,12 @@ class ElementWriter extends _events.EventEmitter {
204
204
  });
205
205
  }
206
206
  }
207
- addVector(vector, ignoreContextX, ignoreContextY, index) {
207
+ addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
208
208
  let context = this.context();
209
209
  let page = context.getCurrentPage();
210
+ if ((0, _variableType.isNumber)(forcePage)) {
211
+ page = context.pages[forcePage];
212
+ }
210
213
  let position = this.getCurrentPositionOnPage();
211
214
  if (page) {
212
215
  (0, _tools.offsetVector)(vector, ignoreContextX ? 0 : context.x, ignoreContextY ? 0 : context.y);
@@ -36,8 +36,8 @@ class PageElementWriter extends _ElementWriter.default {
36
36
  addAttachment(attachment, index) {
37
37
  return this._fitOnPage(() => super.addAttachment(attachment, index));
38
38
  }
39
- addVector(vector, ignoreContextX, ignoreContextY, index) {
40
- return super.addVector(vector, ignoreContextX, ignoreContextY, index);
39
+ addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
40
+ return super.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
41
41
  }
42
42
  beginClip(width, height) {
43
43
  return super.beginClip(width, height);
@@ -113,13 +113,18 @@ class TableProcessor {
113
113
  }
114
114
  }
115
115
  this.dontBreakRows = tableNode.table.dontBreakRows || false;
116
- if (this.rowsWithoutPageBreak) {
116
+ if (this.rowsWithoutPageBreak || this.dontBreakRows) {
117
117
  writer.beginUnbreakableBlock();
118
+ // Draw the top border of the table
119
+ this.drawHorizontalLine(0, writer);
120
+ if (this.rowsWithoutPageBreak && this.dontBreakRows) {
121
+ // We just increase the value of transactionLevel
122
+ writer.beginUnbreakableBlock();
123
+ }
118
124
  }
119
125
 
120
126
  // update the border properties of all cells before drawing any lines
121
127
  prepareCellBorders(this.tableNode.table.body);
122
- this.drawHorizontalLine(0, writer);
123
128
  }
124
129
  onRowBreak(rowIndex, writer) {
125
130
  return () => {
@@ -135,7 +140,12 @@ class TableProcessor {
135
140
  this.rowPaddingBottom = this.layout.paddingBottom(rowIndex, this.tableNode);
136
141
  this.rowCallback = this.onRowBreak(rowIndex, writer);
137
142
  writer.addListener('pageChanged', this.rowCallback);
138
- if (this.dontBreakRows) {
143
+ if (rowIndex == 0 && !this.dontBreakRows && !this.rowsWithoutPageBreak) {
144
+ // We store the 'y' to draw later and if necessary the top border of the table
145
+ this._tableTopBorderY = writer.context().y;
146
+ writer.context().moveDown(this.topLineWidth);
147
+ }
148
+ if (this.dontBreakRows && rowIndex > 0) {
139
149
  writer.beginUnbreakableBlock();
140
150
  }
141
151
  this.rowTopY = writer.context().y;
@@ -143,7 +153,7 @@ class TableProcessor {
143
153
  writer.context().availableHeight -= this.reservedAtBottom;
144
154
  writer.context().moveDown(this.rowPaddingTop);
145
155
  }
146
- drawHorizontalLine(lineIndex, writer, overrideY) {
156
+ drawHorizontalLine(lineIndex, writer, overrideY, moveDown = true, forcePage) {
147
157
  let lineWidth = this.layout.hLineWidth(lineIndex, this.tableNode);
148
158
  if (lineWidth) {
149
159
  let style = this.layout.hLineStyle(lineIndex, this.tableNode);
@@ -237,7 +247,7 @@ class TableProcessor {
237
247
  lineWidth: lineWidth,
238
248
  dash: dash,
239
249
  lineColor: borderColor
240
- }, false, overrideY);
250
+ }, false, (0, _variableType.isNumber)(overrideY), null, forcePage);
241
251
  currentLine = null;
242
252
  borderColor = null;
243
253
  cellAbove = null;
@@ -246,7 +256,9 @@ class TableProcessor {
246
256
  }
247
257
  }
248
258
  }
249
- writer.context().moveDown(lineWidth);
259
+ if (moveDown) {
260
+ writer.context().moveDown(lineWidth);
261
+ }
250
262
  }
251
263
  }
252
264
  drawVerticalLine(x, y0, y1, vLineColIndex, writer, vLineRowIndex, beforeVLineColIndex) {
@@ -369,6 +381,15 @@ class TableProcessor {
369
381
  }
370
382
  ys[ys.length - 1].y1 = endingY;
371
383
  let skipOrphanePadding = ys[0].y1 - ys[0].y0 === this.rowPaddingTop;
384
+ if (rowIndex === 0 && !skipOrphanePadding && !this.rowsWithoutPageBreak && !this.dontBreakRows) {
385
+ // Draw the top border of the table
386
+ let pageTableStartedAt = null;
387
+ if (pageBreaks && pageBreaks.length > 0) {
388
+ // Get the page where table started at
389
+ pageTableStartedAt = pageBreaks[0].prevPage;
390
+ }
391
+ this.drawHorizontalLine(0, writer, this._tableTopBorderY, false, pageTableStartedAt);
392
+ }
372
393
  for (let yi = skipOrphanePadding ? 1 : 0, yl = ys.length; yi < yl; yi++) {
373
394
  let willBreak = yi < ys.length - 1;
374
395
  let rowBreakWithoutHeader = yi > 0 && !this.headerRows;
@@ -385,6 +406,14 @@ class TableProcessor {
385
406
  // TableProcessor should be pageChanged listener, instead of processRow
386
407
  this.reservedAtBottom = 0;
387
408
  }
409
+
410
+ // Draw horizontal lines before the vertical lines so they are not overridden
411
+ if (willBreak && this.layout.hLineWhenBroken !== false) {
412
+ this.drawHorizontalLine(rowIndex + 1, writer, y2);
413
+ }
414
+ if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
415
+ this.drawHorizontalLine(rowIndex, writer, y1);
416
+ }
388
417
  for (let i = 0, l = xs.length; i < l; i++) {
389
418
  let leftCellBorder = false;
390
419
  let rightCellBorder = false;
@@ -467,12 +496,6 @@ class TableProcessor {
467
496
  }
468
497
  }
469
498
  }
470
- if (willBreak && this.layout.hLineWhenBroken !== false) {
471
- this.drawHorizontalLine(rowIndex + 1, writer, y2);
472
- }
473
- if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
474
- this.drawHorizontalLine(rowIndex, writer, y1);
475
- }
476
499
  }
477
500
  writer.context().page = endingPage;
478
501
  writer.context().y = endingY;
@@ -505,7 +528,8 @@ class TableProcessor {
505
528
  }
506
529
  if (this.dontBreakRows) {
507
530
  const pageChangedCallback = () => {
508
- if (!this.headerRows && this.layout.hLineWhenBroken !== false) {
531
+ if (rowIndex > 0 && !this.headerRows && this.layout.hLineWhenBroken !== false) {
532
+ // Draw the top border of the row after a page break
509
533
  this.drawHorizontalLine(rowIndex, writer);
510
534
  }
511
535
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdfmake",
3
- "version": "0.3.0-beta.10",
3
+ "version": "0.3.0-beta.11",
4
4
  "description": "Client/server side PDF printing in pure JavaScript",
5
5
  "main": "js/index.js",
6
6
  "esnext": "src/index.js",
@@ -259,9 +259,12 @@ class ElementWriter extends EventEmitter {
259
259
  }
260
260
  }
261
261
 
262
- addVector(vector, ignoreContextX, ignoreContextY, index) {
262
+ addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
263
263
  let context = this.context();
264
264
  let page = context.getCurrentPage();
265
+ if (isNumber(forcePage)) {
266
+ page = context.pages[forcePage];
267
+ }
265
268
  let position = this.getCurrentPositionOnPage();
266
269
 
267
270
  if (page) {
@@ -39,8 +39,8 @@ class PageElementWriter extends ElementWriter {
39
39
  return this._fitOnPage(() => super.addAttachment(attachment, index));
40
40
  }
41
41
 
42
- addVector(vector, ignoreContextX, ignoreContextY, index) {
43
- return super.addVector(vector, ignoreContextX, ignoreContextY, index);
42
+ addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
43
+ return super.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
44
44
  }
45
45
 
46
46
  beginClip(width, height) {
@@ -125,14 +125,18 @@ class TableProcessor {
125
125
 
126
126
  this.dontBreakRows = tableNode.table.dontBreakRows || false;
127
127
 
128
- if (this.rowsWithoutPageBreak) {
128
+ if (this.rowsWithoutPageBreak || this.dontBreakRows) {
129
129
  writer.beginUnbreakableBlock();
130
+ // Draw the top border of the table
131
+ this.drawHorizontalLine(0, writer);
132
+ if (this.rowsWithoutPageBreak && this.dontBreakRows) {
133
+ // We just increase the value of transactionLevel
134
+ writer.beginUnbreakableBlock();
135
+ }
130
136
  }
131
137
 
132
138
  // update the border properties of all cells before drawing any lines
133
139
  prepareCellBorders(this.tableNode.table.body);
134
-
135
- this.drawHorizontalLine(0, writer);
136
140
  }
137
141
 
138
142
  onRowBreak(rowIndex, writer) {
@@ -151,7 +155,12 @@ class TableProcessor {
151
155
 
152
156
  this.rowCallback = this.onRowBreak(rowIndex, writer);
153
157
  writer.addListener('pageChanged', this.rowCallback);
154
- if (this.dontBreakRows) {
158
+ if (rowIndex == 0 && !this.dontBreakRows && !this.rowsWithoutPageBreak) {
159
+ // We store the 'y' to draw later and if necessary the top border of the table
160
+ this._tableTopBorderY = writer.context().y;
161
+ writer.context().moveDown(this.topLineWidth);
162
+ }
163
+ if (this.dontBreakRows && rowIndex > 0) {
155
164
  writer.beginUnbreakableBlock();
156
165
  }
157
166
  this.rowTopY = writer.context().y;
@@ -162,7 +171,7 @@ class TableProcessor {
162
171
  writer.context().moveDown(this.rowPaddingTop);
163
172
  }
164
173
 
165
- drawHorizontalLine(lineIndex, writer, overrideY) {
174
+ drawHorizontalLine(lineIndex, writer, overrideY, moveDown = true, forcePage) {
166
175
  let lineWidth = this.layout.hLineWidth(lineIndex, this.tableNode);
167
176
  if (lineWidth) {
168
177
  let style = this.layout.hLineStyle(lineIndex, this.tableNode);
@@ -260,7 +269,7 @@ class TableProcessor {
260
269
  lineWidth: lineWidth,
261
270
  dash: dash,
262
271
  lineColor: borderColor
263
- }, false, overrideY);
272
+ }, false, isNumber(overrideY), null, forcePage);
264
273
  currentLine = null;
265
274
  borderColor = null;
266
275
  cellAbove = null;
@@ -270,7 +279,9 @@ class TableProcessor {
270
279
  }
271
280
  }
272
281
 
273
- writer.context().moveDown(lineWidth);
282
+ if (moveDown) {
283
+ writer.context().moveDown(lineWidth);
284
+ }
274
285
  }
275
286
  }
276
287
 
@@ -406,6 +417,15 @@ class TableProcessor {
406
417
  ys[ys.length - 1].y1 = endingY;
407
418
 
408
419
  let skipOrphanePadding = (ys[0].y1 - ys[0].y0 === this.rowPaddingTop);
420
+ if (rowIndex === 0 && !skipOrphanePadding && !this.rowsWithoutPageBreak && !this.dontBreakRows) {
421
+ // Draw the top border of the table
422
+ let pageTableStartedAt = null;
423
+ if (pageBreaks && pageBreaks.length > 0) {
424
+ // Get the page where table started at
425
+ pageTableStartedAt = pageBreaks[0].prevPage;
426
+ }
427
+ this.drawHorizontalLine(0, writer, this._tableTopBorderY, false, pageTableStartedAt);
428
+ }
409
429
  for (let yi = (skipOrphanePadding ? 1 : 0), yl = ys.length; yi < yl; yi++) {
410
430
  let willBreak = yi < ys.length - 1;
411
431
  let rowBreakWithoutHeader = (yi > 0 && !this.headerRows);
@@ -425,6 +445,14 @@ class TableProcessor {
425
445
  this.reservedAtBottom = 0;
426
446
  }
427
447
 
448
+ // Draw horizontal lines before the vertical lines so they are not overridden
449
+ if (willBreak && this.layout.hLineWhenBroken !== false) {
450
+ this.drawHorizontalLine(rowIndex + 1, writer, y2);
451
+ }
452
+ if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
453
+ this.drawHorizontalLine(rowIndex, writer, y1);
454
+ }
455
+
428
456
  for (let i = 0, l = xs.length; i < l; i++) {
429
457
  let leftCellBorder = false;
430
458
  let rightCellBorder = false;
@@ -511,13 +539,6 @@ class TableProcessor {
511
539
  }
512
540
  }
513
541
  }
514
-
515
- if (willBreak && this.layout.hLineWhenBroken !== false) {
516
- this.drawHorizontalLine(rowIndex + 1, writer, y2);
517
- }
518
- if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
519
- this.drawHorizontalLine(rowIndex, writer, y1);
520
- }
521
542
  }
522
543
 
523
544
  writer.context().page = endingPage;
@@ -556,7 +577,8 @@ class TableProcessor {
556
577
 
557
578
  if (this.dontBreakRows) {
558
579
  const pageChangedCallback = () => {
559
- if (!this.headerRows && this.layout.hLineWhenBroken !== false) {
580
+ if (rowIndex > 0 && !this.headerRows && this.layout.hLineWhenBroken !== false) {
581
+ // Draw the top border of the row after a page break
560
582
  this.drawHorizontalLine(rowIndex, writer);
561
583
  }
562
584
  };