pdfmake 0.2.20 → 0.2.22
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/CHANGELOG.md +12 -0
- package/LICENSE +1 -1
- package/build/pdfmake.js +37326 -37174
- 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 +15 -15
- package/src/browser-extensions/pdfMake.js +5 -0
- package/src/layoutBuilder.js +11 -3
- package/src/printer.js +10 -1
- package/src/svgMeasure.js +43 -15
- package/src/textTools.js +28 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfmake",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.22",
|
|
4
4
|
"description": "Client/server side PDF printing in pure JavaScript",
|
|
5
5
|
"main": "src/printer.js",
|
|
6
6
|
"browser": "build/pdfmake.js",
|
|
@@ -10,40 +10,40 @@
|
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@foliojs-fork/linebreak": "^1.1.2",
|
|
12
12
|
"@foliojs-fork/pdfkit": "^0.15.3",
|
|
13
|
-
"iconv-lite": "^0.
|
|
14
|
-
"xmldoc": "^2.0.
|
|
13
|
+
"iconv-lite": "^0.7.1",
|
|
14
|
+
"xmldoc": "^2.0.3"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
|
-
"@babel/cli": "^7.
|
|
18
|
-
"@babel/core": "^7.
|
|
17
|
+
"@babel/cli": "^7.28.3",
|
|
18
|
+
"@babel/core": "^7.28.5",
|
|
19
19
|
"@babel/plugin-transform-modules-commonjs": "^7.27.1",
|
|
20
|
-
"@babel/preset-env": "^7.
|
|
21
|
-
"@eslint/js": "^9.
|
|
20
|
+
"@babel/preset-env": "^7.28.5",
|
|
21
|
+
"@eslint/js": "^9.39.2",
|
|
22
22
|
"assert": "^2.1.0",
|
|
23
23
|
"babel-loader": "^10.0.0",
|
|
24
24
|
"brfs": "^2.0.2",
|
|
25
25
|
"browserify-zlib": "^0.2.0",
|
|
26
26
|
"buffer": "^6.0.3",
|
|
27
27
|
"core-js": "3.19.0",
|
|
28
|
-
"eslint": "^9.
|
|
29
|
-
"eslint-plugin-jsdoc": "^
|
|
28
|
+
"eslint": "^9.39.2",
|
|
29
|
+
"eslint-plugin-jsdoc": "^61.5.0",
|
|
30
30
|
"expose-loader": "^5.0.1",
|
|
31
31
|
"file-saver": "^2.0.5",
|
|
32
|
-
"globals": "^16.
|
|
33
|
-
"mocha": "^11.
|
|
32
|
+
"globals": "^16.5.0",
|
|
33
|
+
"mocha": "^11.7.5",
|
|
34
34
|
"npm-run-all": "^4.1.5",
|
|
35
35
|
"process": "^0.11.10",
|
|
36
|
-
"rewire": "^
|
|
36
|
+
"rewire": "^9.0.1",
|
|
37
37
|
"shx": "^0.4.0",
|
|
38
|
-
"sinon": "^
|
|
38
|
+
"sinon": "^21.0.1",
|
|
39
39
|
"source-map-loader": "^5.0.0",
|
|
40
40
|
"stream-browserify": "^3.0.0",
|
|
41
41
|
"string-replace-webpack-plugin": "^0.1.3",
|
|
42
42
|
"svg-to-pdfkit": "^0.1.8",
|
|
43
|
-
"terser-webpack-plugin": "^5.3.
|
|
43
|
+
"terser-webpack-plugin": "^5.3.16",
|
|
44
44
|
"transform-loader": "^0.2.4",
|
|
45
45
|
"util": "^0.12.5",
|
|
46
|
-
"webpack": "^5.
|
|
46
|
+
"webpack": "^5.104.1",
|
|
47
47
|
"webpack-cli": "^6.0.1"
|
|
48
48
|
},
|
|
49
49
|
"engines": {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var isFunction = require('../helpers').isFunction;
|
|
4
|
+
var isObject = require('../helpers').isObject;
|
|
4
5
|
var isUndefined = require('../helpers').isUndefined;
|
|
5
6
|
//var isNull = require('../helpers').isNull;
|
|
6
7
|
var pack = require('../helpers').pack;
|
|
@@ -321,6 +322,10 @@ Document.prototype.getStream = function (options, cb) {
|
|
|
321
322
|
|
|
322
323
|
module.exports = {
|
|
323
324
|
createPdf: function (docDefinition, tableLayouts, fonts, vfs) {
|
|
325
|
+
if (!isObject(docDefinition)) {
|
|
326
|
+
throw new Error("Parameter 'docDefinition' has an invalid type. Object expected.");
|
|
327
|
+
}
|
|
328
|
+
|
|
324
329
|
if (!canCreatePdf()) {
|
|
325
330
|
throw 'Your browser does not provide the level of support needed';
|
|
326
331
|
}
|
package/src/layoutBuilder.js
CHANGED
|
@@ -66,9 +66,17 @@ LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, s
|
|
|
66
66
|
return false;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
69
|
+
const hasRenderableContent = node => {
|
|
70
|
+
if (!node || node.positions.length === 0) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (node.text === '' && !node.listMarker) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
linearNodeList = linearNodeList.filter(hasRenderableContent);
|
|
72
80
|
|
|
73
81
|
linearNodeList.forEach(function (node) {
|
|
74
82
|
var nodeInfo = {};
|
package/src/printer.js
CHANGED
|
@@ -15,6 +15,7 @@ var isNumber = require('./helpers').isNumber;
|
|
|
15
15
|
var isBoolean = require('./helpers').isBoolean;
|
|
16
16
|
var isArray = require('./helpers').isArray;
|
|
17
17
|
var isUndefined = require('./helpers').isUndefined;
|
|
18
|
+
var isObject = require('./helpers').isObject;
|
|
18
19
|
var isPattern = require('./helpers').isPattern;
|
|
19
20
|
var getPattern = require('./helpers').getPattern;
|
|
20
21
|
var SVGtoPDF = require('./3rd-party/svg-to-pdfkit');
|
|
@@ -111,6 +112,14 @@ function PdfPrinter(fontDescriptors) {
|
|
|
111
112
|
PdfPrinter.prototype.createPdfKitDocument = function (docDefinition, options) {
|
|
112
113
|
options = options || {};
|
|
113
114
|
|
|
115
|
+
if (!isObject(docDefinition)) {
|
|
116
|
+
throw new Error("Parameter 'docDefinition' has an invalid type. Object expected.");
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (!isObject(options)) {
|
|
120
|
+
throw new Error("Parameter 'options' has an invalid type. Object expected.");
|
|
121
|
+
}
|
|
122
|
+
|
|
114
123
|
docDefinition.version = docDefinition.version || '1.3';
|
|
115
124
|
docDefinition.subset = docDefinition.subset || undefined;
|
|
116
125
|
docDefinition.tagged = typeof docDefinition.tagged === 'boolean' ? docDefinition.tagged : false;
|
|
@@ -677,7 +686,7 @@ function renderImage(image, x, y, pdfKitDoc) {
|
|
|
677
686
|
}
|
|
678
687
|
|
|
679
688
|
function renderSVG(svg, x, y, pdfKitDoc, fontProvider) {
|
|
680
|
-
var options = Object.assign({ width: svg._width, height: svg._height, assumePt: true }, svg.options);
|
|
689
|
+
var options = Object.assign({ width: svg._width, height: svg._height, assumePt: true, useCSS: !isString(svg.svg) }, svg.options);
|
|
681
690
|
options.fontCallback = function (family, bold, italic) {
|
|
682
691
|
var fontsFamily = family.split(',').map(function (f) { return f.trim().replace(/('|")/g, ''); });
|
|
683
692
|
var font = findFont(fontProvider.fonts, fontsFamily, svg.font || 'Roboto');
|
package/src/svgMeasure.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var xmldoc = require('xmldoc');
|
|
4
|
+
var isString = require('./helpers').isString;
|
|
4
5
|
|
|
5
6
|
/** Strip unit postfix, parse number, but return undefined instead of NaN for bad input */
|
|
6
7
|
function stripUnits(textVal) {
|
|
@@ -18,11 +19,11 @@ function parseSVG(svgString) {
|
|
|
18
19
|
try {
|
|
19
20
|
doc = new xmldoc.XmlDocument(svgString);
|
|
20
21
|
} catch (err) {
|
|
21
|
-
throw new Error('
|
|
22
|
+
throw new Error('Invalid svg document (' + err + ')');
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
if (doc.name !== "svg") {
|
|
25
|
-
throw new Error('
|
|
26
|
+
throw new Error('Invalid svg document (expected <svg>)');
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
return doc;
|
|
@@ -31,17 +32,30 @@ function parseSVG(svgString) {
|
|
|
31
32
|
function SVGMeasure() {
|
|
32
33
|
}
|
|
33
34
|
|
|
34
|
-
SVGMeasure.prototype.measureSVG = function (
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
SVGMeasure.prototype.measureSVG = function (svg) {
|
|
36
|
+
var width, height, viewBox;
|
|
37
|
+
|
|
38
|
+
if (isString(svg)) {
|
|
39
|
+
var doc = parseSVG(svg);
|
|
40
|
+
|
|
41
|
+
width = doc.attr.width;
|
|
42
|
+
height = doc.attr.height;
|
|
43
|
+
viewBox = doc.attr.viewBox;
|
|
44
|
+
} else if (typeof SVGElement !== 'undefined' && svg instanceof SVGElement && typeof getComputedStyle === 'function') {
|
|
45
|
+
width = svg.getAttribute("width");
|
|
46
|
+
height = svg.getAttribute("height");
|
|
47
|
+
viewBox = svg.getAttribute("viewBox");
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('Invalid SVG document');
|
|
50
|
+
}
|
|
37
51
|
|
|
38
|
-
var docWidth = stripUnits(
|
|
39
|
-
var docHeight = stripUnits(
|
|
52
|
+
var docWidth = stripUnits(width);
|
|
53
|
+
var docHeight = stripUnits(height);
|
|
40
54
|
|
|
41
|
-
if ((docWidth == undefined || docHeight == undefined) && typeof
|
|
42
|
-
var viewBoxParts =
|
|
55
|
+
if ((docWidth == undefined || docHeight == undefined) && typeof viewBox == 'string') {
|
|
56
|
+
var viewBoxParts = viewBox.split(/[,\s]+/);
|
|
43
57
|
if (viewBoxParts.length !== 4) {
|
|
44
|
-
throw new Error("Unexpected svg
|
|
58
|
+
throw new Error("Unexpected svg viewBox format, should have 4 entries but found: '" + viewBox + "'");
|
|
45
59
|
}
|
|
46
60
|
if (docWidth == undefined) {
|
|
47
61
|
docWidth = stripUnits(viewBoxParts[2]);
|
|
@@ -57,14 +71,28 @@ SVGMeasure.prototype.measureSVG = function (svgString) {
|
|
|
57
71
|
};
|
|
58
72
|
};
|
|
59
73
|
|
|
60
|
-
SVGMeasure.prototype.writeDimensions = function (
|
|
74
|
+
SVGMeasure.prototype.writeDimensions = function (svg, dimensions) {
|
|
75
|
+
if (isString(svg)) {
|
|
76
|
+
var doc = parseSVG(svg);
|
|
77
|
+
|
|
78
|
+
if (typeof doc.attr.viewBox !== 'string') {
|
|
79
|
+
doc.attr.viewBox = `0 0 ${stripUnits(doc.attr.width)} ${stripUnits(doc.attr.height)}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
doc.attr.width = "" + dimensions.width;
|
|
83
|
+
doc.attr.height = "" + dimensions.height;
|
|
84
|
+
|
|
85
|
+
return doc.toString();
|
|
86
|
+
}
|
|
61
87
|
|
|
62
|
-
|
|
88
|
+
if (!svg.hasAttribute('viewBox')) {
|
|
89
|
+
svg.setAttribute('viewBox', `0 0 ${stripUnits(svg.getAttribute('width'))} ${stripUnits(svg.getAttribute('height'))}`);
|
|
90
|
+
}
|
|
63
91
|
|
|
64
|
-
|
|
65
|
-
|
|
92
|
+
svg.setAttribute('width', "" + dimensions.width);
|
|
93
|
+
svg.setAttribute('height', "" + dimensions.height);
|
|
66
94
|
|
|
67
|
-
return
|
|
95
|
+
return svg;
|
|
68
96
|
};
|
|
69
97
|
|
|
70
98
|
module.exports = SVGMeasure;
|
package/src/textTools.js
CHANGED
|
@@ -118,8 +118,19 @@ TextTools.prototype.widthOfString = function (text, font, fontSize, characterSpa
|
|
|
118
118
|
return widthOfString(text, font, fontSize, characterSpacing, fontFeatures);
|
|
119
119
|
};
|
|
120
120
|
|
|
121
|
-
function splitWords(text, noWrap) {
|
|
121
|
+
function splitWords(text, noWrap, breakAll) {
|
|
122
|
+
if (breakAll === undefined) {
|
|
123
|
+
breakAll = false;
|
|
124
|
+
}
|
|
125
|
+
|
|
122
126
|
var results = [];
|
|
127
|
+
|
|
128
|
+
if (text === undefined || text === null) {
|
|
129
|
+
text = '';
|
|
130
|
+
} else {
|
|
131
|
+
text = String(text);
|
|
132
|
+
}
|
|
133
|
+
|
|
123
134
|
text = text.replace(/\t/g, ' ');
|
|
124
135
|
|
|
125
136
|
if (noWrap) {
|
|
@@ -127,6 +138,19 @@ function splitWords(text, noWrap) {
|
|
|
127
138
|
return results;
|
|
128
139
|
}
|
|
129
140
|
|
|
141
|
+
if (text.length === 0) {
|
|
142
|
+
results.push({ text: '' });
|
|
143
|
+
return results;
|
|
144
|
+
}
|
|
145
|
+
if (breakAll) {
|
|
146
|
+
return text.split('').map(c => {
|
|
147
|
+
if(c.match(/^\n$|^\r$/)) { // new line
|
|
148
|
+
return { text: '', lineEnd: true };
|
|
149
|
+
}
|
|
150
|
+
return { text: c };
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
130
154
|
var breaker = new LineBreaker(text);
|
|
131
155
|
var last = 0;
|
|
132
156
|
var bk;
|
|
@@ -205,15 +229,16 @@ function normalizeTextArray(array, styleContextStack) {
|
|
|
205
229
|
var style = null;
|
|
206
230
|
var words;
|
|
207
231
|
|
|
232
|
+
var breakAll = getStyleProperty(item || {}, styleContextStack, 'wordBreak', 'normal') === 'break-all';
|
|
208
233
|
var noWrap = getStyleProperty(item || {}, styleContextStack, 'noWrap', false);
|
|
209
234
|
if (isObject(item)) {
|
|
210
235
|
if (item._textRef && item._textRef._textNodeRef.text) {
|
|
211
236
|
item.text = item._textRef._textNodeRef.text;
|
|
212
237
|
}
|
|
213
|
-
words = splitWords(normalizeString(item.text), noWrap);
|
|
238
|
+
words = splitWords(normalizeString(item.text), noWrap, breakAll);
|
|
214
239
|
style = copyStyle(item);
|
|
215
240
|
} else {
|
|
216
|
-
words = splitWords(normalizeString(item), noWrap);
|
|
241
|
+
words = splitWords(normalizeString(item), noWrap, breakAll);
|
|
217
242
|
}
|
|
218
243
|
|
|
219
244
|
if (lastWord && words.length) {
|