pdfmake 0.1.61 → 0.1.65
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/build/pdfmake.js +2978 -2161
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +8 -8
- package/build/pdfmake.min.js.map +1 -1
- package/package.json +69 -69
- package/src/docMeasure.js +8 -1
- package/src/fontProvider.js +15 -2
- package/src/layoutBuilder.js +44 -28
- package/src/printer.js +29 -29
- package/src/styleContextStack.js +1 -0
- package/src/tableProcessor.js +7 -1
- package/webpack.config.js +1 -1
package/package.json
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pdfmake",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "Client/server side PDF printing in pure JavaScript",
|
|
5
|
-
"main": "src/printer.js",
|
|
6
|
-
"browser": "build/pdfmake.js",
|
|
7
|
-
"directories": {
|
|
8
|
-
"test": "tests"
|
|
9
|
-
},
|
|
10
|
-
"dependencies": {
|
|
11
|
-
"iconv-lite": "^0.5.
|
|
12
|
-
"linebreak": "^1.0.2",
|
|
13
|
-
"pdfkit": "^0.
|
|
14
|
-
"svg-to-pdfkit": "^0.1.
|
|
15
|
-
},
|
|
16
|
-
"devDependencies": {
|
|
17
|
-
"@babel/core": "^7.
|
|
18
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
19
|
-
"@babel/preset-env": "^7.
|
|
20
|
-
"babel-loader": "^8.0.6",
|
|
21
|
-
"brfs": "^2.0.2",
|
|
22
|
-
"eslint-plugin-jsdoc": "^
|
|
23
|
-
"expose-loader": "^0.7.5",
|
|
24
|
-
"fancy-log": "^1.3.3",
|
|
25
|
-
"file-saver": "^2.0.2",
|
|
26
|
-
"gulp": "^4.0.2",
|
|
27
|
-
"gulp-each": "^0.5.0",
|
|
28
|
-
"gulp-eslint": "^6.0.0",
|
|
29
|
-
"gulp-file-contents-to-json": "^0.2.2",
|
|
30
|
-
"gulp-spawn-mocha": "^
|
|
31
|
-
"mocha": "^
|
|
32
|
-
"rewire": "^4.0.1",
|
|
33
|
-
"sinon": "^
|
|
34
|
-
"string-replace-webpack-plugin": "^0.1.3",
|
|
35
|
-
"transform-loader": "^0.2.4",
|
|
36
|
-
"uglifyjs-webpack-plugin": "^2.2.0",
|
|
37
|
-
"webpack": "^4.
|
|
38
|
-
},
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "gulp build",
|
|
41
|
-
"test": "gulp",
|
|
42
|
-
"playground": "node dev-playground/server.js"
|
|
43
|
-
},
|
|
44
|
-
"repository": {
|
|
45
|
-
"type": "git",
|
|
46
|
-
"url": "git://github.com/bpampuch/pdfmake.git"
|
|
47
|
-
},
|
|
48
|
-
"keywords": [
|
|
49
|
-
"pdf",
|
|
50
|
-
"javascript",
|
|
51
|
-
"printing",
|
|
52
|
-
"layout"
|
|
53
|
-
],
|
|
54
|
-
"author": "Bartek Pampuch <bartosz.pampuch@gmail.com>",
|
|
55
|
-
"license": "MIT",
|
|
56
|
-
"bugs": {
|
|
57
|
-
"url": "https://github.com/bpampuch/pdfmake/issues"
|
|
58
|
-
},
|
|
59
|
-
"homepage": "http://pdfmake.org",
|
|
60
|
-
"config": {
|
|
61
|
-
"blanket": {
|
|
62
|
-
"pattern": "src",
|
|
63
|
-
"data-cover-never": [
|
|
64
|
-
"node_modules",
|
|
65
|
-
"tests"
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "pdfmake",
|
|
3
|
+
"version": "0.1.65",
|
|
4
|
+
"description": "Client/server side PDF printing in pure JavaScript",
|
|
5
|
+
"main": "src/printer.js",
|
|
6
|
+
"browser": "build/pdfmake.js",
|
|
7
|
+
"directories": {
|
|
8
|
+
"test": "tests"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"iconv-lite": "^0.5.1",
|
|
12
|
+
"linebreak": "^1.0.2",
|
|
13
|
+
"pdfkit": "^0.11.0",
|
|
14
|
+
"svg-to-pdfkit": "^0.1.8"
|
|
15
|
+
},
|
|
16
|
+
"devDependencies": {
|
|
17
|
+
"@babel/core": "^7.8.4",
|
|
18
|
+
"@babel/plugin-transform-modules-commonjs": "^7.8.3",
|
|
19
|
+
"@babel/preset-env": "^7.8.4",
|
|
20
|
+
"babel-loader": "^8.0.6",
|
|
21
|
+
"brfs": "^2.0.2",
|
|
22
|
+
"eslint-plugin-jsdoc": "^21.0.0",
|
|
23
|
+
"expose-loader": "^0.7.5",
|
|
24
|
+
"fancy-log": "^1.3.3",
|
|
25
|
+
"file-saver": "^2.0.2",
|
|
26
|
+
"gulp": "^4.0.2",
|
|
27
|
+
"gulp-each": "^0.5.0",
|
|
28
|
+
"gulp-eslint": "^6.0.0",
|
|
29
|
+
"gulp-file-contents-to-json": "^0.2.2",
|
|
30
|
+
"gulp-spawn-mocha": "^6.0.0",
|
|
31
|
+
"mocha": "^7.0.1",
|
|
32
|
+
"rewire": "^4.0.1",
|
|
33
|
+
"sinon": "^8.1.1",
|
|
34
|
+
"string-replace-webpack-plugin": "^0.1.3",
|
|
35
|
+
"transform-loader": "^0.2.4",
|
|
36
|
+
"uglifyjs-webpack-plugin": "^2.2.0",
|
|
37
|
+
"webpack": "^4.41.5"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"build": "gulp build",
|
|
41
|
+
"test": "gulp",
|
|
42
|
+
"playground": "node dev-playground/server.js"
|
|
43
|
+
},
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "git://github.com/bpampuch/pdfmake.git"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"pdf",
|
|
50
|
+
"javascript",
|
|
51
|
+
"printing",
|
|
52
|
+
"layout"
|
|
53
|
+
],
|
|
54
|
+
"author": "Bartek Pampuch <bartosz.pampuch@gmail.com>",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/bpampuch/pdfmake/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "http://pdfmake.org",
|
|
60
|
+
"config": {
|
|
61
|
+
"blanket": {
|
|
62
|
+
"pattern": "src",
|
|
63
|
+
"data-cover-never": [
|
|
64
|
+
"node_modules",
|
|
65
|
+
"tests"
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/docMeasure.js
CHANGED
|
@@ -210,6 +210,8 @@ DocMeasure.prototype.measureSVG = function (node) {
|
|
|
210
210
|
|
|
211
211
|
this.measureImageWithDimensions(node, dimensions);
|
|
212
212
|
|
|
213
|
+
node.font = this.styleStack.getProperty('font');
|
|
214
|
+
|
|
213
215
|
// scale SVG based on final dimension
|
|
214
216
|
node.svg = this.svgMeasure.writeDimensions(node.svg, {
|
|
215
217
|
width: node._width,
|
|
@@ -601,6 +603,7 @@ DocMeasure.prototype.measureTable = function (node) {
|
|
|
601
603
|
return function () {
|
|
602
604
|
if (isObject(data)) {
|
|
603
605
|
data.fillColor = _this.styleStack.getProperty('fillColor');
|
|
606
|
+
data.fillOpacity = _this.styleStack.getProperty('fillOpacity');
|
|
604
607
|
}
|
|
605
608
|
return _this.measureNode(data);
|
|
606
609
|
};
|
|
@@ -647,6 +650,9 @@ DocMeasure.prototype.measureTable = function (node) {
|
|
|
647
650
|
fillColor: function (i, node) {
|
|
648
651
|
return null;
|
|
649
652
|
},
|
|
653
|
+
fillOpacity: function (i, node) {
|
|
654
|
+
return 1;
|
|
655
|
+
},
|
|
650
656
|
defaultBorder: true
|
|
651
657
|
};
|
|
652
658
|
|
|
@@ -729,7 +735,8 @@ DocMeasure.prototype.measureTable = function (node) {
|
|
|
729
735
|
_span: true,
|
|
730
736
|
_minWidth: 0,
|
|
731
737
|
_maxWidth: 0,
|
|
732
|
-
fillColor: table.body[row][col].fillColor
|
|
738
|
+
fillColor: table.body[row][col].fillColor,
|
|
739
|
+
fillOpacity: table.body[row][col].fillOpacity
|
|
733
740
|
};
|
|
734
741
|
}
|
|
735
742
|
}
|
package/src/fontProvider.js
CHANGED
|
@@ -33,9 +33,22 @@ function FontProvider(fontDescriptors, pdfKitDoc) {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
FontProvider.prototype.
|
|
37
|
-
|
|
36
|
+
FontProvider.prototype.getFontType = function (bold, italics) {
|
|
37
|
+
return typeName(bold, italics);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
FontProvider.prototype.getFontFile = function (familyName, bold, italics) {
|
|
41
|
+
var type = this.getFontType(bold, italics);
|
|
38
42
|
if (!this.fonts[familyName] || !this.fonts[familyName][type]) {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return this.fonts[familyName][type];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
FontProvider.prototype.provideFont = function (familyName, bold, italics) {
|
|
50
|
+
var type = this.getFontType(bold, italics);
|
|
51
|
+
if (this.getFontFile(familyName, bold, italics) === null) {
|
|
39
52
|
throw new Error('Font \'' + familyName + '\' in style \'' + type + '\' is not defined in the font section of the document definition.');
|
|
40
53
|
}
|
|
41
54
|
|
package/src/layoutBuilder.js
CHANGED
|
@@ -19,6 +19,7 @@ var getNodeId = require('./helpers').getNodeId;
|
|
|
19
19
|
var isFunction = require('./helpers').isFunction;
|
|
20
20
|
var TextTools = require('./textTools');
|
|
21
21
|
var StyleContextStack = require('./styleContextStack');
|
|
22
|
+
var isNumber = require('./helpers').isNumber;
|
|
22
23
|
|
|
23
24
|
function addAll(target, otherArray) {
|
|
24
25
|
otherArray.forEach(function (item) {
|
|
@@ -91,40 +92,35 @@ LayoutBuilder.prototype.layoutDocument = function (docStructure, fontProvider, s
|
|
|
91
92
|
node.nodeInfo = nodeInfo;
|
|
92
93
|
});
|
|
93
94
|
|
|
94
|
-
|
|
95
|
+
for (var index = 0; index < linearNodeList.length; index++) {
|
|
96
|
+
var node = linearNodeList[index];
|
|
95
97
|
if (node.pageBreak !== 'before' && !node.pageBreakCalculated) {
|
|
96
98
|
node.pageBreakCalculated = true;
|
|
97
99
|
var pageNumber = node.nodeInfo.pageNumbers[0];
|
|
98
|
-
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
return node.nodeInfo;
|
|
116
|
-
}),
|
|
117
|
-
nodesOnNextPage.map(function (node) {
|
|
118
|
-
return node.nodeInfo;
|
|
119
|
-
}),
|
|
120
|
-
previousNodesOnPage.map(function (node) {
|
|
121
|
-
return node.nodeInfo;
|
|
122
|
-
}))) {
|
|
100
|
+
var followingNodesOnPage = [];
|
|
101
|
+
var nodesOnNextPage = [];
|
|
102
|
+
var previousNodesOnPage = [];
|
|
103
|
+
for (var ii = index + 1, l = linearNodeList.length; ii < l; ii++) {
|
|
104
|
+
if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
|
|
105
|
+
followingNodesOnPage.push(linearNodeList[ii].nodeInfo);
|
|
106
|
+
}
|
|
107
|
+
if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber + 1) > -1) {
|
|
108
|
+
nodesOnNextPage.push(linearNodeList[ii].nodeInfo);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
for (var ii = 0; ii < index; ii++) {
|
|
112
|
+
if (linearNodeList[ii].nodeInfo.pageNumbers.indexOf(pageNumber) > -1) {
|
|
113
|
+
previousNodesOnPage.push(linearNodeList[ii].nodeInfo);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (pageBreakBeforeFct(node.nodeInfo, followingNodesOnPage, nodesOnNextPage, previousNodesOnPage)) {
|
|
123
117
|
node.pageBreak = 'before';
|
|
124
118
|
return true;
|
|
125
119
|
}
|
|
126
120
|
}
|
|
127
|
-
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return false;
|
|
128
124
|
}
|
|
129
125
|
|
|
130
126
|
this.docPreprocessor = new DocPreprocessor();
|
|
@@ -258,7 +254,7 @@ LayoutBuilder.prototype.addWatermark = function (watermark, fontProvider, defaul
|
|
|
258
254
|
watermark.font = watermark.font || defaultStyle.font || 'Roboto';
|
|
259
255
|
watermark.fontSize = watermark.fontSize || 'auto';
|
|
260
256
|
watermark.color = watermark.color || 'black';
|
|
261
|
-
watermark.opacity = watermark.opacity
|
|
257
|
+
watermark.opacity = isNumber(watermark.opacity) ? watermark.opacity : 0.6;
|
|
262
258
|
watermark.bold = watermark.bold || false;
|
|
263
259
|
watermark.italics = watermark.italics || false;
|
|
264
260
|
watermark.angle = !isUndefined(watermark.angle) && !isNull(watermark.angle) ? watermark.angle : null;
|
|
@@ -433,6 +429,16 @@ LayoutBuilder.prototype.processNode = function (node) {
|
|
|
433
429
|
|
|
434
430
|
if (node.pageBreak === 'before') {
|
|
435
431
|
self.writer.moveToNextPage(node.pageOrientation);
|
|
432
|
+
} else if (node.pageBreak === 'beforeOdd') {
|
|
433
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
434
|
+
if ((self.writer.context().page + 1) % 2 === 1) {
|
|
435
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
436
|
+
}
|
|
437
|
+
} else if (node.pageBreak === 'beforeEven') {
|
|
438
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
439
|
+
if ((self.writer.context().page + 1) % 2 === 0) {
|
|
440
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
441
|
+
}
|
|
436
442
|
}
|
|
437
443
|
|
|
438
444
|
if (margin) {
|
|
@@ -449,6 +455,16 @@ LayoutBuilder.prototype.processNode = function (node) {
|
|
|
449
455
|
|
|
450
456
|
if (node.pageBreak === 'after') {
|
|
451
457
|
self.writer.moveToNextPage(node.pageOrientation);
|
|
458
|
+
} else if (node.pageBreak === 'afterOdd') {
|
|
459
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
460
|
+
if ((self.writer.context().page + 1) % 2 === 1) {
|
|
461
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
462
|
+
}
|
|
463
|
+
} else if (node.pageBreak === 'afterEven') {
|
|
464
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
465
|
+
if ((self.writer.context().page + 1) % 2 === 0) {
|
|
466
|
+
self.writer.moveToNextPage(node.pageOrientation);
|
|
467
|
+
}
|
|
452
468
|
}
|
|
453
469
|
}
|
|
454
470
|
};
|
package/src/printer.js
CHANGED
|
@@ -39,18 +39,6 @@ var findFont = function (fonts, requiredFonts, defaultFont) {
|
|
|
39
39
|
return defaultFont;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
var typeName = function (bold, italics) {
|
|
43
|
-
var type = 'normal';
|
|
44
|
-
if (bold && italics) {
|
|
45
|
-
type = 'bolditalics';
|
|
46
|
-
} else if (bold) {
|
|
47
|
-
type = 'bold';
|
|
48
|
-
} else if (italics) {
|
|
49
|
-
type = 'italics';
|
|
50
|
-
}
|
|
51
|
-
return type;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
42
|
////////////////////////////////////////
|
|
55
43
|
// PdfPrinter
|
|
56
44
|
|
|
@@ -124,6 +112,7 @@ PdfPrinter.prototype.createPdfKitDocument = function (docDefinition, options) {
|
|
|
124
112
|
docDefinition.version = docDefinition.version || '1.3';
|
|
125
113
|
docDefinition.compress = isBoolean(docDefinition.compress) ? docDefinition.compress : true;
|
|
126
114
|
docDefinition.images = docDefinition.images || {};
|
|
115
|
+
docDefinition.pageMargins = ((docDefinition.pageMargins !== undefined) && (docDefinition.pageMargins !== null)) ? docDefinition.pageMargins : 40;
|
|
127
116
|
|
|
128
117
|
var pageSize = fixPageSize(docDefinition.pageSize, docDefinition.pageOrientation);
|
|
129
118
|
|
|
@@ -145,7 +134,7 @@ PdfPrinter.prototype.createPdfKitDocument = function (docDefinition, options) {
|
|
|
145
134
|
|
|
146
135
|
this.fontProvider = new FontProvider(this.fontDescriptors, this.pdfKitDoc);
|
|
147
136
|
|
|
148
|
-
var builder = new LayoutBuilder(pageSize, fixPageMargins(docDefinition.pageMargins
|
|
137
|
+
var builder = new LayoutBuilder(pageSize, fixPageMargins(docDefinition.pageMargins), new ImageMeasure(this.pdfKitDoc, docDefinition.images), new SVGMeasure());
|
|
149
138
|
|
|
150
139
|
registerDefaultTableLayouts(builder);
|
|
151
140
|
if (options.tableLayouts) {
|
|
@@ -271,10 +260,6 @@ function fixPageSize(pageSize, pageOrientation) {
|
|
|
271
260
|
}
|
|
272
261
|
|
|
273
262
|
function fixPageMargins(margin) {
|
|
274
|
-
if (!margin) {
|
|
275
|
-
return null;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
263
|
if (isNumber(margin)) {
|
|
279
264
|
margin = { left: margin, right: margin, top: margin, bottom: margin };
|
|
280
265
|
} else if (isArray(margin)) {
|
|
@@ -490,7 +475,8 @@ function renderLine(line, x, y, pdfKitDoc) {
|
|
|
490
475
|
options.features = inline.fontFeatures;
|
|
491
476
|
}
|
|
492
477
|
|
|
493
|
-
|
|
478
|
+
var opacity = isNumber(inline.opacity) ? inline.opacity : 1;
|
|
479
|
+
pdfKitDoc.opacity(opacity);
|
|
494
480
|
pdfKitDoc.fill(inline.color || 'black');
|
|
495
481
|
|
|
496
482
|
pdfKitDoc._font = inline.font;
|
|
@@ -602,37 +588,51 @@ function renderVector(vector, pdfKitDoc) {
|
|
|
602
588
|
vector.color = gradient;
|
|
603
589
|
}
|
|
604
590
|
|
|
591
|
+
var fillOpacity = isNumber(vector.fillOpacity) ? vector.fillOpacity : 1;
|
|
592
|
+
var strokeOpacity = isNumber(vector.strokeOpacity) ? vector.strokeOpacity : 1;
|
|
593
|
+
|
|
605
594
|
if (vector.color && vector.lineColor) {
|
|
606
|
-
pdfKitDoc.fillColor(vector.color,
|
|
607
|
-
pdfKitDoc.strokeColor(vector.lineColor,
|
|
595
|
+
pdfKitDoc.fillColor(vector.color, fillOpacity);
|
|
596
|
+
pdfKitDoc.strokeColor(vector.lineColor, strokeOpacity);
|
|
608
597
|
pdfKitDoc.fillAndStroke();
|
|
609
598
|
} else if (vector.color) {
|
|
610
|
-
pdfKitDoc.fillColor(vector.color,
|
|
599
|
+
pdfKitDoc.fillColor(vector.color, fillOpacity);
|
|
611
600
|
pdfKitDoc.fill();
|
|
612
601
|
} else {
|
|
613
|
-
pdfKitDoc.strokeColor(vector.lineColor || 'black',
|
|
602
|
+
pdfKitDoc.strokeColor(vector.lineColor || 'black', strokeOpacity);
|
|
614
603
|
pdfKitDoc.stroke();
|
|
615
604
|
}
|
|
616
605
|
}
|
|
617
606
|
|
|
618
607
|
function renderImage(image, x, y, pdfKitDoc) {
|
|
619
|
-
|
|
608
|
+
var opacity = isNumber(image.opacity) ? image.opacity : 1;
|
|
609
|
+
pdfKitDoc.opacity(opacity);
|
|
620
610
|
pdfKitDoc.image(image.image, image.x, image.y, { width: image._width, height: image._height });
|
|
621
611
|
if (image.link) {
|
|
622
612
|
pdfKitDoc.link(image.x, image.y, image._width, image._height, image.link);
|
|
623
613
|
}
|
|
614
|
+
if (image.linkToPage) {
|
|
615
|
+
pdfKitDoc.ref({ Type: 'Action', S: 'GoTo', D: [image.linkToPage, 0, 0] }).end();
|
|
616
|
+
pdfKitDoc.annotate(image.x, image.y, image._width, image._height, { Subtype: 'Link', Dest: [image.linkToPage - 1, 'XYZ', null, null, null] });
|
|
617
|
+
}
|
|
618
|
+
if (image.linkToDestination) {
|
|
619
|
+
pdfKitDoc.goTo(image.x, image.y, image._width, image._height, image.linkToDestination);
|
|
620
|
+
}
|
|
624
621
|
}
|
|
625
622
|
|
|
626
623
|
function renderSVG(svg, x, y, pdfKitDoc, fontProvider) {
|
|
627
624
|
var options = Object.assign({ width: svg._width, height: svg._height, assumePt: true }, svg.options);
|
|
628
|
-
options.fontCallback = function (family, bold, italic
|
|
629
|
-
fontOptions.fauxBold = bold;
|
|
630
|
-
fontOptions.fauxItalic = italic;
|
|
631
|
-
|
|
625
|
+
options.fontCallback = function (family, bold, italic) {
|
|
632
626
|
var fontsFamily = family.split(',').map(function (f) { return f.trim().replace(/('|")/g, ''); });
|
|
633
|
-
var font = findFont(fontProvider.fonts, fontsFamily, 'Roboto');
|
|
627
|
+
var font = findFont(fontProvider.fonts, fontsFamily, svg.font || 'Roboto');
|
|
628
|
+
|
|
629
|
+
var fontFile = fontProvider.getFontFile(font, bold, italic);
|
|
630
|
+
if (fontFile === null) {
|
|
631
|
+
var type = fontProvider.getFontType(bold, italic);
|
|
632
|
+
throw new Error('Font \'' + font + '\' in style \'' + type + '\' is not defined in the font section of the document definition.');
|
|
633
|
+
}
|
|
634
634
|
|
|
635
|
-
return
|
|
635
|
+
return fontFile;
|
|
636
636
|
};
|
|
637
637
|
|
|
638
638
|
getSvgToPDF()(pdfKitDoc, svg.svg, svg.x, svg.y, options);
|
package/src/styleContextStack.js
CHANGED
package/src/tableProcessor.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var ColumnCalculator = require('./columnCalculator');
|
|
4
4
|
var isFunction = require('./helpers').isFunction;
|
|
5
|
+
var isNumber = require('./helpers').isNumber;
|
|
5
6
|
|
|
6
7
|
function TableProcessor(tableNode) {
|
|
7
8
|
this.tableNode = tableNode;
|
|
@@ -419,9 +420,13 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
|
|
|
419
420
|
|
|
420
421
|
if (i < l - 1) {
|
|
421
422
|
var fillColor = body[rowIndex][colIndex].fillColor;
|
|
423
|
+
var fillOpacity = body[rowIndex][colIndex].fillOpacity;
|
|
422
424
|
if (!fillColor) {
|
|
423
425
|
fillColor = isFunction(this.layout.fillColor) ? this.layout.fillColor(rowIndex, this.tableNode, colIndex) : this.layout.fillColor;
|
|
424
426
|
}
|
|
427
|
+
if (!isNumber(fillOpacity)) {
|
|
428
|
+
fillOpacity = isFunction(this.layout.fillOpacity) ? this.layout.fillOpacity(rowIndex, this.tableNode, colIndex) : this.layout.fillOpacity;
|
|
429
|
+
}
|
|
425
430
|
if (fillColor) {
|
|
426
431
|
var widthLeftBorder = leftCellBorder ? this.layout.vLineWidth(colIndex, this.tableNode) : 0;
|
|
427
432
|
var widthRightBorder;
|
|
@@ -444,7 +449,8 @@ TableProcessor.prototype.endRow = function (rowIndex, writer, pageBreaks) {
|
|
|
444
449
|
w: x2f - x1f,
|
|
445
450
|
h: y2f - y1f,
|
|
446
451
|
lineWidth: 0,
|
|
447
|
-
color: fillColor
|
|
452
|
+
color: fillColor,
|
|
453
|
+
fillOpacity: fillOpacity
|
|
448
454
|
}, false, true, writer.context().backgroundLength[writer.context().page]);
|
|
449
455
|
}
|
|
450
456
|
}
|
package/webpack.config.js
CHANGED
|
@@ -46,7 +46,7 @@ module.exports = {
|
|
|
46
46
|
},
|
|
47
47
|
{
|
|
48
48
|
test: /\.js$/,
|
|
49
|
-
include: /(pdfkit|saslprep|unicode-trie|unicode-properties|dfa|linebreak)/,
|
|
49
|
+
include: /(pdfkit|saslprep|unicode-trie|unicode-properties|dfa|linebreak|png-js)/,
|
|
50
50
|
use: {
|
|
51
51
|
loader: 'babel-loader',
|
|
52
52
|
options: {
|