pdfmake 0.2.12 → 0.2.13
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.
- package/.idea/codeStyles/Project.xml +7 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/misc.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/pdfmake.iml +11 -0
- package/.idea/vcs.xml +6 -0
- package/CHANGELOG.md +12 -0
- package/build/pdfmake.js +1040 -936
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/vfs_fonts.js +4 -4
- package/package.json +2 -2
- package/src/browser-extensions/URLBrowserResolver.js +2 -2
- package/src/browser-extensions/pdfMake.js +6 -6
- package/src/browser-extensions/virtual-fs.js +1 -1
- package/src/docPreprocessor.js +1 -1
- package/src/documentContext.js +29 -7
- package/src/elementWriter.js +16 -5
- package/src/fontProvider.js +2 -2
- package/src/helpers.js +1 -1
- package/src/imageMeasure.js +55 -55
- package/src/layoutBuilder.js +989 -857
- package/src/printer.js +1 -1
- package/src/tableProcessor.js +4 -2
- package/src/textTools.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfmake",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "Client/server side PDF printing in pure JavaScript",
|
|
5
5
|
"main": "src/printer.js",
|
|
6
6
|
"browser": "build/pdfmake.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"webpack-cli": "^4.7.2"
|
|
46
46
|
},
|
|
47
47
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
48
|
+
"node": ">=18"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"test": "run-s build mocha",
|
|
@@ -80,7 +80,7 @@ URLBrowserResolver.prototype.resolve = function (url, headers) {
|
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
return this.resolving[url];
|
|
83
|
-
}
|
|
83
|
+
};
|
|
84
84
|
|
|
85
85
|
URLBrowserResolver.prototype.resolved = function () {
|
|
86
86
|
var _this = this;
|
|
@@ -91,6 +91,6 @@ URLBrowserResolver.prototype.resolved = function () {
|
|
|
91
91
|
reject(result);
|
|
92
92
|
});
|
|
93
93
|
});
|
|
94
|
-
}
|
|
94
|
+
};
|
|
95
95
|
|
|
96
96
|
module.exports = URLBrowserResolver;
|
|
@@ -25,13 +25,13 @@ function Document(docDefinition, tableLayouts, fonts, vfs) {
|
|
|
25
25
|
function canCreatePdf() {
|
|
26
26
|
// Ensure the browser provides the level of support needed
|
|
27
27
|
try {
|
|
28
|
-
var arr = new Uint8Array(1)
|
|
29
|
-
var proto = { foo: function () { return 42 } }
|
|
30
|
-
Object.setPrototypeOf(proto, Uint8Array.prototype)
|
|
31
|
-
Object.setPrototypeOf(arr, proto)
|
|
32
|
-
return arr.foo() === 42
|
|
28
|
+
var arr = new Uint8Array(1);
|
|
29
|
+
var proto = { foo: function () { return 42; } };
|
|
30
|
+
Object.setPrototypeOf(proto, Uint8Array.prototype);
|
|
31
|
+
Object.setPrototypeOf(arr, proto);
|
|
32
|
+
return arr.foo() === 42;
|
|
33
33
|
} catch (e) {
|
|
34
|
-
return false
|
|
34
|
+
return false;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
|
|
@@ -9,7 +9,7 @@ VirtualFileSystem.prototype.existsSync = function (filename) {
|
|
|
9
9
|
filename = fixFilename(filename);
|
|
10
10
|
return typeof this.fileSystem[filename] !== 'undefined'
|
|
11
11
|
|| typeof this.dataSystem[filename] !== 'undefined';
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
13
|
|
|
14
14
|
VirtualFileSystem.prototype.readFileSync = function (filename, options) {
|
|
15
15
|
filename = fixFilename(filename);
|
package/src/docPreprocessor.js
CHANGED
package/src/documentContext.js
CHANGED
|
@@ -26,7 +26,7 @@ function DocumentContext(pageSize, pageMargins) {
|
|
|
26
26
|
this.addPage(pageSize);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
DocumentContext.prototype.beginColumnGroup = function () {
|
|
29
|
+
DocumentContext.prototype.beginColumnGroup = function (marginXTopParent) {
|
|
30
30
|
this.snapshots.push({
|
|
31
31
|
x: this.x,
|
|
32
32
|
y: this.y,
|
|
@@ -44,6 +44,13 @@ DocumentContext.prototype.beginColumnGroup = function () {
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
this.lastColumnWidth = 0;
|
|
47
|
+
if (marginXTopParent) {
|
|
48
|
+
this.marginXTopParent = marginXTopParent;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
DocumentContext.prototype.resetMarginXTopParent = function () {
|
|
53
|
+
this.marginXTopParent = null;
|
|
47
54
|
};
|
|
48
55
|
|
|
49
56
|
DocumentContext.prototype.beginColumn = function (width, offset, endingCell) {
|
|
@@ -68,10 +75,10 @@ DocumentContext.prototype.calculateBottomMost = function (destContext, endingCel
|
|
|
68
75
|
}
|
|
69
76
|
};
|
|
70
77
|
|
|
71
|
-
DocumentContext.prototype.markEnding = function (endingCell) {
|
|
78
|
+
DocumentContext.prototype.markEnding = function (endingCell, originalXOffset, discountY) {
|
|
72
79
|
this.page = endingCell._columnEndingContext.page;
|
|
73
|
-
this.x = endingCell._columnEndingContext.x;
|
|
74
|
-
this.y = endingCell._columnEndingContext.y;
|
|
80
|
+
this.x = endingCell._columnEndingContext.x + originalXOffset;
|
|
81
|
+
this.y = endingCell._columnEndingContext.y - discountY;
|
|
75
82
|
this.availableWidth = endingCell._columnEndingContext.availableWidth;
|
|
76
83
|
this.availableHeight = endingCell._columnEndingContext.availableHeight;
|
|
77
84
|
this.lastColumnWidth = endingCell._columnEndingContext.lastColumnWidth;
|
|
@@ -131,14 +138,19 @@ DocumentContext.prototype.moveDown = function (offset) {
|
|
|
131
138
|
DocumentContext.prototype.initializePage = function () {
|
|
132
139
|
this.y = this.pageMargins.top;
|
|
133
140
|
this.availableHeight = this.getCurrentPage().pageSize.height - this.pageMargins.top - this.pageMargins.bottom;
|
|
134
|
-
|
|
141
|
+
const { pageCtx, isSnapshot } = this.pageSnapshot();
|
|
142
|
+
pageCtx.availableWidth = this.getCurrentPage().pageSize.width - this.pageMargins.left - this.pageMargins.right;
|
|
143
|
+
if (isSnapshot && this.marginXTopParent) {
|
|
144
|
+
pageCtx.availableWidth -= this.marginXTopParent[0];
|
|
145
|
+
pageCtx.availableWidth -= this.marginXTopParent[1];
|
|
146
|
+
}
|
|
135
147
|
};
|
|
136
148
|
|
|
137
149
|
DocumentContext.prototype.pageSnapshot = function () {
|
|
138
150
|
if (this.snapshots[0]) {
|
|
139
|
-
return this.snapshots[0];
|
|
151
|
+
return { pageCtx: this.snapshots[0], isSnapshot: true };
|
|
140
152
|
} else {
|
|
141
|
-
return this;
|
|
153
|
+
return { pageCtx: this, isSnapshot: false };
|
|
142
154
|
}
|
|
143
155
|
};
|
|
144
156
|
|
|
@@ -221,6 +233,16 @@ DocumentContext.prototype.moveToNextPage = function (pageOrientation) {
|
|
|
221
233
|
var prevPage = this.page;
|
|
222
234
|
var prevY = this.y;
|
|
223
235
|
|
|
236
|
+
// If we are in a column group
|
|
237
|
+
if (this.snapshots.length > 0) {
|
|
238
|
+
var lastSnapshot = this.snapshots[this.snapshots.length - 1];
|
|
239
|
+
// We have to update prevY accordingly by also taking into consideration
|
|
240
|
+
// the 'y' of cells that don't break page
|
|
241
|
+
if (lastSnapshot.bottomMost && lastSnapshot.bottomMost.y) {
|
|
242
|
+
prevY = Math.max(this.y, lastSnapshot.bottomMost.y);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
224
246
|
var createNewPage = nextPageIndex >= this.pages.length;
|
|
225
247
|
if (createNewPage) {
|
|
226
248
|
var currentAvailableWidth = this.availableWidth;
|
package/src/elementWriter.js
CHANGED
|
@@ -116,7 +116,7 @@ ElementWriter.prototype.addImage = function (image, index, type) {
|
|
|
116
116
|
};
|
|
117
117
|
|
|
118
118
|
ElementWriter.prototype.addSVG = function (image, index) {
|
|
119
|
-
return this.addImage(image, index, 'svg')
|
|
119
|
+
return this.addImage(image, index, 'svg');
|
|
120
120
|
};
|
|
121
121
|
|
|
122
122
|
ElementWriter.prototype.addQr = function (qr, index) {
|
|
@@ -261,10 +261,21 @@ ElementWriter.prototype.addFragment = function (block, useBlockXOffset, useBlock
|
|
|
261
261
|
var v = pack(item.item);
|
|
262
262
|
|
|
263
263
|
offsetVector(v, useBlockXOffset ? (block.xOffset || 0) : ctx.x, useBlockYOffset ? (block.yOffset || 0) : ctx.y);
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
264
|
+
if (v._isFillColorFromUnbreakable) {
|
|
265
|
+
// If the item is a fillColor from an unbreakable block
|
|
266
|
+
// We have to add it at the beginning of the items body array of the page
|
|
267
|
+
delete v._isFillColorFromUnbreakable;
|
|
268
|
+
const endOfBackgroundItemsIndex = ctx.backgroundLength[ctx.page];
|
|
269
|
+
page.items.splice(endOfBackgroundItemsIndex, 0, {
|
|
270
|
+
type: 'vector',
|
|
271
|
+
item: v
|
|
272
|
+
});
|
|
273
|
+
} else {
|
|
274
|
+
page.items.push({
|
|
275
|
+
type: 'vector',
|
|
276
|
+
item: v
|
|
277
|
+
});
|
|
278
|
+
}
|
|
268
279
|
break;
|
|
269
280
|
|
|
270
281
|
case 'image':
|
package/src/fontProvider.js
CHANGED
|
@@ -35,7 +35,7 @@ function FontProvider(fontDescriptors, pdfKitDoc) {
|
|
|
35
35
|
|
|
36
36
|
FontProvider.prototype.getFontType = function (bold, italics) {
|
|
37
37
|
return typeName(bold, italics);
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
|
|
40
40
|
FontProvider.prototype.getFontFile = function (familyName, bold, italics) {
|
|
41
41
|
var type = this.getFontType(bold, italics);
|
|
@@ -44,7 +44,7 @@ FontProvider.prototype.getFontFile = function (familyName, bold, italics) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
return this.fonts[familyName][type];
|
|
47
|
-
}
|
|
47
|
+
};
|
|
48
48
|
|
|
49
49
|
FontProvider.prototype.provideFont = function (familyName, bold, italics) {
|
|
50
50
|
var type = this.getFontType(bold, italics);
|
package/src/helpers.js
CHANGED
package/src/imageMeasure.js
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
|
|
5
|
-
function ImageMeasure(pdfKitDoc, imageDictionary) {
|
|
6
|
-
this.pdfKitDoc = pdfKitDoc;
|
|
7
|
-
this.imageDictionary = imageDictionary || {};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
ImageMeasure.prototype.measureImage = function (src) {
|
|
11
|
-
var image;
|
|
12
|
-
var that = this;
|
|
13
|
-
|
|
14
|
-
if (!this.pdfKitDoc._imageRegistry[src]) {
|
|
15
|
-
try {
|
|
16
|
-
image = this.pdfKitDoc.openImage(realImageSrc(src));
|
|
17
|
-
if (!image) {
|
|
18
|
-
throw 'No image';
|
|
19
|
-
}
|
|
20
|
-
} catch (error) {
|
|
21
|
-
throw 'Invalid image: ' + error.toString() + '\nImages dictionary should contain dataURL entries (or local file paths in node.js)';
|
|
22
|
-
}
|
|
23
|
-
image.embed(this.pdfKitDoc);
|
|
24
|
-
this.pdfKitDoc._imageRegistry[src] = image;
|
|
25
|
-
} else {
|
|
26
|
-
image = this.pdfKitDoc._imageRegistry[src];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return { width: image.width, height: image.height };
|
|
30
|
-
|
|
31
|
-
function realImageSrc(src) {
|
|
32
|
-
var img = that.imageDictionary[src];
|
|
33
|
-
|
|
34
|
-
if (!img) {
|
|
35
|
-
return src;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (typeof img === 'object') {
|
|
39
|
-
throw 'Not supported image definition: ' + JSON.stringify(img);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (fs.existsSync(img)) {
|
|
43
|
-
return fs.readFileSync(img);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
var index = img.indexOf('base64,');
|
|
47
|
-
if (index < 0) {
|
|
48
|
-
return that.imageDictionary[src];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return Buffer.from(img.substring(index + 7), 'base64');
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
module.exports = ImageMeasure;
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
|
|
5
|
+
function ImageMeasure(pdfKitDoc, imageDictionary) {
|
|
6
|
+
this.pdfKitDoc = pdfKitDoc;
|
|
7
|
+
this.imageDictionary = imageDictionary || {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
ImageMeasure.prototype.measureImage = function (src) {
|
|
11
|
+
var image;
|
|
12
|
+
var that = this;
|
|
13
|
+
|
|
14
|
+
if (!this.pdfKitDoc._imageRegistry[src]) {
|
|
15
|
+
try {
|
|
16
|
+
image = this.pdfKitDoc.openImage(realImageSrc(src));
|
|
17
|
+
if (!image) {
|
|
18
|
+
throw 'No image';
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw 'Invalid image: ' + error.toString() + '\nImages dictionary should contain dataURL entries (or local file paths in node.js)';
|
|
22
|
+
}
|
|
23
|
+
image.embed(this.pdfKitDoc);
|
|
24
|
+
this.pdfKitDoc._imageRegistry[src] = image;
|
|
25
|
+
} else {
|
|
26
|
+
image = this.pdfKitDoc._imageRegistry[src];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { width: image.width, height: image.height };
|
|
30
|
+
|
|
31
|
+
function realImageSrc(src) {
|
|
32
|
+
var img = that.imageDictionary[src];
|
|
33
|
+
|
|
34
|
+
if (!img) {
|
|
35
|
+
return src;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof img === 'object') {
|
|
39
|
+
throw 'Not supported image definition: ' + JSON.stringify(img);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (fs.existsSync(img)) {
|
|
43
|
+
return fs.readFileSync(img);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var index = img.indexOf('base64,');
|
|
47
|
+
if (index < 0) {
|
|
48
|
+
return that.imageDictionary[src];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Buffer.from(img.substring(index + 7), 'base64');
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
module.exports = ImageMeasure;
|