pdfmake 0.2.3 → 0.2.4
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 +6 -0
- package/build/pdfmake.js +723 -791
- 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.js +1 -1
- package/package.json +2 -2
- package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
- package/src/printer.js +705 -705
package/build/pdfmake.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/*! pdfmake v0.2.
|
|
1
|
+
/*! pdfmake v0.2.4, @license MIT, @link http://pdfmake.org */
|
|
2
2
|
(function webpackUniversalModuleDefinition(root, factory) {
|
|
3
3
|
if(typeof exports === 'object' && typeof module === 'object')
|
|
4
4
|
module.exports = factory();
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
return /******/ (function() { // webpackBootstrap
|
|
13
13
|
/******/ var __webpack_modules__ = ({
|
|
14
14
|
|
|
15
|
-
/***/
|
|
15
|
+
/***/ 9282:
|
|
16
16
|
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
17
17
|
|
|
18
18
|
"use strict";
|
|
@@ -1280,7 +1280,7 @@ function includes(str, search, start) {
|
|
|
1280
1280
|
|
|
1281
1281
|
createErrorType('ERR_AMBIGUOUS_ARGUMENT', 'The "%s" argument is ambiguous. %s', TypeError);
|
|
1282
1282
|
createErrorType('ERR_INVALID_ARG_TYPE', function (name, expected, actual) {
|
|
1283
|
-
if (assert === undefined) assert = __webpack_require__(
|
|
1283
|
+
if (assert === undefined) assert = __webpack_require__(9282);
|
|
1284
1284
|
assert(typeof name === 'string', "'name' must be a string"); // determiner: 'must be' or 'must not be'
|
|
1285
1285
|
|
|
1286
1286
|
var determiner;
|
|
@@ -1333,7 +1333,7 @@ createErrorType('ERR_MISSING_ARGS', function () {
|
|
|
1333
1333
|
args[_key] = arguments[_key];
|
|
1334
1334
|
}
|
|
1335
1335
|
|
|
1336
|
-
if (assert === undefined) assert = __webpack_require__(
|
|
1336
|
+
if (assert === undefined) assert = __webpack_require__(9282);
|
|
1337
1337
|
assert(args.length > 0, 'At least one arg needs to be specified');
|
|
1338
1338
|
var msg = 'The ';
|
|
1339
1339
|
var len = args.length;
|
|
@@ -6167,33 +6167,6 @@ module.exports = typeof ArrayBuffer != 'undefined' && typeof DataView != 'undefi
|
|
|
6167
6167
|
|
|
6168
6168
|
/***/ }),
|
|
6169
6169
|
|
|
6170
|
-
/***/ 5158:
|
|
6171
|
-
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
6172
|
-
|
|
6173
|
-
"use strict";
|
|
6174
|
-
|
|
6175
|
-
|
|
6176
|
-
__webpack_require__(7803);
|
|
6177
|
-
|
|
6178
|
-
__webpack_require__(1539);
|
|
6179
|
-
|
|
6180
|
-
__webpack_require__(1825);
|
|
6181
|
-
|
|
6182
|
-
// FF26- bug: ArrayBuffers are non-extensible, but Object.isExtensible does not report it
|
|
6183
|
-
var fails = __webpack_require__(7293);
|
|
6184
|
-
|
|
6185
|
-
module.exports = fails(function () {
|
|
6186
|
-
if (typeof ArrayBuffer == 'function') {
|
|
6187
|
-
var buffer = new ArrayBuffer(8); // eslint-disable-next-line es/no-object-isextensible, es/no-object-defineproperty -- safe
|
|
6188
|
-
|
|
6189
|
-
if (Object.isExtensible(buffer)) Object.defineProperty(buffer, 'a', {
|
|
6190
|
-
value: 8
|
|
6191
|
-
});
|
|
6192
|
-
}
|
|
6193
|
-
});
|
|
6194
|
-
|
|
6195
|
-
/***/ }),
|
|
6196
|
-
|
|
6197
6170
|
/***/ 2094:
|
|
6198
6171
|
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
6199
6172
|
|
|
@@ -14377,7 +14350,7 @@ module.exports = /*#__PURE__*/function () {
|
|
|
14377
14350
|
|
|
14378
14351
|
/***/ }),
|
|
14379
14352
|
|
|
14380
|
-
/***/
|
|
14353
|
+
/***/ 4872:
|
|
14381
14354
|
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
14382
14355
|
|
|
14383
14356
|
"use strict";
|
|
@@ -28568,7 +28541,7 @@ module.exports = __webpack_require__(6450).BrotliDecompressBuffer;
|
|
|
28568
28541
|
|
|
28569
28542
|
/* eslint camelcase: "off" */
|
|
28570
28543
|
|
|
28571
|
-
var assert = __webpack_require__(
|
|
28544
|
+
var assert = __webpack_require__(9282);
|
|
28572
28545
|
|
|
28573
28546
|
var Zstream = __webpack_require__(4860);
|
|
28574
28547
|
var zlib_deflate = __webpack_require__(2233);
|
|
@@ -28988,7 +28961,7 @@ var Buffer = (__webpack_require__(8823).Buffer);
|
|
|
28988
28961
|
var Transform = (__webpack_require__(2830).Transform);
|
|
28989
28962
|
var binding = __webpack_require__(4505);
|
|
28990
28963
|
var util = __webpack_require__(9539);
|
|
28991
|
-
var assert = (__webpack_require__(
|
|
28964
|
+
var assert = (__webpack_require__(9282).ok);
|
|
28992
28965
|
var kMaxLength = (__webpack_require__(8823).kMaxLength);
|
|
28993
28966
|
var kRangeErrorMessage = 'Cannot create final Buffer. It would be larger ' + 'than 0x' + kMaxLength.toString(16) + ' bytes';
|
|
28994
28967
|
|
|
@@ -38040,7 +38013,6 @@ var hasOwn = __webpack_require__(2597);
|
|
|
38040
38013
|
var defineProperty = (__webpack_require__(3070).f);
|
|
38041
38014
|
var getOwnPropertyNamesModule = __webpack_require__(8006);
|
|
38042
38015
|
var getOwnPropertyNamesExternalModule = __webpack_require__(1156);
|
|
38043
|
-
var isExtensible = __webpack_require__(2050);
|
|
38044
38016
|
var uid = __webpack_require__(9711);
|
|
38045
38017
|
var FREEZING = __webpack_require__(6677);
|
|
38046
38018
|
|
|
@@ -38048,6 +38020,11 @@ var REQUIRED = false;
|
|
|
38048
38020
|
var METADATA = uid('meta');
|
|
38049
38021
|
var id = 0;
|
|
38050
38022
|
|
|
38023
|
+
// eslint-disable-next-line es/no-object-isextensible -- safe
|
|
38024
|
+
var isExtensible = Object.isExtensible || function () {
|
|
38025
|
+
return true;
|
|
38026
|
+
};
|
|
38027
|
+
|
|
38051
38028
|
var setMetadata = function (it) {
|
|
38052
38029
|
defineProperty(it, METADATA, { value: {
|
|
38053
38030
|
objectID: 'O' + id++, // object ID
|
|
@@ -39113,29 +39090,6 @@ module.exports = CORRECT_PROTOTYPE_GETTER ? Object.getPrototypeOf : function (O)
|
|
|
39113
39090
|
};
|
|
39114
39091
|
|
|
39115
39092
|
|
|
39116
|
-
/***/ }),
|
|
39117
|
-
|
|
39118
|
-
/***/ 2050:
|
|
39119
|
-
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
39120
|
-
|
|
39121
|
-
var fails = __webpack_require__(7293);
|
|
39122
|
-
var isObject = __webpack_require__(111);
|
|
39123
|
-
var classof = __webpack_require__(4326);
|
|
39124
|
-
var ARRAY_BUFFER_NON_EXTENSIBLE = __webpack_require__(5158);
|
|
39125
|
-
|
|
39126
|
-
// eslint-disable-next-line es/no-object-isextensible -- safe
|
|
39127
|
-
var $isExtensible = Object.isExtensible;
|
|
39128
|
-
var FAILS_ON_PRIMITIVES = fails(function () { $isExtensible(1); });
|
|
39129
|
-
|
|
39130
|
-
// `Object.isExtensible` method
|
|
39131
|
-
// https://tc39.es/ecma262/#sec-object.isextensible
|
|
39132
|
-
module.exports = (FAILS_ON_PRIMITIVES || ARRAY_BUFFER_NON_EXTENSIBLE) ? function isExtensible(it) {
|
|
39133
|
-
if (!isObject(it)) return false;
|
|
39134
|
-
if (ARRAY_BUFFER_NON_EXTENSIBLE && classof(it) == 'ArrayBuffer') return false;
|
|
39135
|
-
return $isExtensible ? $isExtensible(it) : true;
|
|
39136
|
-
} : $isExtensible;
|
|
39137
|
-
|
|
39138
|
-
|
|
39139
39093
|
/***/ }),
|
|
39140
39094
|
|
|
39141
39095
|
/***/ 7976:
|
|
@@ -39817,7 +39771,7 @@ var store = __webpack_require__(5465);
|
|
|
39817
39771
|
(module.exports = function (key, value) {
|
|
39818
39772
|
return store[key] || (store[key] = value !== undefined ? value : {});
|
|
39819
39773
|
})('versions', []).push({
|
|
39820
|
-
version: '3.19.
|
|
39774
|
+
version: '3.19.0',
|
|
39821
39775
|
mode: IS_PURE ? 'pure' : 'global',
|
|
39822
39776
|
copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
|
|
39823
39777
|
});
|
|
@@ -40811,22 +40765,16 @@ var clearErrorStack = __webpack_require__(7741);
|
|
|
40811
40765
|
var installErrorCause = __webpack_require__(8340);
|
|
40812
40766
|
var iterate = __webpack_require__(408);
|
|
40813
40767
|
var normalizeStringArgument = __webpack_require__(6277);
|
|
40814
|
-
var wellKnownSymbol = __webpack_require__(5112);
|
|
40815
40768
|
var ERROR_STACK_INSTALLABLE = __webpack_require__(2914);
|
|
40816
40769
|
|
|
40817
|
-
var TO_STRING_TAG = wellKnownSymbol('toStringTag');
|
|
40818
40770
|
var Error = global.Error;
|
|
40819
40771
|
var push = [].push;
|
|
40820
40772
|
|
|
40821
40773
|
var $AggregateError = function AggregateError(errors, message /* , options */) {
|
|
40774
|
+
var that = isPrototypeOf(AggregateErrorPrototype, this) ? this : create(AggregateErrorPrototype);
|
|
40822
40775
|
var options = arguments.length > 2 ? arguments[2] : undefined;
|
|
40823
|
-
var isInstance = isPrototypeOf(AggregateErrorPrototype, this);
|
|
40824
|
-
var that;
|
|
40825
40776
|
if (setPrototypeOf) {
|
|
40826
|
-
that = setPrototypeOf(new Error(undefined),
|
|
40827
|
-
} else {
|
|
40828
|
-
that = isInstance ? this : create(AggregateErrorPrototype);
|
|
40829
|
-
createNonEnumerableProperty(that, TO_STRING_TAG, 'Error');
|
|
40777
|
+
that = setPrototypeOf(new Error(undefined), getPrototypeOf(that));
|
|
40830
40778
|
}
|
|
40831
40779
|
createNonEnumerableProperty(that, 'message', normalizeStringArgument(message, ''));
|
|
40832
40780
|
if (ERROR_STACK_INSTALLABLE) createNonEnumerableProperty(that, 'stack', clearErrorStack(that.stack, 1));
|
|
@@ -41886,22 +41834,6 @@ $({ target: 'Object', stat: true, forced: FAILS_ON_PRIMITIVES, sham: !CORRECT_PR
|
|
|
41886
41834
|
|
|
41887
41835
|
|
|
41888
41836
|
|
|
41889
|
-
/***/ }),
|
|
41890
|
-
|
|
41891
|
-
/***/ 1825:
|
|
41892
|
-
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
|
|
41893
|
-
|
|
41894
|
-
var $ = __webpack_require__(2109);
|
|
41895
|
-
var $isExtensible = __webpack_require__(2050);
|
|
41896
|
-
|
|
41897
|
-
// `Object.isExtensible` method
|
|
41898
|
-
// https://tc39.es/ecma262/#sec-object.isextensible
|
|
41899
|
-
// eslint-disable-next-line es/no-object-isextensible -- safe
|
|
41900
|
-
$({ target: 'Object', stat: true, forced: Object.isExtensible !== $isExtensible }, {
|
|
41901
|
-
isExtensible: $isExtensible
|
|
41902
|
-
});
|
|
41903
|
-
|
|
41904
|
-
|
|
41905
41837
|
/***/ }),
|
|
41906
41838
|
|
|
41907
41839
|
/***/ 7941:
|
|
@@ -55568,7 +55500,7 @@ module.exports = __webpack_require__(7187).EventEmitter;
|
|
|
55568
55500
|
|
|
55569
55501
|
/***/ }),
|
|
55570
55502
|
|
|
55571
|
-
/***/
|
|
55503
|
+
/***/ 4896:
|
|
55572
55504
|
/***/ (function(module, exports, __webpack_require__) {
|
|
55573
55505
|
|
|
55574
55506
|
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(a,b){if(true)!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (b),
|
|
@@ -72713,7 +72645,7 @@ module.exports = URLBrowserResolver;
|
|
|
72713
72645
|
var isFunction = (__webpack_require__(6225).isFunction);
|
|
72714
72646
|
var isUndefined = (__webpack_require__(6225).isUndefined);
|
|
72715
72647
|
var isNull = (__webpack_require__(6225).isNull);
|
|
72716
|
-
var FileSaver = __webpack_require__(
|
|
72648
|
+
var FileSaver = __webpack_require__(4896);
|
|
72717
72649
|
var saveAs = FileSaver.saveAs;
|
|
72718
72650
|
|
|
72719
72651
|
var defaultClientFonts = {
|
|
@@ -76315,7 +76247,7 @@ function _interopDefault(ex) {
|
|
|
76315
76247
|
return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex;
|
|
76316
76248
|
}
|
|
76317
76249
|
|
|
76318
|
-
var PdfKit = _interopDefault(__webpack_require__(
|
|
76250
|
+
var PdfKit = _interopDefault(__webpack_require__(4872));
|
|
76319
76251
|
|
|
76320
76252
|
function getEngineInstance() {
|
|
76321
76253
|
return PdfKit;
|
|
@@ -76338,711 +76270,711 @@ module.exports = {
|
|
|
76338
76270
|
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
|
|
76339
76271
|
|
|
76340
76272
|
"use strict";
|
|
76341
|
-
/*eslint no-unused-vars: ["error", {"args": "none"}]*/
|
|
76342
|
-
|
|
76343
|
-
|
|
76344
|
-
var PdfKitEngine = __webpack_require__(6079);
|
|
76345
|
-
var FontProvider = __webpack_require__(2249);
|
|
76346
|
-
var LayoutBuilder = __webpack_require__(2678);
|
|
76347
|
-
var sizes = __webpack_require__(4762);
|
|
76348
|
-
var ImageMeasure = __webpack_require__(3090);
|
|
76349
|
-
var SVGMeasure = __webpack_require__(7601);
|
|
76350
|
-
var textDecorator = __webpack_require__(3497);
|
|
76351
|
-
var TextTools = __webpack_require__(1350);
|
|
76352
|
-
var isFunction = (__webpack_require__(6225).isFunction);
|
|
76353
|
-
var isString = (__webpack_require__(6225).isString);
|
|
76354
|
-
var isNumber = (__webpack_require__(6225).isNumber);
|
|
76355
|
-
var isBoolean = (__webpack_require__(6225).isBoolean);
|
|
76356
|
-
var isArray = (__webpack_require__(6225).isArray);
|
|
76357
|
-
var isUndefined = (__webpack_require__(6225).isUndefined);
|
|
76358
|
-
var isPattern = (__webpack_require__(6225).isPattern);
|
|
76359
|
-
var getPattern = (__webpack_require__(6225).getPattern);
|
|
76360
|
-
var SVGtoPDF = __webpack_require__(8071);
|
|
76361
|
-
|
|
76362
|
-
var findFont = function (fonts, requiredFonts, defaultFont) {
|
|
76363
|
-
for (var i = 0; i < requiredFonts.length; i++) {
|
|
76364
|
-
var requiredFont = requiredFonts[i].toLowerCase();
|
|
76365
|
-
|
|
76366
|
-
for (var font in fonts) {
|
|
76367
|
-
if (font.toLowerCase() === requiredFont) {
|
|
76368
|
-
return font;
|
|
76369
|
-
}
|
|
76370
|
-
}
|
|
76371
|
-
}
|
|
76372
|
-
|
|
76373
|
-
return defaultFont;
|
|
76374
|
-
};
|
|
76375
|
-
|
|
76376
|
-
////////////////////////////////////////
|
|
76377
|
-
// PdfPrinter
|
|
76378
|
-
|
|
76379
|
-
/**
|
|
76380
|
-
* @class Creates an instance of a PdfPrinter which turns document definition into a pdf
|
|
76381
|
-
*
|
|
76382
|
-
* @param {Object} fontDescriptors font definition dictionary
|
|
76383
|
-
*
|
|
76384
|
-
* @example
|
|
76385
|
-
* var fontDescriptors = {
|
|
76386
|
-
* Roboto: {
|
|
76387
|
-
* normal: 'fonts/Roboto-Regular.ttf',
|
|
76388
|
-
* bold: 'fonts/Roboto-Medium.ttf',
|
|
76389
|
-
* italics: 'fonts/Roboto-Italic.ttf',
|
|
76390
|
-
* bolditalics: 'fonts/Roboto-MediumItalic.ttf'
|
|
76391
|
-
* }
|
|
76392
|
-
* };
|
|
76393
|
-
*
|
|
76394
|
-
* var printer = new PdfPrinter(fontDescriptors);
|
|
76395
|
-
*/
|
|
76396
|
-
function PdfPrinter(fontDescriptors) {
|
|
76397
|
-
this.fontDescriptors = fontDescriptors;
|
|
76398
|
-
}
|
|
76399
|
-
|
|
76400
|
-
/**
|
|
76401
|
-
* Executes layout engine for the specified document and renders it into a pdfkit document
|
|
76402
|
-
* ready to be saved.
|
|
76403
|
-
*
|
|
76404
|
-
* @param {Object} docDefinition document definition
|
|
76405
|
-
* @param {Object} docDefinition.content an array describing the pdf structure (for more information take a look at the examples in the /examples folder)
|
|
76406
|
-
* @param {Object} [docDefinition.defaultStyle] default (implicit) style definition
|
|
76407
|
-
* @param {Object} [docDefinition.styles] dictionary defining all styles which can be used in the document
|
|
76408
|
-
* @param {Object} [docDefinition.pageSize] page size (pdfkit units, A4 dimensions by default)
|
|
76409
|
-
* @param {Number} docDefinition.pageSize.width width
|
|
76410
|
-
* @param {Number} docDefinition.pageSize.height height
|
|
76411
|
-
* @param {Object} [docDefinition.pageMargins] page margins (pdfkit units)
|
|
76412
|
-
* @param {Number} docDefinition.maxPagesNumber maximum number of pages to render
|
|
76413
|
-
*
|
|
76414
|
-
* @example
|
|
76415
|
-
*
|
|
76416
|
-
* var docDefinition = {
|
|
76417
|
-
* info: {
|
|
76418
|
-
* title: 'awesome Document',
|
|
76419
|
-
* author: 'john doe',
|
|
76420
|
-
* subject: 'subject of document',
|
|
76421
|
-
* keywords: 'keywords for document',
|
|
76422
|
-
* },
|
|
76423
|
-
* content: [
|
|
76424
|
-
* 'First paragraph',
|
|
76425
|
-
* 'Second paragraph, this time a little bit longer',
|
|
76426
|
-
* { text: 'Third paragraph, slightly bigger font size', fontSize: 20 },
|
|
76427
|
-
* { text: 'Another paragraph using a named style', style: 'header' },
|
|
76428
|
-
* { text: ['playing with ', 'inlines' ] },
|
|
76429
|
-
* { text: ['and ', { text: 'restyling ', bold: true }, 'them'] },
|
|
76430
|
-
* ],
|
|
76431
|
-
* styles: {
|
|
76432
|
-
* header: { fontSize: 30, bold: true }
|
|
76433
|
-
* },
|
|
76434
|
-
* patterns: {
|
|
76435
|
-
* stripe45d: {
|
|
76436
|
-
* boundingBox: [1, 1, 4, 4],
|
|
76437
|
-
* xStep: 3,
|
|
76438
|
-
* yStep: 3,
|
|
76439
|
-
* pattern: '1 w 0 1 m 4 5 l s 2 0 m 5 3 l s'
|
|
76440
|
-
* }
|
|
76441
|
-
* }
|
|
76442
|
-
* };
|
|
76443
|
-
*
|
|
76444
|
-
* var pdfKitDoc = printer.createPdfKitDocument(docDefinition);
|
|
76445
|
-
*
|
|
76446
|
-
* pdfKitDoc.pipe(fs.createWriteStream('sample.pdf'));
|
|
76447
|
-
* pdfKitDoc.end();
|
|
76448
|
-
*
|
|
76449
|
-
* @return {Object} a pdfKit document object which can be saved or encode to data-url
|
|
76450
|
-
*/
|
|
76451
|
-
PdfPrinter.prototype.createPdfKitDocument = function (docDefinition, options) {
|
|
76452
|
-
options = options || {};
|
|
76453
|
-
|
|
76454
|
-
docDefinition.version = docDefinition.version || '1.3';
|
|
76455
|
-
docDefinition.compress = isBoolean(docDefinition.compress) ? docDefinition.compress : true;
|
|
76456
|
-
docDefinition.images = docDefinition.images || {};
|
|
76457
|
-
docDefinition.pageMargins = ((docDefinition.pageMargins !== undefined) && (docDefinition.pageMargins !== null)) ? docDefinition.pageMargins : 40;
|
|
76458
|
-
|
|
76459
|
-
var pageSize = fixPageSize(docDefinition.pageSize, docDefinition.pageOrientation);
|
|
76460
|
-
|
|
76461
|
-
var pdfOptions = {
|
|
76462
|
-
size: [pageSize.width, pageSize.height],
|
|
76463
|
-
pdfVersion: docDefinition.version,
|
|
76464
|
-
compress: docDefinition.compress,
|
|
76465
|
-
userPassword: docDefinition.userPassword,
|
|
76466
|
-
ownerPassword: docDefinition.ownerPassword,
|
|
76467
|
-
permissions: docDefinition.permissions,
|
|
76468
|
-
fontLayoutCache: isBoolean(options.fontLayoutCache) ? options.fontLayoutCache : true,
|
|
76469
|
-
bufferPages: options.bufferPages || false,
|
|
76470
|
-
autoFirstPage: false,
|
|
76471
|
-
info: createMetadata(docDefinition),
|
|
76472
|
-
font: null
|
|
76473
|
-
};
|
|
76474
|
-
|
|
76475
|
-
this.pdfKitDoc = PdfKitEngine.createPdfDocument(pdfOptions);
|
|
76476
|
-
|
|
76477
|
-
this.fontProvider = new FontProvider(this.fontDescriptors, this.pdfKitDoc);
|
|
76478
|
-
|
|
76479
|
-
var builder = new LayoutBuilder(pageSize, fixPageMargins(docDefinition.pageMargins), new ImageMeasure(this.pdfKitDoc, docDefinition.images), new SVGMeasure());
|
|
76480
|
-
|
|
76481
|
-
registerDefaultTableLayouts(builder);
|
|
76482
|
-
if (options.tableLayouts) {
|
|
76483
|
-
builder.registerTableLayouts(options.tableLayouts);
|
|
76484
|
-
}
|
|
76485
|
-
|
|
76486
|
-
var pages = builder.layoutDocument(docDefinition.content, this.fontProvider, docDefinition.styles || {}, docDefinition.defaultStyle || {
|
|
76487
|
-
fontSize: 12,
|
|
76488
|
-
font: 'Roboto'
|
|
76489
|
-
}, docDefinition.background, docDefinition.header, docDefinition.footer, docDefinition.images, docDefinition.watermark, docDefinition.pageBreakBefore);
|
|
76490
|
-
var maxNumberPages = docDefinition.maxPagesNumber || -1;
|
|
76491
|
-
if (isNumber(maxNumberPages) && maxNumberPages > -1) {
|
|
76492
|
-
pages = pages.slice(0, maxNumberPages);
|
|
76493
|
-
}
|
|
76494
|
-
|
|
76495
|
-
// if pageSize.height is set to Infinity, calculate the actual height of the page that
|
|
76496
|
-
// was laid out using the height of each of the items in the page.
|
|
76497
|
-
if (pageSize.height === Infinity) {
|
|
76498
|
-
var pageHeight = calculatePageHeight(pages, docDefinition.pageMargins);
|
|
76499
|
-
this.pdfKitDoc.options.size = [pageSize.width, pageHeight];
|
|
76500
|
-
}
|
|
76501
|
-
|
|
76502
|
-
var patterns = createPatterns(docDefinition.patterns || {}, this.pdfKitDoc);
|
|
76503
|
-
|
|
76504
|
-
renderPages(pages, this.fontProvider, this.pdfKitDoc, patterns, options.progressCallback);
|
|
76505
|
-
|
|
76506
|
-
if (options.autoPrint) {
|
|
76507
|
-
var printActionRef = this.pdfKitDoc.ref({
|
|
76508
|
-
Type: 'Action',
|
|
76509
|
-
S: 'Named',
|
|
76510
|
-
N: 'Print'
|
|
76511
|
-
});
|
|
76512
|
-
this.pdfKitDoc._root.data.OpenAction = printActionRef;
|
|
76513
|
-
printActionRef.end();
|
|
76514
|
-
}
|
|
76515
|
-
return this.pdfKitDoc;
|
|
76516
|
-
};
|
|
76517
|
-
|
|
76518
|
-
function createMetadata(docDefinition) {
|
|
76519
|
-
// PDF standard has these properties reserved: Title, Author, Subject, Keywords,
|
|
76520
|
-
// Creator, Producer, CreationDate, ModDate, Trapped.
|
|
76521
|
-
// To keep the pdfmake api consistent, the info field are defined lowercase.
|
|
76522
|
-
// Custom properties don't contain a space.
|
|
76523
|
-
function standardizePropertyKey(key) {
|
|
76524
|
-
var standardProperties = ['Title', 'Author', 'Subject', 'Keywords',
|
|
76525
|
-
'Creator', 'Producer', 'CreationDate', 'ModDate', 'Trapped'];
|
|
76526
|
-
var standardizedKey = key.charAt(0).toUpperCase() + key.slice(1);
|
|
76527
|
-
if (standardProperties.indexOf(standardizedKey) !== -1) {
|
|
76528
|
-
return standardizedKey;
|
|
76529
|
-
}
|
|
76530
|
-
|
|
76531
|
-
return key.replace(/\s+/g, '');
|
|
76532
|
-
}
|
|
76533
|
-
|
|
76534
|
-
var info = {
|
|
76535
|
-
Producer: 'pdfmake',
|
|
76536
|
-
Creator: 'pdfmake'
|
|
76537
|
-
};
|
|
76538
|
-
|
|
76539
|
-
if (docDefinition.info) {
|
|
76540
|
-
for (var key in docDefinition.info) {
|
|
76541
|
-
var value = docDefinition.info[key];
|
|
76542
|
-
if (value) {
|
|
76543
|
-
key = standardizePropertyKey(key);
|
|
76544
|
-
info[key] = value;
|
|
76545
|
-
}
|
|
76546
|
-
}
|
|
76547
|
-
}
|
|
76548
|
-
return info;
|
|
76549
|
-
}
|
|
76550
|
-
|
|
76551
|
-
function calculatePageHeight(pages, margins) {
|
|
76552
|
-
function getItemHeight(item) {
|
|
76553
|
-
if (isFunction(item.item.getHeight)) {
|
|
76554
|
-
return item.item.getHeight();
|
|
76555
|
-
} else if (item.item._height) {
|
|
76556
|
-
return item.item._height;
|
|
76557
|
-
} else if (item.type === 'vector') {
|
|
76558
|
-
return item.item.y1 > item.item.y2 ? item.item.y1 : item.item.y2;
|
|
76559
|
-
} else {
|
|
76560
|
-
// TODO: add support for next item types
|
|
76561
|
-
return 0;
|
|
76562
|
-
}
|
|
76563
|
-
}
|
|
76564
|
-
|
|
76565
|
-
function getBottomPosition(item) {
|
|
76566
|
-
var top = item.item.y || 0;
|
|
76567
|
-
var height = getItemHeight(item);
|
|
76568
|
-
return top + height;
|
|
76569
|
-
}
|
|
76570
|
-
|
|
76571
|
-
var fixedMargins = fixPageMargins(margins || 40);
|
|
76572
|
-
var height = fixedMargins.top;
|
|
76573
|
-
|
|
76574
|
-
pages.forEach(function (page) {
|
|
76575
|
-
page.items.forEach(function (item) {
|
|
76576
|
-
var bottomPosition = getBottomPosition(item);
|
|
76577
|
-
if (bottomPosition > height) {
|
|
76578
|
-
height = bottomPosition;
|
|
76579
|
-
}
|
|
76580
|
-
});
|
|
76581
|
-
});
|
|
76582
|
-
|
|
76583
|
-
height += fixedMargins.bottom;
|
|
76584
|
-
|
|
76585
|
-
return height;
|
|
76586
|
-
}
|
|
76587
|
-
|
|
76588
|
-
function fixPageSize(pageSize, pageOrientation) {
|
|
76589
|
-
function isNeedSwapPageSizes(pageOrientation) {
|
|
76590
|
-
if (isString(pageOrientation)) {
|
|
76591
|
-
pageOrientation = pageOrientation.toLowerCase();
|
|
76592
|
-
return ((pageOrientation === 'portrait') && (size.width > size.height)) ||
|
|
76593
|
-
((pageOrientation === 'landscape') && (size.width < size.height));
|
|
76594
|
-
}
|
|
76595
|
-
return false;
|
|
76596
|
-
}
|
|
76597
|
-
|
|
76598
|
-
// if pageSize.height is set to auto, set the height to infinity so there are no page breaks.
|
|
76599
|
-
if (pageSize && pageSize.height === 'auto') {
|
|
76600
|
-
pageSize.height = Infinity;
|
|
76601
|
-
}
|
|
76602
|
-
|
|
76603
|
-
var size = pageSize2widthAndHeight(pageSize || 'A4');
|
|
76604
|
-
if (isNeedSwapPageSizes(pageOrientation)) { // swap page sizes
|
|
76605
|
-
size = { width: size.height, height: size.width };
|
|
76606
|
-
}
|
|
76607
|
-
size.orientation = size.width > size.height ? 'landscape' : 'portrait';
|
|
76608
|
-
return size;
|
|
76609
|
-
}
|
|
76610
|
-
|
|
76611
|
-
function fixPageMargins(margin) {
|
|
76612
|
-
if (isNumber(margin)) {
|
|
76613
|
-
margin = { left: margin, right: margin, top: margin, bottom: margin };
|
|
76614
|
-
} else if (isArray(margin)) {
|
|
76615
|
-
if (margin.length === 2) {
|
|
76616
|
-
margin = { left: margin[0], top: margin[1], right: margin[0], bottom: margin[1] };
|
|
76617
|
-
} else if (margin.length === 4) {
|
|
76618
|
-
margin = { left: margin[0], top: margin[1], right: margin[2], bottom: margin[3] };
|
|
76619
|
-
} else {
|
|
76620
|
-
throw 'Invalid pageMargins definition';
|
|
76621
|
-
}
|
|
76622
|
-
}
|
|
76623
|
-
|
|
76624
|
-
return margin;
|
|
76625
|
-
}
|
|
76626
|
-
|
|
76627
|
-
function registerDefaultTableLayouts(layoutBuilder) {
|
|
76628
|
-
layoutBuilder.registerTableLayouts({
|
|
76629
|
-
noBorders: {
|
|
76630
|
-
hLineWidth: function (i) {
|
|
76631
|
-
return 0;
|
|
76632
|
-
},
|
|
76633
|
-
vLineWidth: function (i) {
|
|
76634
|
-
return 0;
|
|
76635
|
-
},
|
|
76636
|
-
paddingLeft: function (i) {
|
|
76637
|
-
return i && 4 || 0;
|
|
76638
|
-
},
|
|
76639
|
-
paddingRight: function (i, node) {
|
|
76640
|
-
return (i < node.table.widths.length - 1) ? 4 : 0;
|
|
76641
|
-
}
|
|
76642
|
-
},
|
|
76643
|
-
headerLineOnly: {
|
|
76644
|
-
hLineWidth: function (i, node) {
|
|
76645
|
-
if (i === 0 || i === node.table.body.length) {
|
|
76646
|
-
return 0;
|
|
76647
|
-
}
|
|
76648
|
-
return (i === node.table.headerRows) ? 2 : 0;
|
|
76649
|
-
},
|
|
76650
|
-
vLineWidth: function (i) {
|
|
76651
|
-
return 0;
|
|
76652
|
-
},
|
|
76653
|
-
paddingLeft: function (i) {
|
|
76654
|
-
return i === 0 ? 0 : 8;
|
|
76655
|
-
},
|
|
76656
|
-
paddingRight: function (i, node) {
|
|
76657
|
-
return (i === node.table.widths.length - 1) ? 0 : 8;
|
|
76658
|
-
}
|
|
76659
|
-
},
|
|
76660
|
-
lightHorizontalLines: {
|
|
76661
|
-
hLineWidth: function (i, node) {
|
|
76662
|
-
if (i === 0 || i === node.table.body.length) {
|
|
76663
|
-
return 0;
|
|
76664
|
-
}
|
|
76665
|
-
return (i === node.table.headerRows) ? 2 : 1;
|
|
76666
|
-
},
|
|
76667
|
-
vLineWidth: function (i) {
|
|
76668
|
-
return 0;
|
|
76669
|
-
},
|
|
76670
|
-
hLineColor: function (i) {
|
|
76671
|
-
return i === 1 ? 'black' : '#aaa';
|
|
76672
|
-
},
|
|
76673
|
-
paddingLeft: function (i) {
|
|
76674
|
-
return i === 0 ? 0 : 8;
|
|
76675
|
-
},
|
|
76676
|
-
paddingRight: function (i, node) {
|
|
76677
|
-
return (i === node.table.widths.length - 1) ? 0 : 8;
|
|
76678
|
-
}
|
|
76679
|
-
}
|
|
76680
|
-
});
|
|
76681
|
-
}
|
|
76682
|
-
|
|
76683
|
-
function pageSize2widthAndHeight(pageSize) {
|
|
76684
|
-
if (isString(pageSize)) {
|
|
76685
|
-
var size = sizes[pageSize.toUpperCase()];
|
|
76686
|
-
if (!size) {
|
|
76687
|
-
throw 'Page size ' + pageSize + ' not recognized';
|
|
76688
|
-
}
|
|
76689
|
-
return { width: size[0], height: size[1] };
|
|
76690
|
-
}
|
|
76691
|
-
|
|
76692
|
-
return pageSize;
|
|
76693
|
-
}
|
|
76694
|
-
|
|
76695
|
-
function updatePageOrientationInOptions(currentPage, pdfKitDoc) {
|
|
76696
|
-
var previousPageOrientation = pdfKitDoc.options.size[0] > pdfKitDoc.options.size[1] ? 'landscape' : 'portrait';
|
|
76697
|
-
|
|
76698
|
-
if (currentPage.pageSize.orientation !== previousPageOrientation) {
|
|
76699
|
-
var width = pdfKitDoc.options.size[0];
|
|
76700
|
-
var height = pdfKitDoc.options.size[1];
|
|
76701
|
-
pdfKitDoc.options.size = [height, width];
|
|
76702
|
-
}
|
|
76703
|
-
}
|
|
76704
|
-
|
|
76705
|
-
function renderPages(pages, fontProvider, pdfKitDoc, patterns, progressCallback) {
|
|
76706
|
-
pdfKitDoc._pdfMakePages = pages;
|
|
76707
|
-
pdfKitDoc.addPage();
|
|
76708
|
-
|
|
76709
|
-
var totalItems = 0;
|
|
76710
|
-
if (progressCallback) {
|
|
76711
|
-
pages.forEach(function (page) {
|
|
76712
|
-
totalItems += page.items.length;
|
|
76713
|
-
});
|
|
76714
|
-
}
|
|
76715
|
-
|
|
76716
|
-
var renderedItems = 0;
|
|
76717
|
-
progressCallback = progressCallback || function () {
|
|
76718
|
-
};
|
|
76719
|
-
|
|
76720
|
-
for (var i = 0; i < pages.length; i++) {
|
|
76721
|
-
if (i > 0) {
|
|
76722
|
-
updatePageOrientationInOptions(pages[i], pdfKitDoc);
|
|
76723
|
-
pdfKitDoc.addPage(pdfKitDoc.options);
|
|
76724
|
-
}
|
|
76725
|
-
|
|
76726
|
-
var page = pages[i];
|
|
76727
|
-
for (var ii = 0, il = page.items.length; ii < il; ii++) {
|
|
76728
|
-
var item = page.items[ii];
|
|
76729
|
-
switch (item.type) {
|
|
76730
|
-
case 'vector':
|
|
76731
|
-
renderVector(item.item, patterns, pdfKitDoc);
|
|
76732
|
-
break;
|
|
76733
|
-
case 'line':
|
|
76734
|
-
renderLine(item.item, item.item.x, item.item.y, patterns, pdfKitDoc);
|
|
76735
|
-
break;
|
|
76736
|
-
case 'image':
|
|
76737
|
-
renderImage(item.item, item.item.x, item.item.y, pdfKitDoc);
|
|
76738
|
-
break;
|
|
76739
|
-
case 'svg':
|
|
76740
|
-
renderSVG(item.item, item.item.x, item.item.y, pdfKitDoc, fontProvider);
|
|
76741
|
-
break;
|
|
76742
|
-
case 'beginClip':
|
|
76743
|
-
beginClip(item.item, pdfKitDoc);
|
|
76744
|
-
break;
|
|
76745
|
-
case 'endClip':
|
|
76746
|
-
endClip(pdfKitDoc);
|
|
76747
|
-
break;
|
|
76748
|
-
}
|
|
76749
|
-
renderedItems++;
|
|
76750
|
-
progressCallback(renderedItems / totalItems);
|
|
76751
|
-
}
|
|
76752
|
-
if (page.watermark) {
|
|
76753
|
-
renderWatermark(page, pdfKitDoc);
|
|
76754
|
-
}
|
|
76755
|
-
}
|
|
76756
|
-
}
|
|
76757
|
-
|
|
76758
|
-
/**
|
|
76759
|
-
* Shift the "y" height of the text baseline up or down (superscript or subscript,
|
|
76760
|
-
* respectively). The exact shift can / should be changed according to standard
|
|
76761
|
-
* conventions.
|
|
76762
|
-
*
|
|
76763
|
-
* @param {number} y
|
|
76764
|
-
* @param {any} inline
|
|
76765
|
-
*/
|
|
76766
|
-
function offsetText(y, inline) {
|
|
76767
|
-
var newY = y;
|
|
76768
|
-
if (inline.sup) {
|
|
76769
|
-
newY -= inline.fontSize * 0.75;
|
|
76770
|
-
}
|
|
76771
|
-
if (inline.sub) {
|
|
76772
|
-
newY += inline.fontSize * 0.35;
|
|
76773
|
-
}
|
|
76774
|
-
return newY;
|
|
76775
|
-
}
|
|
76776
|
-
|
|
76777
|
-
function renderLine(line, x, y, patterns, pdfKitDoc) {
|
|
76778
|
-
function preparePageNodeRefLine(_pageNodeRef, inline) {
|
|
76779
|
-
var newWidth;
|
|
76780
|
-
var diffWidth;
|
|
76781
|
-
var textTools = new TextTools(null);
|
|
76782
|
-
|
|
76783
|
-
if (isUndefined(_pageNodeRef.positions)) {
|
|
76784
|
-
throw 'Page reference id not found';
|
|
76785
|
-
}
|
|
76786
|
-
|
|
76787
|
-
var pageNumber = _pageNodeRef.positions[0].pageNumber.toString();
|
|
76788
|
-
|
|
76789
|
-
inline.text = pageNumber;
|
|
76790
|
-
newWidth = textTools.widthOfString(inline.text, inline.font, inline.fontSize, inline.characterSpacing, inline.fontFeatures);
|
|
76791
|
-
diffWidth = inline.width - newWidth;
|
|
76792
|
-
inline.width = newWidth;
|
|
76793
|
-
|
|
76794
|
-
switch (inline.alignment) {
|
|
76795
|
-
case 'right':
|
|
76796
|
-
inline.x += diffWidth;
|
|
76797
|
-
break;
|
|
76798
|
-
case 'center':
|
|
76799
|
-
inline.x += diffWidth / 2;
|
|
76800
|
-
break;
|
|
76801
|
-
}
|
|
76802
|
-
}
|
|
76803
|
-
|
|
76804
|
-
if (line._pageNodeRef) {
|
|
76805
|
-
preparePageNodeRefLine(line._pageNodeRef, line.inlines[0]);
|
|
76806
|
-
}
|
|
76807
|
-
|
|
76808
|
-
x = x || 0;
|
|
76809
|
-
y = y || 0;
|
|
76810
|
-
|
|
76811
|
-
var lineHeight = line.getHeight();
|
|
76812
|
-
var ascenderHeight = line.getAscenderHeight();
|
|
76813
|
-
var descent = lineHeight - ascenderHeight;
|
|
76814
|
-
|
|
76815
|
-
textDecorator.drawBackground(line, x, y, patterns, pdfKitDoc);
|
|
76816
|
-
|
|
76817
|
-
//TODO: line.optimizeInlines();
|
|
76818
|
-
for (var i = 0, l = line.inlines.length; i < l; i++) {
|
|
76819
|
-
var inline = line.inlines[i];
|
|
76820
|
-
var shiftToBaseline = lineHeight - ((inline.font.ascender / 1000) * inline.fontSize) - descent;
|
|
76821
|
-
|
|
76822
|
-
if (inline._pageNodeRef) {
|
|
76823
|
-
preparePageNodeRefLine(inline._pageNodeRef, inline);
|
|
76824
|
-
}
|
|
76825
|
-
|
|
76826
|
-
var options = {
|
|
76827
|
-
lineBreak: false,
|
|
76828
|
-
textWidth: inline.width,
|
|
76829
|
-
characterSpacing: inline.characterSpacing,
|
|
76830
|
-
wordCount: 1,
|
|
76831
|
-
link: inline.link
|
|
76832
|
-
};
|
|
76833
|
-
|
|
76834
|
-
if (inline.linkToDestination) {
|
|
76835
|
-
options.goTo = inline.linkToDestination;
|
|
76836
|
-
}
|
|
76837
|
-
|
|
76838
|
-
if (line.id && i === 0) {
|
|
76839
|
-
options.destination = line.id;
|
|
76840
|
-
}
|
|
76841
|
-
|
|
76842
|
-
if (inline.fontFeatures) {
|
|
76843
|
-
options.features = inline.fontFeatures;
|
|
76844
|
-
}
|
|
76845
|
-
|
|
76846
|
-
var opacity = isNumber(inline.opacity) ? inline.opacity : 1;
|
|
76847
|
-
pdfKitDoc.opacity(opacity);
|
|
76848
|
-
pdfKitDoc.fill(inline.color || 'black');
|
|
76849
|
-
|
|
76850
|
-
pdfKitDoc._font = inline.font;
|
|
76851
|
-
pdfKitDoc.fontSize(inline.fontSize);
|
|
76852
|
-
|
|
76853
|
-
var shiftedY = offsetText(y + shiftToBaseline, inline);
|
|
76854
|
-
pdfKitDoc.text(inline.text, x + inline.x, shiftedY, options);
|
|
76855
|
-
|
|
76856
|
-
if (inline.linkToPage) {
|
|
76857
|
-
var _ref = pdfKitDoc.ref({ Type: 'Action', S: 'GoTo', D: [inline.linkToPage, 0, 0] }).end();
|
|
76858
|
-
pdfKitDoc.annotate(x + inline.x, shiftedY, inline.width, inline.height, {
|
|
76859
|
-
Subtype: 'Link',
|
|
76860
|
-
Dest: [inline.linkToPage - 1, 'XYZ', null, null, null]
|
|
76861
|
-
});
|
|
76862
|
-
}
|
|
76863
|
-
|
|
76864
|
-
}
|
|
76865
|
-
// Decorations won't draw correctly for superscript
|
|
76866
|
-
textDecorator.drawDecorations(line, x, y, pdfKitDoc);
|
|
76867
|
-
}
|
|
76868
|
-
|
|
76869
|
-
function renderWatermark(page, pdfKitDoc) {
|
|
76870
|
-
var watermark = page.watermark;
|
|
76871
|
-
|
|
76872
|
-
pdfKitDoc.fill(watermark.color);
|
|
76873
|
-
pdfKitDoc.opacity(watermark.opacity);
|
|
76874
|
-
|
|
76875
|
-
pdfKitDoc.save();
|
|
76876
|
-
|
|
76877
|
-
pdfKitDoc.rotate(watermark.angle, { origin: [pdfKitDoc.page.width / 2, pdfKitDoc.page.height / 2] });
|
|
76878
|
-
|
|
76879
|
-
var x = pdfKitDoc.page.width / 2 - watermark._size.size.width / 2;
|
|
76880
|
-
var y = pdfKitDoc.page.height / 2 - watermark._size.size.height / 2;
|
|
76881
|
-
|
|
76882
|
-
pdfKitDoc._font = watermark.font;
|
|
76883
|
-
pdfKitDoc.fontSize(watermark.fontSize);
|
|
76884
|
-
pdfKitDoc.text(watermark.text, x, y, { lineBreak: false });
|
|
76885
|
-
|
|
76886
|
-
pdfKitDoc.restore();
|
|
76887
|
-
}
|
|
76888
|
-
|
|
76889
|
-
function renderVector(vector, patterns, pdfKitDoc) {
|
|
76890
|
-
//TODO: pdf optimization (there's no need to write all properties everytime)
|
|
76891
|
-
pdfKitDoc.lineWidth(vector.lineWidth || 1);
|
|
76892
|
-
if (vector.dash) {
|
|
76893
|
-
pdfKitDoc.dash(vector.dash.length, { space: vector.dash.space || vector.dash.length, phase: vector.dash.phase || 0 });
|
|
76894
|
-
} else {
|
|
76895
|
-
pdfKitDoc.undash();
|
|
76896
|
-
}
|
|
76897
|
-
pdfKitDoc.lineJoin(vector.lineJoin || 'miter');
|
|
76898
|
-
pdfKitDoc.lineCap(vector.lineCap || 'butt');
|
|
76899
|
-
|
|
76900
|
-
//TODO: clipping
|
|
76901
|
-
|
|
76902
|
-
var gradient = null;
|
|
76903
|
-
|
|
76904
|
-
switch (vector.type) {
|
|
76905
|
-
case 'ellipse':
|
|
76906
|
-
pdfKitDoc.ellipse(vector.x, vector.y, vector.r1, vector.r2);
|
|
76907
|
-
|
|
76908
|
-
if (vector.linearGradient) {
|
|
76909
|
-
gradient = pdfKitDoc.linearGradient(vector.x - vector.r1, vector.y, vector.x + vector.r1, vector.y);
|
|
76910
|
-
}
|
|
76911
|
-
break;
|
|
76912
|
-
case 'rect':
|
|
76913
|
-
if (vector.r) {
|
|
76914
|
-
pdfKitDoc.roundedRect(vector.x, vector.y, vector.w, vector.h, vector.r);
|
|
76915
|
-
} else {
|
|
76916
|
-
pdfKitDoc.rect(vector.x, vector.y, vector.w, vector.h);
|
|
76917
|
-
}
|
|
76918
|
-
|
|
76919
|
-
if (vector.linearGradient) {
|
|
76920
|
-
gradient = pdfKitDoc.linearGradient(vector.x, vector.y, vector.x + vector.w, vector.y);
|
|
76921
|
-
}
|
|
76922
|
-
break;
|
|
76923
|
-
case 'line':
|
|
76924
|
-
pdfKitDoc.moveTo(vector.x1, vector.y1);
|
|
76925
|
-
pdfKitDoc.lineTo(vector.x2, vector.y2);
|
|
76926
|
-
break;
|
|
76927
|
-
case 'polyline':
|
|
76928
|
-
if (vector.points.length === 0) {
|
|
76929
|
-
break;
|
|
76930
|
-
}
|
|
76931
|
-
|
|
76932
|
-
pdfKitDoc.moveTo(vector.points[0].x, vector.points[0].y);
|
|
76933
|
-
for (var i = 1, l = vector.points.length; i < l; i++) {
|
|
76934
|
-
pdfKitDoc.lineTo(vector.points[i].x, vector.points[i].y);
|
|
76935
|
-
}
|
|
76936
|
-
|
|
76937
|
-
if (vector.points.length > 1) {
|
|
76938
|
-
var p1 = vector.points[0];
|
|
76939
|
-
var pn = vector.points[vector.points.length - 1];
|
|
76940
|
-
|
|
76941
|
-
if (vector.closePath || p1.x === pn.x && p1.y === pn.y) {
|
|
76942
|
-
pdfKitDoc.closePath();
|
|
76943
|
-
}
|
|
76944
|
-
}
|
|
76945
|
-
break;
|
|
76946
|
-
case 'path':
|
|
76947
|
-
pdfKitDoc.path(vector.d);
|
|
76948
|
-
break;
|
|
76949
|
-
}
|
|
76950
|
-
|
|
76951
|
-
if (vector.linearGradient && gradient) {
|
|
76952
|
-
var step = 1 / (vector.linearGradient.length - 1);
|
|
76953
|
-
|
|
76954
|
-
for (var i = 0; i < vector.linearGradient.length; i++) {
|
|
76955
|
-
gradient.stop(i * step, vector.linearGradient[i]);
|
|
76956
|
-
}
|
|
76957
|
-
|
|
76958
|
-
vector.color = gradient;
|
|
76959
|
-
}
|
|
76960
|
-
|
|
76961
|
-
if (isPattern(vector.color)) {
|
|
76962
|
-
vector.color = getPattern(vector.color, patterns);
|
|
76963
|
-
}
|
|
76964
|
-
|
|
76965
|
-
var fillOpacity = isNumber(vector.fillOpacity) ? vector.fillOpacity : 1;
|
|
76966
|
-
var strokeOpacity = isNumber(vector.strokeOpacity) ? vector.strokeOpacity : 1;
|
|
76967
|
-
|
|
76968
|
-
if (vector.color && vector.lineColor) {
|
|
76969
|
-
pdfKitDoc.fillColor(vector.color, fillOpacity);
|
|
76970
|
-
pdfKitDoc.strokeColor(vector.lineColor, strokeOpacity);
|
|
76971
|
-
pdfKitDoc.fillAndStroke();
|
|
76972
|
-
} else if (vector.color) {
|
|
76973
|
-
pdfKitDoc.fillColor(vector.color, fillOpacity);
|
|
76974
|
-
pdfKitDoc.fill();
|
|
76975
|
-
} else {
|
|
76976
|
-
pdfKitDoc.strokeColor(vector.lineColor || 'black', strokeOpacity);
|
|
76977
|
-
pdfKitDoc.stroke();
|
|
76978
|
-
}
|
|
76979
|
-
}
|
|
76980
|
-
|
|
76981
|
-
function renderImage(image, x, y, pdfKitDoc) {
|
|
76982
|
-
var opacity = isNumber(image.opacity) ? image.opacity : 1;
|
|
76983
|
-
pdfKitDoc.opacity(opacity);
|
|
76984
|
-
if (image.cover) {
|
|
76985
|
-
var align = image.cover.align || 'center';
|
|
76986
|
-
var valign = image.cover.valign || 'center';
|
|
76987
|
-
var width = image.cover.width ? image.cover.width : image.width;
|
|
76988
|
-
var height = image.cover.height ? image.cover.height : image.height;
|
|
76989
|
-
pdfKitDoc.save();
|
|
76990
|
-
pdfKitDoc.rect(image.x, image.y, width, height).clip();
|
|
76991
|
-
pdfKitDoc.image(image.image, image.x, image.y, { cover: [width, height], align: align, valign: valign });
|
|
76992
|
-
pdfKitDoc.restore();
|
|
76993
|
-
} else {
|
|
76994
|
-
pdfKitDoc.image(image.image, image.x, image.y, { width: image._width, height: image._height });
|
|
76995
|
-
}
|
|
76996
|
-
if (image.link) {
|
|
76997
|
-
pdfKitDoc.link(image.x, image.y, image._width, image._height, image.link);
|
|
76998
|
-
}
|
|
76999
|
-
if (image.linkToPage) {
|
|
77000
|
-
pdfKitDoc.ref({ Type: 'Action', S: 'GoTo', D: [image.linkToPage, 0, 0] }).end();
|
|
77001
|
-
pdfKitDoc.annotate(image.x, image.y, image._width, image._height, { Subtype: 'Link', Dest: [image.linkToPage - 1, 'XYZ', null, null, null] });
|
|
77002
|
-
}
|
|
77003
|
-
if (image.linkToDestination) {
|
|
77004
|
-
pdfKitDoc.goTo(image.x, image.y, image._width, image._height, image.linkToDestination);
|
|
77005
|
-
}
|
|
77006
|
-
}
|
|
77007
|
-
|
|
77008
|
-
function renderSVG(svg, x, y, pdfKitDoc, fontProvider) {
|
|
77009
|
-
var options = Object.assign({ width: svg._width, height: svg._height, assumePt: true }, svg.options);
|
|
77010
|
-
options.fontCallback = function (family, bold, italic) {
|
|
77011
|
-
var fontsFamily = family.split(',').map(function (f) { return f.trim().replace(/('|")/g, ''); });
|
|
77012
|
-
var font = findFont(fontProvider.fonts, fontsFamily, svg.font || 'Roboto');
|
|
77013
|
-
|
|
77014
|
-
var fontFile = fontProvider.getFontFile(font, bold, italic);
|
|
77015
|
-
if (fontFile === null) {
|
|
77016
|
-
var type = fontProvider.getFontType(bold, italic);
|
|
77017
|
-
throw new Error('Font \'' + font + '\' in style \'' + type + '\' is not defined in the font section of the document definition.');
|
|
77018
|
-
}
|
|
77019
|
-
|
|
77020
|
-
return fontFile;
|
|
77021
|
-
};
|
|
77022
|
-
|
|
77023
|
-
SVGtoPDF(pdfKitDoc, svg.svg, svg.x, svg.y, options);
|
|
77024
|
-
}
|
|
77025
|
-
|
|
77026
|
-
function beginClip(rect, pdfKitDoc) {
|
|
77027
|
-
pdfKitDoc.save();
|
|
77028
|
-
pdfKitDoc.addContent('' + rect.x + ' ' + rect.y + ' ' + rect.width + ' ' + rect.height + ' re');
|
|
77029
|
-
pdfKitDoc.clip();
|
|
77030
|
-
}
|
|
77031
|
-
|
|
77032
|
-
function endClip(pdfKitDoc) {
|
|
77033
|
-
pdfKitDoc.restore();
|
|
77034
|
-
}
|
|
77035
|
-
|
|
77036
|
-
function createPatterns(patternDefinitions, pdfKitDoc) {
|
|
77037
|
-
var patterns = {};
|
|
77038
|
-
Object.keys(patternDefinitions).forEach(function (p) {
|
|
77039
|
-
var pattern = patternDefinitions[p];
|
|
77040
|
-
patterns[p] = pdfKitDoc.pattern(pattern.boundingBox, pattern.xStep, pattern.yStep, pattern.pattern, pattern.colored);
|
|
77041
|
-
});
|
|
77042
|
-
return patterns;
|
|
77043
|
-
}
|
|
77044
|
-
|
|
77045
|
-
module.exports = PdfPrinter;
|
|
76273
|
+
/*eslint no-unused-vars: ["error", {"args": "none"}]*/
|
|
76274
|
+
|
|
76275
|
+
|
|
76276
|
+
var PdfKitEngine = __webpack_require__(6079);
|
|
76277
|
+
var FontProvider = __webpack_require__(2249);
|
|
76278
|
+
var LayoutBuilder = __webpack_require__(2678);
|
|
76279
|
+
var sizes = __webpack_require__(4762);
|
|
76280
|
+
var ImageMeasure = __webpack_require__(3090);
|
|
76281
|
+
var SVGMeasure = __webpack_require__(7601);
|
|
76282
|
+
var textDecorator = __webpack_require__(3497);
|
|
76283
|
+
var TextTools = __webpack_require__(1350);
|
|
76284
|
+
var isFunction = (__webpack_require__(6225).isFunction);
|
|
76285
|
+
var isString = (__webpack_require__(6225).isString);
|
|
76286
|
+
var isNumber = (__webpack_require__(6225).isNumber);
|
|
76287
|
+
var isBoolean = (__webpack_require__(6225).isBoolean);
|
|
76288
|
+
var isArray = (__webpack_require__(6225).isArray);
|
|
76289
|
+
var isUndefined = (__webpack_require__(6225).isUndefined);
|
|
76290
|
+
var isPattern = (__webpack_require__(6225).isPattern);
|
|
76291
|
+
var getPattern = (__webpack_require__(6225).getPattern);
|
|
76292
|
+
var SVGtoPDF = __webpack_require__(8071);
|
|
76293
|
+
|
|
76294
|
+
var findFont = function (fonts, requiredFonts, defaultFont) {
|
|
76295
|
+
for (var i = 0; i < requiredFonts.length; i++) {
|
|
76296
|
+
var requiredFont = requiredFonts[i].toLowerCase();
|
|
76297
|
+
|
|
76298
|
+
for (var font in fonts) {
|
|
76299
|
+
if (font.toLowerCase() === requiredFont) {
|
|
76300
|
+
return font;
|
|
76301
|
+
}
|
|
76302
|
+
}
|
|
76303
|
+
}
|
|
76304
|
+
|
|
76305
|
+
return defaultFont;
|
|
76306
|
+
};
|
|
76307
|
+
|
|
76308
|
+
////////////////////////////////////////
|
|
76309
|
+
// PdfPrinter
|
|
76310
|
+
|
|
76311
|
+
/**
|
|
76312
|
+
* @class Creates an instance of a PdfPrinter which turns document definition into a pdf
|
|
76313
|
+
*
|
|
76314
|
+
* @param {Object} fontDescriptors font definition dictionary
|
|
76315
|
+
*
|
|
76316
|
+
* @example
|
|
76317
|
+
* var fontDescriptors = {
|
|
76318
|
+
* Roboto: {
|
|
76319
|
+
* normal: 'fonts/Roboto-Regular.ttf',
|
|
76320
|
+
* bold: 'fonts/Roboto-Medium.ttf',
|
|
76321
|
+
* italics: 'fonts/Roboto-Italic.ttf',
|
|
76322
|
+
* bolditalics: 'fonts/Roboto-MediumItalic.ttf'
|
|
76323
|
+
* }
|
|
76324
|
+
* };
|
|
76325
|
+
*
|
|
76326
|
+
* var printer = new PdfPrinter(fontDescriptors);
|
|
76327
|
+
*/
|
|
76328
|
+
function PdfPrinter(fontDescriptors) {
|
|
76329
|
+
this.fontDescriptors = fontDescriptors;
|
|
76330
|
+
}
|
|
76331
|
+
|
|
76332
|
+
/**
|
|
76333
|
+
* Executes layout engine for the specified document and renders it into a pdfkit document
|
|
76334
|
+
* ready to be saved.
|
|
76335
|
+
*
|
|
76336
|
+
* @param {Object} docDefinition document definition
|
|
76337
|
+
* @param {Object} docDefinition.content an array describing the pdf structure (for more information take a look at the examples in the /examples folder)
|
|
76338
|
+
* @param {Object} [docDefinition.defaultStyle] default (implicit) style definition
|
|
76339
|
+
* @param {Object} [docDefinition.styles] dictionary defining all styles which can be used in the document
|
|
76340
|
+
* @param {Object} [docDefinition.pageSize] page size (pdfkit units, A4 dimensions by default)
|
|
76341
|
+
* @param {Number} docDefinition.pageSize.width width
|
|
76342
|
+
* @param {Number} docDefinition.pageSize.height height
|
|
76343
|
+
* @param {Object} [docDefinition.pageMargins] page margins (pdfkit units)
|
|
76344
|
+
* @param {Number} docDefinition.maxPagesNumber maximum number of pages to render
|
|
76345
|
+
*
|
|
76346
|
+
* @example
|
|
76347
|
+
*
|
|
76348
|
+
* var docDefinition = {
|
|
76349
|
+
* info: {
|
|
76350
|
+
* title: 'awesome Document',
|
|
76351
|
+
* author: 'john doe',
|
|
76352
|
+
* subject: 'subject of document',
|
|
76353
|
+
* keywords: 'keywords for document',
|
|
76354
|
+
* },
|
|
76355
|
+
* content: [
|
|
76356
|
+
* 'First paragraph',
|
|
76357
|
+
* 'Second paragraph, this time a little bit longer',
|
|
76358
|
+
* { text: 'Third paragraph, slightly bigger font size', fontSize: 20 },
|
|
76359
|
+
* { text: 'Another paragraph using a named style', style: 'header' },
|
|
76360
|
+
* { text: ['playing with ', 'inlines' ] },
|
|
76361
|
+
* { text: ['and ', { text: 'restyling ', bold: true }, 'them'] },
|
|
76362
|
+
* ],
|
|
76363
|
+
* styles: {
|
|
76364
|
+
* header: { fontSize: 30, bold: true }
|
|
76365
|
+
* },
|
|
76366
|
+
* patterns: {
|
|
76367
|
+
* stripe45d: {
|
|
76368
|
+
* boundingBox: [1, 1, 4, 4],
|
|
76369
|
+
* xStep: 3,
|
|
76370
|
+
* yStep: 3,
|
|
76371
|
+
* pattern: '1 w 0 1 m 4 5 l s 2 0 m 5 3 l s'
|
|
76372
|
+
* }
|
|
76373
|
+
* }
|
|
76374
|
+
* };
|
|
76375
|
+
*
|
|
76376
|
+
* var pdfKitDoc = printer.createPdfKitDocument(docDefinition);
|
|
76377
|
+
*
|
|
76378
|
+
* pdfKitDoc.pipe(fs.createWriteStream('sample.pdf'));
|
|
76379
|
+
* pdfKitDoc.end();
|
|
76380
|
+
*
|
|
76381
|
+
* @return {Object} a pdfKit document object which can be saved or encode to data-url
|
|
76382
|
+
*/
|
|
76383
|
+
PdfPrinter.prototype.createPdfKitDocument = function (docDefinition, options) {
|
|
76384
|
+
options = options || {};
|
|
76385
|
+
|
|
76386
|
+
docDefinition.version = docDefinition.version || '1.3';
|
|
76387
|
+
docDefinition.compress = isBoolean(docDefinition.compress) ? docDefinition.compress : true;
|
|
76388
|
+
docDefinition.images = docDefinition.images || {};
|
|
76389
|
+
docDefinition.pageMargins = ((docDefinition.pageMargins !== undefined) && (docDefinition.pageMargins !== null)) ? docDefinition.pageMargins : 40;
|
|
76390
|
+
|
|
76391
|
+
var pageSize = fixPageSize(docDefinition.pageSize, docDefinition.pageOrientation);
|
|
76392
|
+
|
|
76393
|
+
var pdfOptions = {
|
|
76394
|
+
size: [pageSize.width, pageSize.height],
|
|
76395
|
+
pdfVersion: docDefinition.version,
|
|
76396
|
+
compress: docDefinition.compress,
|
|
76397
|
+
userPassword: docDefinition.userPassword,
|
|
76398
|
+
ownerPassword: docDefinition.ownerPassword,
|
|
76399
|
+
permissions: docDefinition.permissions,
|
|
76400
|
+
fontLayoutCache: isBoolean(options.fontLayoutCache) ? options.fontLayoutCache : true,
|
|
76401
|
+
bufferPages: options.bufferPages || false,
|
|
76402
|
+
autoFirstPage: false,
|
|
76403
|
+
info: createMetadata(docDefinition),
|
|
76404
|
+
font: null
|
|
76405
|
+
};
|
|
76406
|
+
|
|
76407
|
+
this.pdfKitDoc = PdfKitEngine.createPdfDocument(pdfOptions);
|
|
76408
|
+
|
|
76409
|
+
this.fontProvider = new FontProvider(this.fontDescriptors, this.pdfKitDoc);
|
|
76410
|
+
|
|
76411
|
+
var builder = new LayoutBuilder(pageSize, fixPageMargins(docDefinition.pageMargins), new ImageMeasure(this.pdfKitDoc, docDefinition.images), new SVGMeasure());
|
|
76412
|
+
|
|
76413
|
+
registerDefaultTableLayouts(builder);
|
|
76414
|
+
if (options.tableLayouts) {
|
|
76415
|
+
builder.registerTableLayouts(options.tableLayouts);
|
|
76416
|
+
}
|
|
76417
|
+
|
|
76418
|
+
var pages = builder.layoutDocument(docDefinition.content, this.fontProvider, docDefinition.styles || {}, docDefinition.defaultStyle || {
|
|
76419
|
+
fontSize: 12,
|
|
76420
|
+
font: 'Roboto'
|
|
76421
|
+
}, docDefinition.background, docDefinition.header, docDefinition.footer, docDefinition.images, docDefinition.watermark, docDefinition.pageBreakBefore);
|
|
76422
|
+
var maxNumberPages = docDefinition.maxPagesNumber || -1;
|
|
76423
|
+
if (isNumber(maxNumberPages) && maxNumberPages > -1) {
|
|
76424
|
+
pages = pages.slice(0, maxNumberPages);
|
|
76425
|
+
}
|
|
76426
|
+
|
|
76427
|
+
// if pageSize.height is set to Infinity, calculate the actual height of the page that
|
|
76428
|
+
// was laid out using the height of each of the items in the page.
|
|
76429
|
+
if (pageSize.height === Infinity) {
|
|
76430
|
+
var pageHeight = calculatePageHeight(pages, docDefinition.pageMargins);
|
|
76431
|
+
this.pdfKitDoc.options.size = [pageSize.width, pageHeight];
|
|
76432
|
+
}
|
|
76433
|
+
|
|
76434
|
+
var patterns = createPatterns(docDefinition.patterns || {}, this.pdfKitDoc);
|
|
76435
|
+
|
|
76436
|
+
renderPages(pages, this.fontProvider, this.pdfKitDoc, patterns, options.progressCallback);
|
|
76437
|
+
|
|
76438
|
+
if (options.autoPrint) {
|
|
76439
|
+
var printActionRef = this.pdfKitDoc.ref({
|
|
76440
|
+
Type: 'Action',
|
|
76441
|
+
S: 'Named',
|
|
76442
|
+
N: 'Print'
|
|
76443
|
+
});
|
|
76444
|
+
this.pdfKitDoc._root.data.OpenAction = printActionRef;
|
|
76445
|
+
printActionRef.end();
|
|
76446
|
+
}
|
|
76447
|
+
return this.pdfKitDoc;
|
|
76448
|
+
};
|
|
76449
|
+
|
|
76450
|
+
function createMetadata(docDefinition) {
|
|
76451
|
+
// PDF standard has these properties reserved: Title, Author, Subject, Keywords,
|
|
76452
|
+
// Creator, Producer, CreationDate, ModDate, Trapped.
|
|
76453
|
+
// To keep the pdfmake api consistent, the info field are defined lowercase.
|
|
76454
|
+
// Custom properties don't contain a space.
|
|
76455
|
+
function standardizePropertyKey(key) {
|
|
76456
|
+
var standardProperties = ['Title', 'Author', 'Subject', 'Keywords',
|
|
76457
|
+
'Creator', 'Producer', 'CreationDate', 'ModDate', 'Trapped'];
|
|
76458
|
+
var standardizedKey = key.charAt(0).toUpperCase() + key.slice(1);
|
|
76459
|
+
if (standardProperties.indexOf(standardizedKey) !== -1) {
|
|
76460
|
+
return standardizedKey;
|
|
76461
|
+
}
|
|
76462
|
+
|
|
76463
|
+
return key.replace(/\s+/g, '');
|
|
76464
|
+
}
|
|
76465
|
+
|
|
76466
|
+
var info = {
|
|
76467
|
+
Producer: 'pdfmake',
|
|
76468
|
+
Creator: 'pdfmake'
|
|
76469
|
+
};
|
|
76470
|
+
|
|
76471
|
+
if (docDefinition.info) {
|
|
76472
|
+
for (var key in docDefinition.info) {
|
|
76473
|
+
var value = docDefinition.info[key];
|
|
76474
|
+
if (value) {
|
|
76475
|
+
key = standardizePropertyKey(key);
|
|
76476
|
+
info[key] = value;
|
|
76477
|
+
}
|
|
76478
|
+
}
|
|
76479
|
+
}
|
|
76480
|
+
return info;
|
|
76481
|
+
}
|
|
76482
|
+
|
|
76483
|
+
function calculatePageHeight(pages, margins) {
|
|
76484
|
+
function getItemHeight(item) {
|
|
76485
|
+
if (isFunction(item.item.getHeight)) {
|
|
76486
|
+
return item.item.getHeight();
|
|
76487
|
+
} else if (item.item._height) {
|
|
76488
|
+
return item.item._height;
|
|
76489
|
+
} else if (item.type === 'vector') {
|
|
76490
|
+
return item.item.y1 > item.item.y2 ? item.item.y1 : item.item.y2;
|
|
76491
|
+
} else {
|
|
76492
|
+
// TODO: add support for next item types
|
|
76493
|
+
return 0;
|
|
76494
|
+
}
|
|
76495
|
+
}
|
|
76496
|
+
|
|
76497
|
+
function getBottomPosition(item) {
|
|
76498
|
+
var top = item.item.y || 0;
|
|
76499
|
+
var height = getItemHeight(item);
|
|
76500
|
+
return top + height;
|
|
76501
|
+
}
|
|
76502
|
+
|
|
76503
|
+
var fixedMargins = fixPageMargins(margins || 40);
|
|
76504
|
+
var height = fixedMargins.top;
|
|
76505
|
+
|
|
76506
|
+
pages.forEach(function (page) {
|
|
76507
|
+
page.items.forEach(function (item) {
|
|
76508
|
+
var bottomPosition = getBottomPosition(item);
|
|
76509
|
+
if (bottomPosition > height) {
|
|
76510
|
+
height = bottomPosition;
|
|
76511
|
+
}
|
|
76512
|
+
});
|
|
76513
|
+
});
|
|
76514
|
+
|
|
76515
|
+
height += fixedMargins.bottom;
|
|
76516
|
+
|
|
76517
|
+
return height;
|
|
76518
|
+
}
|
|
76519
|
+
|
|
76520
|
+
function fixPageSize(pageSize, pageOrientation) {
|
|
76521
|
+
function isNeedSwapPageSizes(pageOrientation) {
|
|
76522
|
+
if (isString(pageOrientation)) {
|
|
76523
|
+
pageOrientation = pageOrientation.toLowerCase();
|
|
76524
|
+
return ((pageOrientation === 'portrait') && (size.width > size.height)) ||
|
|
76525
|
+
((pageOrientation === 'landscape') && (size.width < size.height));
|
|
76526
|
+
}
|
|
76527
|
+
return false;
|
|
76528
|
+
}
|
|
76529
|
+
|
|
76530
|
+
// if pageSize.height is set to auto, set the height to infinity so there are no page breaks.
|
|
76531
|
+
if (pageSize && pageSize.height === 'auto') {
|
|
76532
|
+
pageSize.height = Infinity;
|
|
76533
|
+
}
|
|
76534
|
+
|
|
76535
|
+
var size = pageSize2widthAndHeight(pageSize || 'A4');
|
|
76536
|
+
if (isNeedSwapPageSizes(pageOrientation)) { // swap page sizes
|
|
76537
|
+
size = { width: size.height, height: size.width };
|
|
76538
|
+
}
|
|
76539
|
+
size.orientation = size.width > size.height ? 'landscape' : 'portrait';
|
|
76540
|
+
return size;
|
|
76541
|
+
}
|
|
76542
|
+
|
|
76543
|
+
function fixPageMargins(margin) {
|
|
76544
|
+
if (isNumber(margin)) {
|
|
76545
|
+
margin = { left: margin, right: margin, top: margin, bottom: margin };
|
|
76546
|
+
} else if (isArray(margin)) {
|
|
76547
|
+
if (margin.length === 2) {
|
|
76548
|
+
margin = { left: margin[0], top: margin[1], right: margin[0], bottom: margin[1] };
|
|
76549
|
+
} else if (margin.length === 4) {
|
|
76550
|
+
margin = { left: margin[0], top: margin[1], right: margin[2], bottom: margin[3] };
|
|
76551
|
+
} else {
|
|
76552
|
+
throw 'Invalid pageMargins definition';
|
|
76553
|
+
}
|
|
76554
|
+
}
|
|
76555
|
+
|
|
76556
|
+
return margin;
|
|
76557
|
+
}
|
|
76558
|
+
|
|
76559
|
+
function registerDefaultTableLayouts(layoutBuilder) {
|
|
76560
|
+
layoutBuilder.registerTableLayouts({
|
|
76561
|
+
noBorders: {
|
|
76562
|
+
hLineWidth: function (i) {
|
|
76563
|
+
return 0;
|
|
76564
|
+
},
|
|
76565
|
+
vLineWidth: function (i) {
|
|
76566
|
+
return 0;
|
|
76567
|
+
},
|
|
76568
|
+
paddingLeft: function (i) {
|
|
76569
|
+
return i && 4 || 0;
|
|
76570
|
+
},
|
|
76571
|
+
paddingRight: function (i, node) {
|
|
76572
|
+
return (i < node.table.widths.length - 1) ? 4 : 0;
|
|
76573
|
+
}
|
|
76574
|
+
},
|
|
76575
|
+
headerLineOnly: {
|
|
76576
|
+
hLineWidth: function (i, node) {
|
|
76577
|
+
if (i === 0 || i === node.table.body.length) {
|
|
76578
|
+
return 0;
|
|
76579
|
+
}
|
|
76580
|
+
return (i === node.table.headerRows) ? 2 : 0;
|
|
76581
|
+
},
|
|
76582
|
+
vLineWidth: function (i) {
|
|
76583
|
+
return 0;
|
|
76584
|
+
},
|
|
76585
|
+
paddingLeft: function (i) {
|
|
76586
|
+
return i === 0 ? 0 : 8;
|
|
76587
|
+
},
|
|
76588
|
+
paddingRight: function (i, node) {
|
|
76589
|
+
return (i === node.table.widths.length - 1) ? 0 : 8;
|
|
76590
|
+
}
|
|
76591
|
+
},
|
|
76592
|
+
lightHorizontalLines: {
|
|
76593
|
+
hLineWidth: function (i, node) {
|
|
76594
|
+
if (i === 0 || i === node.table.body.length) {
|
|
76595
|
+
return 0;
|
|
76596
|
+
}
|
|
76597
|
+
return (i === node.table.headerRows) ? 2 : 1;
|
|
76598
|
+
},
|
|
76599
|
+
vLineWidth: function (i) {
|
|
76600
|
+
return 0;
|
|
76601
|
+
},
|
|
76602
|
+
hLineColor: function (i) {
|
|
76603
|
+
return i === 1 ? 'black' : '#aaa';
|
|
76604
|
+
},
|
|
76605
|
+
paddingLeft: function (i) {
|
|
76606
|
+
return i === 0 ? 0 : 8;
|
|
76607
|
+
},
|
|
76608
|
+
paddingRight: function (i, node) {
|
|
76609
|
+
return (i === node.table.widths.length - 1) ? 0 : 8;
|
|
76610
|
+
}
|
|
76611
|
+
}
|
|
76612
|
+
});
|
|
76613
|
+
}
|
|
76614
|
+
|
|
76615
|
+
function pageSize2widthAndHeight(pageSize) {
|
|
76616
|
+
if (isString(pageSize)) {
|
|
76617
|
+
var size = sizes[pageSize.toUpperCase()];
|
|
76618
|
+
if (!size) {
|
|
76619
|
+
throw 'Page size ' + pageSize + ' not recognized';
|
|
76620
|
+
}
|
|
76621
|
+
return { width: size[0], height: size[1] };
|
|
76622
|
+
}
|
|
76623
|
+
|
|
76624
|
+
return pageSize;
|
|
76625
|
+
}
|
|
76626
|
+
|
|
76627
|
+
function updatePageOrientationInOptions(currentPage, pdfKitDoc) {
|
|
76628
|
+
var previousPageOrientation = pdfKitDoc.options.size[0] > pdfKitDoc.options.size[1] ? 'landscape' : 'portrait';
|
|
76629
|
+
|
|
76630
|
+
if (currentPage.pageSize.orientation !== previousPageOrientation) {
|
|
76631
|
+
var width = pdfKitDoc.options.size[0];
|
|
76632
|
+
var height = pdfKitDoc.options.size[1];
|
|
76633
|
+
pdfKitDoc.options.size = [height, width];
|
|
76634
|
+
}
|
|
76635
|
+
}
|
|
76636
|
+
|
|
76637
|
+
function renderPages(pages, fontProvider, pdfKitDoc, patterns, progressCallback) {
|
|
76638
|
+
pdfKitDoc._pdfMakePages = pages;
|
|
76639
|
+
pdfKitDoc.addPage();
|
|
76640
|
+
|
|
76641
|
+
var totalItems = 0;
|
|
76642
|
+
if (progressCallback) {
|
|
76643
|
+
pages.forEach(function (page) {
|
|
76644
|
+
totalItems += page.items.length;
|
|
76645
|
+
});
|
|
76646
|
+
}
|
|
76647
|
+
|
|
76648
|
+
var renderedItems = 0;
|
|
76649
|
+
progressCallback = progressCallback || function () {
|
|
76650
|
+
};
|
|
76651
|
+
|
|
76652
|
+
for (var i = 0; i < pages.length; i++) {
|
|
76653
|
+
if (i > 0) {
|
|
76654
|
+
updatePageOrientationInOptions(pages[i], pdfKitDoc);
|
|
76655
|
+
pdfKitDoc.addPage(pdfKitDoc.options);
|
|
76656
|
+
}
|
|
76657
|
+
|
|
76658
|
+
var page = pages[i];
|
|
76659
|
+
for (var ii = 0, il = page.items.length; ii < il; ii++) {
|
|
76660
|
+
var item = page.items[ii];
|
|
76661
|
+
switch (item.type) {
|
|
76662
|
+
case 'vector':
|
|
76663
|
+
renderVector(item.item, patterns, pdfKitDoc);
|
|
76664
|
+
break;
|
|
76665
|
+
case 'line':
|
|
76666
|
+
renderLine(item.item, item.item.x, item.item.y, patterns, pdfKitDoc);
|
|
76667
|
+
break;
|
|
76668
|
+
case 'image':
|
|
76669
|
+
renderImage(item.item, item.item.x, item.item.y, pdfKitDoc);
|
|
76670
|
+
break;
|
|
76671
|
+
case 'svg':
|
|
76672
|
+
renderSVG(item.item, item.item.x, item.item.y, pdfKitDoc, fontProvider);
|
|
76673
|
+
break;
|
|
76674
|
+
case 'beginClip':
|
|
76675
|
+
beginClip(item.item, pdfKitDoc);
|
|
76676
|
+
break;
|
|
76677
|
+
case 'endClip':
|
|
76678
|
+
endClip(pdfKitDoc);
|
|
76679
|
+
break;
|
|
76680
|
+
}
|
|
76681
|
+
renderedItems++;
|
|
76682
|
+
progressCallback(renderedItems / totalItems);
|
|
76683
|
+
}
|
|
76684
|
+
if (page.watermark) {
|
|
76685
|
+
renderWatermark(page, pdfKitDoc);
|
|
76686
|
+
}
|
|
76687
|
+
}
|
|
76688
|
+
}
|
|
76689
|
+
|
|
76690
|
+
/**
|
|
76691
|
+
* Shift the "y" height of the text baseline up or down (superscript or subscript,
|
|
76692
|
+
* respectively). The exact shift can / should be changed according to standard
|
|
76693
|
+
* conventions.
|
|
76694
|
+
*
|
|
76695
|
+
* @param {number} y
|
|
76696
|
+
* @param {any} inline
|
|
76697
|
+
*/
|
|
76698
|
+
function offsetText(y, inline) {
|
|
76699
|
+
var newY = y;
|
|
76700
|
+
if (inline.sup) {
|
|
76701
|
+
newY -= inline.fontSize * 0.75;
|
|
76702
|
+
}
|
|
76703
|
+
if (inline.sub) {
|
|
76704
|
+
newY += inline.fontSize * 0.35;
|
|
76705
|
+
}
|
|
76706
|
+
return newY;
|
|
76707
|
+
}
|
|
76708
|
+
|
|
76709
|
+
function renderLine(line, x, y, patterns, pdfKitDoc) {
|
|
76710
|
+
function preparePageNodeRefLine(_pageNodeRef, inline) {
|
|
76711
|
+
var newWidth;
|
|
76712
|
+
var diffWidth;
|
|
76713
|
+
var textTools = new TextTools(null);
|
|
76714
|
+
|
|
76715
|
+
if (isUndefined(_pageNodeRef.positions)) {
|
|
76716
|
+
throw 'Page reference id not found';
|
|
76717
|
+
}
|
|
76718
|
+
|
|
76719
|
+
var pageNumber = _pageNodeRef.positions[0].pageNumber.toString();
|
|
76720
|
+
|
|
76721
|
+
inline.text = pageNumber;
|
|
76722
|
+
newWidth = textTools.widthOfString(inline.text, inline.font, inline.fontSize, inline.characterSpacing, inline.fontFeatures);
|
|
76723
|
+
diffWidth = inline.width - newWidth;
|
|
76724
|
+
inline.width = newWidth;
|
|
76725
|
+
|
|
76726
|
+
switch (inline.alignment) {
|
|
76727
|
+
case 'right':
|
|
76728
|
+
inline.x += diffWidth;
|
|
76729
|
+
break;
|
|
76730
|
+
case 'center':
|
|
76731
|
+
inline.x += diffWidth / 2;
|
|
76732
|
+
break;
|
|
76733
|
+
}
|
|
76734
|
+
}
|
|
76735
|
+
|
|
76736
|
+
if (line._pageNodeRef) {
|
|
76737
|
+
preparePageNodeRefLine(line._pageNodeRef, line.inlines[0]);
|
|
76738
|
+
}
|
|
76739
|
+
|
|
76740
|
+
x = x || 0;
|
|
76741
|
+
y = y || 0;
|
|
76742
|
+
|
|
76743
|
+
var lineHeight = line.getHeight();
|
|
76744
|
+
var ascenderHeight = line.getAscenderHeight();
|
|
76745
|
+
var descent = lineHeight - ascenderHeight;
|
|
76746
|
+
|
|
76747
|
+
textDecorator.drawBackground(line, x, y, patterns, pdfKitDoc);
|
|
76748
|
+
|
|
76749
|
+
//TODO: line.optimizeInlines();
|
|
76750
|
+
for (var i = 0, l = line.inlines.length; i < l; i++) {
|
|
76751
|
+
var inline = line.inlines[i];
|
|
76752
|
+
var shiftToBaseline = lineHeight - ((inline.font.ascender / 1000) * inline.fontSize) - descent;
|
|
76753
|
+
|
|
76754
|
+
if (inline._pageNodeRef) {
|
|
76755
|
+
preparePageNodeRefLine(inline._pageNodeRef, inline);
|
|
76756
|
+
}
|
|
76757
|
+
|
|
76758
|
+
var options = {
|
|
76759
|
+
lineBreak: false,
|
|
76760
|
+
textWidth: inline.width,
|
|
76761
|
+
characterSpacing: inline.characterSpacing,
|
|
76762
|
+
wordCount: 1,
|
|
76763
|
+
link: inline.link
|
|
76764
|
+
};
|
|
76765
|
+
|
|
76766
|
+
if (inline.linkToDestination) {
|
|
76767
|
+
options.goTo = inline.linkToDestination;
|
|
76768
|
+
}
|
|
76769
|
+
|
|
76770
|
+
if (line.id && i === 0) {
|
|
76771
|
+
options.destination = line.id;
|
|
76772
|
+
}
|
|
76773
|
+
|
|
76774
|
+
if (inline.fontFeatures) {
|
|
76775
|
+
options.features = inline.fontFeatures;
|
|
76776
|
+
}
|
|
76777
|
+
|
|
76778
|
+
var opacity = isNumber(inline.opacity) ? inline.opacity : 1;
|
|
76779
|
+
pdfKitDoc.opacity(opacity);
|
|
76780
|
+
pdfKitDoc.fill(inline.color || 'black');
|
|
76781
|
+
|
|
76782
|
+
pdfKitDoc._font = inline.font;
|
|
76783
|
+
pdfKitDoc.fontSize(inline.fontSize);
|
|
76784
|
+
|
|
76785
|
+
var shiftedY = offsetText(y + shiftToBaseline, inline);
|
|
76786
|
+
pdfKitDoc.text(inline.text, x + inline.x, shiftedY, options);
|
|
76787
|
+
|
|
76788
|
+
if (inline.linkToPage) {
|
|
76789
|
+
var _ref = pdfKitDoc.ref({ Type: 'Action', S: 'GoTo', D: [inline.linkToPage, 0, 0] }).end();
|
|
76790
|
+
pdfKitDoc.annotate(x + inline.x, shiftedY, inline.width, inline.height, {
|
|
76791
|
+
Subtype: 'Link',
|
|
76792
|
+
Dest: [inline.linkToPage - 1, 'XYZ', null, null, null]
|
|
76793
|
+
});
|
|
76794
|
+
}
|
|
76795
|
+
|
|
76796
|
+
}
|
|
76797
|
+
// Decorations won't draw correctly for superscript
|
|
76798
|
+
textDecorator.drawDecorations(line, x, y, pdfKitDoc);
|
|
76799
|
+
}
|
|
76800
|
+
|
|
76801
|
+
function renderWatermark(page, pdfKitDoc) {
|
|
76802
|
+
var watermark = page.watermark;
|
|
76803
|
+
|
|
76804
|
+
pdfKitDoc.fill(watermark.color);
|
|
76805
|
+
pdfKitDoc.opacity(watermark.opacity);
|
|
76806
|
+
|
|
76807
|
+
pdfKitDoc.save();
|
|
76808
|
+
|
|
76809
|
+
pdfKitDoc.rotate(watermark.angle, { origin: [pdfKitDoc.page.width / 2, pdfKitDoc.page.height / 2] });
|
|
76810
|
+
|
|
76811
|
+
var x = pdfKitDoc.page.width / 2 - watermark._size.size.width / 2;
|
|
76812
|
+
var y = pdfKitDoc.page.height / 2 - watermark._size.size.height / 2;
|
|
76813
|
+
|
|
76814
|
+
pdfKitDoc._font = watermark.font;
|
|
76815
|
+
pdfKitDoc.fontSize(watermark.fontSize);
|
|
76816
|
+
pdfKitDoc.text(watermark.text, x, y, { lineBreak: false });
|
|
76817
|
+
|
|
76818
|
+
pdfKitDoc.restore();
|
|
76819
|
+
}
|
|
76820
|
+
|
|
76821
|
+
function renderVector(vector, patterns, pdfKitDoc) {
|
|
76822
|
+
//TODO: pdf optimization (there's no need to write all properties everytime)
|
|
76823
|
+
pdfKitDoc.lineWidth(vector.lineWidth || 1);
|
|
76824
|
+
if (vector.dash) {
|
|
76825
|
+
pdfKitDoc.dash(vector.dash.length, { space: vector.dash.space || vector.dash.length, phase: vector.dash.phase || 0 });
|
|
76826
|
+
} else {
|
|
76827
|
+
pdfKitDoc.undash();
|
|
76828
|
+
}
|
|
76829
|
+
pdfKitDoc.lineJoin(vector.lineJoin || 'miter');
|
|
76830
|
+
pdfKitDoc.lineCap(vector.lineCap || 'butt');
|
|
76831
|
+
|
|
76832
|
+
//TODO: clipping
|
|
76833
|
+
|
|
76834
|
+
var gradient = null;
|
|
76835
|
+
|
|
76836
|
+
switch (vector.type) {
|
|
76837
|
+
case 'ellipse':
|
|
76838
|
+
pdfKitDoc.ellipse(vector.x, vector.y, vector.r1, vector.r2);
|
|
76839
|
+
|
|
76840
|
+
if (vector.linearGradient) {
|
|
76841
|
+
gradient = pdfKitDoc.linearGradient(vector.x - vector.r1, vector.y, vector.x + vector.r1, vector.y);
|
|
76842
|
+
}
|
|
76843
|
+
break;
|
|
76844
|
+
case 'rect':
|
|
76845
|
+
if (vector.r) {
|
|
76846
|
+
pdfKitDoc.roundedRect(vector.x, vector.y, vector.w, vector.h, vector.r);
|
|
76847
|
+
} else {
|
|
76848
|
+
pdfKitDoc.rect(vector.x, vector.y, vector.w, vector.h);
|
|
76849
|
+
}
|
|
76850
|
+
|
|
76851
|
+
if (vector.linearGradient) {
|
|
76852
|
+
gradient = pdfKitDoc.linearGradient(vector.x, vector.y, vector.x + vector.w, vector.y);
|
|
76853
|
+
}
|
|
76854
|
+
break;
|
|
76855
|
+
case 'line':
|
|
76856
|
+
pdfKitDoc.moveTo(vector.x1, vector.y1);
|
|
76857
|
+
pdfKitDoc.lineTo(vector.x2, vector.y2);
|
|
76858
|
+
break;
|
|
76859
|
+
case 'polyline':
|
|
76860
|
+
if (vector.points.length === 0) {
|
|
76861
|
+
break;
|
|
76862
|
+
}
|
|
76863
|
+
|
|
76864
|
+
pdfKitDoc.moveTo(vector.points[0].x, vector.points[0].y);
|
|
76865
|
+
for (var i = 1, l = vector.points.length; i < l; i++) {
|
|
76866
|
+
pdfKitDoc.lineTo(vector.points[i].x, vector.points[i].y);
|
|
76867
|
+
}
|
|
76868
|
+
|
|
76869
|
+
if (vector.points.length > 1) {
|
|
76870
|
+
var p1 = vector.points[0];
|
|
76871
|
+
var pn = vector.points[vector.points.length - 1];
|
|
76872
|
+
|
|
76873
|
+
if (vector.closePath || p1.x === pn.x && p1.y === pn.y) {
|
|
76874
|
+
pdfKitDoc.closePath();
|
|
76875
|
+
}
|
|
76876
|
+
}
|
|
76877
|
+
break;
|
|
76878
|
+
case 'path':
|
|
76879
|
+
pdfKitDoc.path(vector.d);
|
|
76880
|
+
break;
|
|
76881
|
+
}
|
|
76882
|
+
|
|
76883
|
+
if (vector.linearGradient && gradient) {
|
|
76884
|
+
var step = 1 / (vector.linearGradient.length - 1);
|
|
76885
|
+
|
|
76886
|
+
for (var i = 0; i < vector.linearGradient.length; i++) {
|
|
76887
|
+
gradient.stop(i * step, vector.linearGradient[i]);
|
|
76888
|
+
}
|
|
76889
|
+
|
|
76890
|
+
vector.color = gradient;
|
|
76891
|
+
}
|
|
76892
|
+
|
|
76893
|
+
if (isPattern(vector.color)) {
|
|
76894
|
+
vector.color = getPattern(vector.color, patterns);
|
|
76895
|
+
}
|
|
76896
|
+
|
|
76897
|
+
var fillOpacity = isNumber(vector.fillOpacity) ? vector.fillOpacity : 1;
|
|
76898
|
+
var strokeOpacity = isNumber(vector.strokeOpacity) ? vector.strokeOpacity : 1;
|
|
76899
|
+
|
|
76900
|
+
if (vector.color && vector.lineColor) {
|
|
76901
|
+
pdfKitDoc.fillColor(vector.color, fillOpacity);
|
|
76902
|
+
pdfKitDoc.strokeColor(vector.lineColor, strokeOpacity);
|
|
76903
|
+
pdfKitDoc.fillAndStroke();
|
|
76904
|
+
} else if (vector.color) {
|
|
76905
|
+
pdfKitDoc.fillColor(vector.color, fillOpacity);
|
|
76906
|
+
pdfKitDoc.fill();
|
|
76907
|
+
} else {
|
|
76908
|
+
pdfKitDoc.strokeColor(vector.lineColor || 'black', strokeOpacity);
|
|
76909
|
+
pdfKitDoc.stroke();
|
|
76910
|
+
}
|
|
76911
|
+
}
|
|
76912
|
+
|
|
76913
|
+
function renderImage(image, x, y, pdfKitDoc) {
|
|
76914
|
+
var opacity = isNumber(image.opacity) ? image.opacity : 1;
|
|
76915
|
+
pdfKitDoc.opacity(opacity);
|
|
76916
|
+
if (image.cover) {
|
|
76917
|
+
var align = image.cover.align || 'center';
|
|
76918
|
+
var valign = image.cover.valign || 'center';
|
|
76919
|
+
var width = image.cover.width ? image.cover.width : image.width;
|
|
76920
|
+
var height = image.cover.height ? image.cover.height : image.height;
|
|
76921
|
+
pdfKitDoc.save();
|
|
76922
|
+
pdfKitDoc.rect(image.x, image.y, width, height).clip();
|
|
76923
|
+
pdfKitDoc.image(image.image, image.x, image.y, { cover: [width, height], align: align, valign: valign });
|
|
76924
|
+
pdfKitDoc.restore();
|
|
76925
|
+
} else {
|
|
76926
|
+
pdfKitDoc.image(image.image, image.x, image.y, { width: image._width, height: image._height });
|
|
76927
|
+
}
|
|
76928
|
+
if (image.link) {
|
|
76929
|
+
pdfKitDoc.link(image.x, image.y, image._width, image._height, image.link);
|
|
76930
|
+
}
|
|
76931
|
+
if (image.linkToPage) {
|
|
76932
|
+
pdfKitDoc.ref({ Type: 'Action', S: 'GoTo', D: [image.linkToPage, 0, 0] }).end();
|
|
76933
|
+
pdfKitDoc.annotate(image.x, image.y, image._width, image._height, { Subtype: 'Link', Dest: [image.linkToPage - 1, 'XYZ', null, null, null] });
|
|
76934
|
+
}
|
|
76935
|
+
if (image.linkToDestination) {
|
|
76936
|
+
pdfKitDoc.goTo(image.x, image.y, image._width, image._height, image.linkToDestination);
|
|
76937
|
+
}
|
|
76938
|
+
}
|
|
76939
|
+
|
|
76940
|
+
function renderSVG(svg, x, y, pdfKitDoc, fontProvider) {
|
|
76941
|
+
var options = Object.assign({ width: svg._width, height: svg._height, assumePt: true }, svg.options);
|
|
76942
|
+
options.fontCallback = function (family, bold, italic) {
|
|
76943
|
+
var fontsFamily = family.split(',').map(function (f) { return f.trim().replace(/('|")/g, ''); });
|
|
76944
|
+
var font = findFont(fontProvider.fonts, fontsFamily, svg.font || 'Roboto');
|
|
76945
|
+
|
|
76946
|
+
var fontFile = fontProvider.getFontFile(font, bold, italic);
|
|
76947
|
+
if (fontFile === null) {
|
|
76948
|
+
var type = fontProvider.getFontType(bold, italic);
|
|
76949
|
+
throw new Error('Font \'' + font + '\' in style \'' + type + '\' is not defined in the font section of the document definition.');
|
|
76950
|
+
}
|
|
76951
|
+
|
|
76952
|
+
return fontFile;
|
|
76953
|
+
};
|
|
76954
|
+
|
|
76955
|
+
SVGtoPDF(pdfKitDoc, svg.svg, svg.x, svg.y, options);
|
|
76956
|
+
}
|
|
76957
|
+
|
|
76958
|
+
function beginClip(rect, pdfKitDoc) {
|
|
76959
|
+
pdfKitDoc.save();
|
|
76960
|
+
pdfKitDoc.addContent('' + rect.x + ' ' + rect.y + ' ' + rect.width + ' ' + rect.height + ' re');
|
|
76961
|
+
pdfKitDoc.clip();
|
|
76962
|
+
}
|
|
76963
|
+
|
|
76964
|
+
function endClip(pdfKitDoc) {
|
|
76965
|
+
pdfKitDoc.restore();
|
|
76966
|
+
}
|
|
76967
|
+
|
|
76968
|
+
function createPatterns(patternDefinitions, pdfKitDoc) {
|
|
76969
|
+
var patterns = {};
|
|
76970
|
+
Object.keys(patternDefinitions).forEach(function (p) {
|
|
76971
|
+
var pattern = patternDefinitions[p];
|
|
76972
|
+
patterns[p] = pdfKitDoc.pattern(pattern.boundingBox, pattern.xStep, pattern.yStep, pattern.pattern, pattern.colored);
|
|
76973
|
+
});
|
|
76974
|
+
return patterns;
|
|
76975
|
+
}
|
|
76976
|
+
|
|
76977
|
+
module.exports = PdfPrinter;
|
|
77046
76978
|
|
|
77047
76979
|
|
|
77048
76980
|
/***/ }),
|