pdfmake 0.3.0-beta.9 → 0.3.0

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.
Files changed (74) hide show
  1. package/CHANGELOG.md +7 -48
  2. package/LICENSE +1 -1
  3. package/README.md +78 -85
  4. package/build/pdfmake.js +66833 -75014
  5. package/build/pdfmake.js.map +1 -1
  6. package/build/pdfmake.min.js +2 -2
  7. package/build/pdfmake.min.js.map +1 -1
  8. package/build/vfs_fonts.js +4 -4
  9. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  10. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  11. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  12. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  13. package/js/DocMeasure.js +20 -1
  14. package/js/DocPreprocessor.js +21 -6
  15. package/js/DocumentContext.js +64 -17
  16. package/js/ElementWriter.js +31 -8
  17. package/js/LayoutBuilder.js +488 -127
  18. package/js/OutputDocument.js +22 -34
  19. package/js/OutputDocumentServer.js +6 -11
  20. package/js/PDFDocument.js +1 -1
  21. package/js/PageElementWriter.js +17 -2
  22. package/js/Printer.js +133 -133
  23. package/js/Renderer.js +22 -14
  24. package/js/SVGMeasure.js +2 -2
  25. package/js/StyleContextStack.js +4 -0
  26. package/js/TableProcessor.js +40 -14
  27. package/js/TextBreaker.js +31 -4
  28. package/js/TextInlines.js +1 -1
  29. package/js/URLResolver.js +25 -55
  30. package/js/base.js +1 -1
  31. package/js/browser-extensions/OutputDocumentBrowser.js +35 -72
  32. package/js/browser-extensions/index.js +2 -2
  33. package/js/browser-extensions/pdfMake.js +0 -12
  34. package/js/browser-extensions/standard-fonts/Courier.js +4 -4
  35. package/js/browser-extensions/standard-fonts/Helvetica.js +4 -4
  36. package/js/browser-extensions/standard-fonts/Symbol.js +1 -1
  37. package/js/browser-extensions/standard-fonts/Times.js +4 -4
  38. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +1 -1
  39. package/js/helpers/tools.js +6 -0
  40. package/js/index.js +1 -1
  41. package/package.json +25 -24
  42. package/src/DocMeasure.js +21 -1
  43. package/src/DocPreprocessor.js +25 -6
  44. package/src/DocumentContext.js +56 -20
  45. package/src/ElementWriter.js +30 -7
  46. package/src/LayoutBuilder.js +531 -144
  47. package/src/OutputDocument.js +23 -37
  48. package/src/OutputDocumentServer.js +6 -11
  49. package/src/PDFDocument.js +1 -1
  50. package/src/PageElementWriter.js +21 -2
  51. package/src/Printer.js +134 -131
  52. package/src/Renderer.js +13 -15
  53. package/src/SVGMeasure.js +2 -2
  54. package/src/StyleContextStack.js +4 -0
  55. package/src/TableProcessor.js +42 -18
  56. package/src/TextBreaker.js +24 -5
  57. package/src/TextInlines.js +1 -1
  58. package/src/URLResolver.js +24 -58
  59. package/src/base.js +1 -1
  60. package/src/browser-extensions/OutputDocumentBrowser.js +33 -71
  61. package/src/browser-extensions/index.js +3 -3
  62. package/src/browser-extensions/pdfMake.js +0 -14
  63. package/src/browser-extensions/standard-fonts/Courier.js +4 -4
  64. package/src/browser-extensions/standard-fonts/Helvetica.js +4 -4
  65. package/src/browser-extensions/standard-fonts/Symbol.js +1 -1
  66. package/src/browser-extensions/standard-fonts/Times.js +4 -4
  67. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +1 -1
  68. package/src/columnCalculator.js +12 -12
  69. package/src/helpers/tools.js +5 -0
  70. package/src/helpers/variableType.js +1 -1
  71. package/src/index.js +1 -1
  72. package/standard-fonts/Helvetica.js +0 -1
  73. package/js/browser-extensions/URLBrowserResolver.js +0 -76
  74. package/src/browser-extensions/URLBrowserResolver.js +0 -84
@@ -108,7 +108,7 @@ class TableProcessor {
108
108
  const headerRows = tableNode.table.headerRows;
109
109
 
110
110
  if (isPositiveInteger(headerRows)) {
111
- this.headerRows = headerRows;
111
+ this.headerRows = headerRows;
112
112
 
113
113
  if (this.headerRows > tableNode.table.body.length) {
114
114
  throw new Error(`Too few rows in the table. Property headerRows requires at least ${this.headerRows}, contains only ${tableNode.table.body.length}`);
@@ -119,20 +119,24 @@ class TableProcessor {
119
119
  const keepWithHeaderRows = tableNode.table.keepWithHeaderRows;
120
120
 
121
121
  if (isPositiveInteger(keepWithHeaderRows)) {
122
- this.rowsWithoutPageBreak += keepWithHeaderRows;
122
+ this.rowsWithoutPageBreak += keepWithHeaderRows;
123
123
  }
124
124
  }
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;
@@ -490,7 +518,9 @@ class TableProcessor {
490
518
  h: bgHeight,
491
519
  lineWidth: 0,
492
520
  color: fillColor,
493
- fillOpacity: fillOpacity
521
+ fillOpacity: fillOpacity,
522
+ // mark if we are in an unbreakable block
523
+ _isFillColorFromUnbreakable: !!writer.transactionLevel
494
524
  }, false, true, writer.context().backgroundLength[writer.context().page]);
495
525
  }
496
526
 
@@ -509,13 +539,6 @@ class TableProcessor {
509
539
  }
510
540
  }
511
541
  }
512
-
513
- if (willBreak && this.layout.hLineWhenBroken !== false) {
514
- this.drawHorizontalLine(rowIndex + 1, writer, y2);
515
- }
516
- if (rowBreakWithoutHeader && this.layout.hLineWhenBroken !== false) {
517
- this.drawHorizontalLine(rowIndex, writer, y1);
518
- }
519
542
  }
520
543
 
521
544
  writer.context().page = endingPage;
@@ -554,7 +577,8 @@ class TableProcessor {
554
577
 
555
578
  if (this.dontBreakRows) {
556
579
  const pageChangedCallback = () => {
557
- 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
558
582
  this.drawHorizontalLine(rowIndex, writer);
559
583
  }
560
584
  };
@@ -1,19 +1,38 @@
1
- import LineBreaker from '@foliojs-fork/linebreak';
1
+ import LineBreaker from 'linebreak';
2
2
  import { isObject } from './helpers/variableType';
3
3
  import StyleContextStack from './StyleContextStack';
4
4
 
5
5
  /**
6
6
  * @param {string} text
7
7
  * @param {boolean} noWrap
8
+ * @param {boolean} breakAll
8
9
  * @returns {Array}
9
10
  */
10
- const splitWords = (text, noWrap) => {
11
+ const splitWords = (text, noWrap, breakAll = false) => {
11
12
  let words = [];
13
+ if (text === undefined || text === null) {
14
+ text = '';
15
+ } else {
16
+ text = String(text);
17
+ }
12
18
 
13
19
  if (noWrap) {
14
20
  words.push({ text: text });
15
21
  return words;
16
22
  }
23
+ if (breakAll) {
24
+ return text.split('').map(c => {
25
+ if(c.match(/^\n$|^\r$/)) { // new line
26
+ return { text: '', lineEnd: true };
27
+ }
28
+ return { text: c };
29
+ });
30
+ }
31
+
32
+ if (text.length === 0) {
33
+ words.push({ text: '' });
34
+ return words;
35
+ }
17
36
 
18
37
  let breaker = new LineBreaker(text);
19
38
  let last = 0;
@@ -101,16 +120,16 @@ class TextBreaker {
101
120
  let item = texts[i];
102
121
  let style = null;
103
122
  let words;
104
-
123
+ let breakAll = StyleContextStack.getStyleProperty(item || {}, styleContextStack, 'wordBreak', 'normal') === 'break-all';
105
124
  let noWrap = StyleContextStack.getStyleProperty(item || {}, styleContextStack, 'noWrap', false);
106
125
  if (isObject(item)) {
107
126
  if (item._textRef && item._textRef._textNodeRef.text) {
108
127
  item.text = item._textRef._textNodeRef.text;
109
128
  }
110
- words = splitWords(item.text, noWrap);
129
+ words = splitWords(item.text, noWrap, breakAll);
111
130
  style = StyleContextStack.copyStyle(item);
112
131
  } else {
113
- words = splitWords(item, noWrap);
132
+ words = splitWords(item, noWrap, breakAll);
114
133
  }
115
134
 
116
135
  if (lastWord && words.length) {
@@ -45,7 +45,7 @@ class TextInlines {
45
45
  * Converts an array of strings (or inline-definition-objects) into a collection
46
46
  * of inlines and calculated minWidth/maxWidth and their min/max widths
47
47
  *
48
- * @param {Array} textArray an array of inline-definition-objects (or strings)
48
+ * @param {Array|object} textArray an array of inline-definition-objects (or strings)
49
49
  * @param {StyleContextStack} styleContextStack current style stack
50
50
  * @returns {object} collection of inlines, minWidth, maxWidth
51
51
  */
@@ -1,35 +1,14 @@
1
- import http from 'http';
2
- import https from 'https';
3
-
4
- const fetchUrl = (url, headers = {}) => {
5
- return new Promise((resolve, reject) => {
6
- const parsedUrl = new URL(url);
7
- const h = (parsedUrl.protocol === 'https:') ? https : http;
8
- let options = {
9
- headers: headers
10
- };
11
-
12
- h.get(url, options, res => {
13
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) { // redirect url
14
- fetchUrl(res.headers.location).then(buffer => {
15
- resolve(buffer);
16
- }, result => {
17
- reject(result);
18
- });
19
- return;
20
- }
21
-
22
- const ok = res.statusCode >= 200 && res.statusCode < 300;
23
- if (!ok) {
24
- reject(new TypeError(`Failed to fetch (status code: ${res.statusCode}, url: "${url}")`));
25
- }
26
-
27
- const chunks = [];
28
- res.on('end', () => resolve(Buffer.concat(chunks)));
29
- res.on('data', d => chunks.push(d));
30
- }).on('error', reject);
31
- });
32
- };
1
+ async function fetchUrl(url, headers = {}) {
2
+ try {
3
+ const response = await fetch(url, { headers });
4
+ if (!response.ok) {
5
+ throw new Error(`Failed to fetch (status code: ${response.status}, url: "${url}")`);
6
+ }
7
+ return await response.arrayBuffer();
8
+ } catch (error) {
9
+ throw new Error(`Network request failed (url: "${url}", error: ${error.message})`);
10
+ }
11
+ }
33
12
 
34
13
  class URLResolver {
35
14
  constructor(fs) {
@@ -38,38 +17,25 @@ class URLResolver {
38
17
  }
39
18
 
40
19
  resolve(url, headers = {}) {
41
- if (!this.resolving[url]) {
42
- this.resolving[url] = new Promise((resolve, reject) => {
43
- if (url.toLowerCase().indexOf('https://') === 0 || url.toLowerCase().indexOf('http://') === 0) {
44
- if (this.fs.existsSync(url)) {
45
- // url was downloaded earlier
46
- resolve();
47
- } else {
48
- fetchUrl(url, headers).then(buffer => {
49
- this.fs.writeFileSync(url, buffer);
50
- resolve();
51
- }, result => {
52
- reject(result);
53
- });
54
- }
55
- } else {
56
- // cannot be resolved
57
- resolve();
20
+ const resolveUrlInternal = async () => {
21
+ if (url.toLowerCase().startsWith('https://') || url.toLowerCase().startsWith('http://')) {
22
+ if (this.fs.existsSync(url)) {
23
+ return; // url was downloaded earlier
58
24
  }
59
- });
60
- }
25
+ const buffer = await fetchUrl(url, headers);
26
+ this.fs.writeFileSync(url, buffer);
27
+ }
28
+ // else cannot be resolved
29
+ };
61
30
 
31
+ if (!this.resolving[url]) {
32
+ this.resolving[url] = resolveUrlInternal();
33
+ }
62
34
  return this.resolving[url];
63
35
  }
64
36
 
65
37
  resolved() {
66
- return new Promise((resolve, reject) => {
67
- Promise.all(Object.values(this.resolving)).then(() => {
68
- resolve();
69
- }, result => {
70
- reject(result);
71
- });
72
- });
38
+ return Promise.all(Object.values(this.resolving));
73
39
  }
74
40
 
75
41
  }
package/src/base.js CHANGED
@@ -18,7 +18,7 @@ class pdfmake {
18
18
  options.progressCallback = this.progressCallback;
19
19
  options.tableLayouts = this.tableLayouts;
20
20
 
21
- let printer = new Printer(this.fonts, this.virtualfs, this.urlResolver);
21
+ let printer = new Printer(this.fonts, this.virtualfs, this.urlResolver());
22
22
  const pdfDocumentPromise = printer.createPdfKitDocument(docDefinition, options);
23
23
 
24
24
  return this._transformToDocument(pdfDocumentPromise);
@@ -20,98 +20,60 @@ class OutputDocumentBrowser extends OutputDocument {
20
20
  /**
21
21
  * @returns {Promise<Blob>}
22
22
  */
23
- getBlob() {
24
- return new Promise((resolve, reject) => {
25
- this.getBuffer().then(buffer => {
26
- try {
27
- let blob = new Blob([buffer], { type: 'application/pdf' });
28
- resolve(blob);
29
- } catch (e) {
30
- reject(e);
31
- }
32
- }, result => {
33
- reject(result);
34
- });
35
- });
23
+ async getBlob() {
24
+ const buffer = await this.getBuffer();
25
+ return new Blob([buffer], { type: 'application/pdf' });
36
26
  }
37
27
 
38
28
  /**
39
29
  * @param {string} filename
40
30
  * @returns {Promise}
41
31
  */
42
- download(filename = 'file.pdf') {
43
- return new Promise((resolve, reject) => {
44
- this.getBlob().then(blob => {
45
- try {
46
- saveAs(blob, filename);
47
- resolve();
48
- } catch (e) {
49
- reject(e);
50
- }
51
- }, result => {
52
- reject(result);
53
- });
54
- });
32
+ async download(filename = 'file.pdf') {
33
+ const blob = await this.getBlob();
34
+ saveAs(blob, filename);
55
35
  }
56
36
 
57
37
  /**
58
38
  * @param {Window} win
59
39
  * @returns {Promise}
60
40
  */
61
- open(win = null) {
62
- return new Promise((resolve, reject) => {
63
- if (!win) {
64
- win = openWindow();
65
- }
66
- this.getBlob().then(blob => {
67
- try {
68
- let urlCreator = window.URL || window.webkitURL;
69
- let pdfUrl = urlCreator.createObjectURL(blob);
70
- win.location.href = pdfUrl;
41
+ async open(win = null) {
42
+ if (!win) {
43
+ win = openWindow();
44
+ }
45
+ const blob = await this.getBlob();
46
+ try {
47
+ let urlCreator = window.URL || window.webkitURL;
48
+ let pdfUrl = urlCreator.createObjectURL(blob);
49
+ win.location.href = pdfUrl;
71
50
 
72
- //
73
- resolve();
74
- /* temporarily disabled
75
- if (win === window) {
76
- resolve();
77
- } else {
78
- setTimeout(() => {
79
- if (win.window === null) { // is closed by AdBlock
80
- window.location.href = pdfUrl; // open in actual window
81
- }
82
- resolve();
83
- }, 500);
51
+ /* temporarily disabled
52
+ if (win === window) {
53
+ return;
54
+ } else {
55
+ setTimeout(() => {
56
+ if (win.window === null) { // is closed by AdBlock
57
+ window.location.href = pdfUrl; // open in actual window
84
58
  }
85
- */
86
- } catch (e) {
87
- win.close();
88
- reject(e);
89
- }
90
- }, result => {
91
- reject(result);
92
- });
93
- });
59
+ return;
60
+ }, 500);
61
+ }
62
+ */
63
+ } finally {
64
+ win.close();
65
+ }
94
66
  }
95
67
 
96
68
  /**
97
69
  * @param {Window} win
98
70
  * @returns {Promise}
99
71
  */
100
- print(win = null) {
101
- return new Promise((resolve, reject) => {
102
- this.getStream().then(stream => {
103
- stream.setOpenActionAsPrint();
104
- return this.open(win).then(() => {
105
- resolve();
106
- }, result => {
107
- reject(result);
108
- });
109
- }, result => {
110
- reject(result);
111
- });
112
- });
72
+ async print(win = null) {
73
+ const stream = await this.getStream();
74
+ stream.setOpenActionAsPrint();
75
+ await this.open(win);
113
76
  }
114
-
115
77
  }
116
78
 
117
79
  export default OutputDocumentBrowser;
@@ -1,12 +1,12 @@
1
1
  import pdfmakeBase from '../base';
2
2
  import OutputDocumentBrowser from './OutputDocumentBrowser';
3
- import URLBrowserResolver from './URLBrowserResolver';
3
+ import URLResolver from '../URLResolver';
4
4
  import fs from 'fs';
5
5
  import configurator from 'core-js/configurator';
6
6
 
7
7
  // core-js: Polyfills will be used only if natives completely unavailable.
8
8
  configurator({
9
- useNative: ['Promise']
9
+ useNative: ['Promise']
10
10
  });
11
11
 
12
12
  let defaultClientFonts = {
@@ -21,7 +21,7 @@ let defaultClientFonts = {
21
21
  class pdfmake extends pdfmakeBase {
22
22
  constructor() {
23
23
  super();
24
- this.urlResolver = new URLBrowserResolver(this.virtualfs);
24
+ this.urlResolver = () => new URLResolver(this.virtualfs);
25
25
  this.fonts = defaultClientFonts;
26
26
  }
27
27
 
@@ -1,15 +1 @@
1
- const isBrowserSupported = () => {
2
- if ((typeof window === 'undefined') || (typeof window.navigator === 'undefined')) {
3
- // Enviroment is not browser.
4
- return true;
5
- }
6
-
7
- // Internet Explorer 10 and older is not supported.
8
- return window.navigator.userAgent.indexOf("MSIE") === -1;
9
- };
10
-
11
- if (!isBrowserSupported()) {
12
- throw new Error('pdfmake: Internet Explorer 10 and older is not supported. Upgrade to version 11 or use modern browser.');
13
- }
14
-
15
1
  module.exports = require('./index').default;
@@ -2,10 +2,10 @@ var fs = require('fs');
2
2
 
3
3
  var fontContainer = {
4
4
  vfs: {
5
- 'data/Courier.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier.afm', 'utf8'), encoding: 'utf8' },
6
- 'data/Courier-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-Bold.afm', 'utf8'), encoding: 'utf8' },
7
- 'data/Courier-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-Oblique.afm', 'utf8'), encoding: 'utf8' },
8
- 'data/Courier-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Courier-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
5
+ 'data/Courier.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier.afm', 'utf8'), encoding: 'utf8' },
6
+ 'data/Courier-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Bold.afm', 'utf8'), encoding: 'utf8' },
7
+ 'data/Courier-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-Oblique.afm', 'utf8'), encoding: 'utf8' },
8
+ 'data/Courier-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Courier-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
9
9
  },
10
10
  fonts: {
11
11
  Courier: {
@@ -2,10 +2,10 @@ var fs = require('fs');
2
2
 
3
3
  var fontContainer = {
4
4
  vfs: {
5
- 'data/Helvetica.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica.afm', 'utf8'), encoding: 'utf8' },
6
- 'data/Helvetica-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'), encoding: 'utf8' },
7
- 'data/Helvetica-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'), encoding: 'utf8' },
8
- 'data/Helvetica-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Helvetica-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
5
+ 'data/Helvetica.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica.afm', 'utf8'), encoding: 'utf8' },
6
+ 'data/Helvetica-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Bold.afm', 'utf8'), encoding: 'utf8' },
7
+ 'data/Helvetica-Oblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-Oblique.afm', 'utf8'), encoding: 'utf8' },
8
+ 'data/Helvetica-BoldOblique.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Helvetica-BoldOblique.afm', 'utf8'), encoding: 'utf8' }
9
9
  },
10
10
  fonts: {
11
11
  Helvetica: {
@@ -2,7 +2,7 @@ var fs = require('fs');
2
2
 
3
3
  var fontContainer = {
4
4
  vfs: {
5
- 'data/Symbol.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Symbol.afm', 'utf8'), encoding: 'utf8' }
5
+ 'data/Symbol.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Symbol.afm', 'utf8'), encoding: 'utf8' }
6
6
  },
7
7
  fonts: {
8
8
  Symbol: {
@@ -2,10 +2,10 @@ var fs = require('fs');
2
2
 
3
3
  var fontContainer = {
4
4
  vfs: {
5
- 'data/Times-Roman.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Roman.afm', 'utf8'), encoding: 'utf8' },
6
- 'data/Times-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Bold.afm', 'utf8'), encoding: 'utf8' },
7
- 'data/Times-Italic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-Italic.afm', 'utf8'), encoding: 'utf8' },
8
- 'data/Times-BoldItalic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/Times-BoldItalic.afm', 'utf8'), encoding: 'utf8' }
5
+ 'data/Times-Roman.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Roman.afm', 'utf8'), encoding: 'utf8' },
6
+ 'data/Times-Bold.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Bold.afm', 'utf8'), encoding: 'utf8' },
7
+ 'data/Times-Italic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-Italic.afm', 'utf8'), encoding: 'utf8' },
8
+ 'data/Times-BoldItalic.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/Times-BoldItalic.afm', 'utf8'), encoding: 'utf8' }
9
9
  },
10
10
  fonts: {
11
11
  Times: {
@@ -2,7 +2,7 @@ var fs = require('fs');
2
2
 
3
3
  var fontContainer = {
4
4
  vfs: {
5
- 'data/ZapfDingbats.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/@foliojs-fork/pdfkit/js/data/ZapfDingbats.afm', 'utf8'), encoding: 'utf8' }
5
+ 'data/ZapfDingbats.afm': { data: fs.readFileSync(__dirname + '/../../../node_modules/pdfkit/js/data/ZapfDingbats.afm', 'utf8'), encoding: 'utf8' }
6
6
  },
7
7
  fonts: {
8
8
  ZapfDingbats: {
@@ -30,25 +30,25 @@ function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode)
30
30
  // In tables we have to take into consideration the reserved width for paddings and borders
31
31
  let reservedWidth = 0;
32
32
  if (tableNode) {
33
- const paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
34
- const paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
35
- const borderLeft = tableNode._layout.vLineWidth (colIndex, tableNode);
36
- const borderRight = tableNode._layout.vLineWidth (colIndex + 1, tableNode);
37
- if (colIndex === 0) {
38
- // first column assumes whole borderLeft and half of border right
33
+ const paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
34
+ const paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
35
+ const borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
36
+ const borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
37
+ if (colIndex === 0) {
38
+ // first column assumes whole borderLeft and half of border right
39
39
  reservedWidth = paddingLeft + paddingRight + borderLeft + (borderRight / 2);
40
40
 
41
- } else if (colIndex === fixedColumns.length - 1) {
42
- // last column assumes whole borderRight and half of border left
41
+ } else if (colIndex === fixedColumns.length - 1) {
42
+ // last column assumes whole borderRight and half of border left
43
43
  reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + borderRight;
44
44
 
45
- } else {
46
- // Columns in the middle assume half of each border
45
+ } else {
46
+ // Columns in the middle assume half of each border
47
47
  reservedWidth = paddingLeft + paddingRight + (borderLeft / 2) + (borderRight / 2);
48
- }
48
+ }
49
49
  }
50
50
  const totalAvailableWidth = initial_availableWidth + offsetTotal;
51
- col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
51
+ col.width = (parseFloat(col.width) * totalAvailableWidth / 100) - reservedWidth;
52
52
  }
53
53
  if (col.width < (col._minWidth) && col.elasticWidth) {
54
54
  col._calcWidth = col._minWidth;
@@ -37,3 +37,8 @@ export function offsetVector(vector, x, y) {
37
37
  break;
38
38
  }
39
39
  }
40
+
41
+ export function convertToDynamicContent(staticContent) {
42
+ return () => // copy to new object
43
+ JSON.parse(JSON.stringify(staticContent));
44
+ }
@@ -20,7 +20,7 @@ export function isNumber(variable) {
20
20
  */
21
21
  export function isPositiveInteger(variable) {
22
22
  if (!isNumber(variable) || !Number.isInteger(variable) || variable <= 0) {
23
- return false;
23
+ return false;
24
24
  }
25
25
  return true;
26
26
  }
package/src/index.js CHANGED
@@ -5,7 +5,7 @@ const URLResolver = require('./URLResolver').default;
5
5
  class pdfmake extends pdfmakeBase {
6
6
  constructor() {
7
7
  super();
8
- this.urlResolver = new URLResolver(this.virtualfs);
8
+ this.urlResolver = () => new URLResolver(this.virtualfs);
9
9
  }
10
10
 
11
11
  _transformToDocument(doc) {
@@ -6,4 +6,3 @@ module.exports = {
6
6
  bolditalics: 'Helvetica-BoldOblique'
7
7
  }
8
8
  };
9
-