pdfmake 0.3.0-beta.8 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/CHANGELOG.md +7 -40
  2. package/LICENSE +1 -1
  3. package/README.md +78 -85
  4. package/build/pdfmake.js +60308 -68400
  5. package/build/pdfmake.js.map +1 -1
  6. package/build/pdfmake.min.js +2 -2
  7. package/build/pdfmake.min.js.map +1 -1
  8. package/build/vfs_fonts.js +4 -4
  9. package/fonts/Roboto/Roboto-Italic.ttf +0 -0
  10. package/fonts/Roboto/Roboto-Medium.ttf +0 -0
  11. package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
  12. package/fonts/Roboto/Roboto-Regular.ttf +0 -0
  13. package/js/3rd-party/svg-to-pdfkit/source.js +3626 -0
  14. package/js/3rd-party/svg-to-pdfkit.js +7 -0
  15. package/js/DocMeasure.js +645 -0
  16. package/js/DocPreprocessor.js +253 -0
  17. package/js/DocumentContext.js +305 -0
  18. package/js/ElementWriter.js +354 -0
  19. package/js/LayoutBuilder.js +1105 -0
  20. package/js/Line.js +105 -0
  21. package/js/OutputDocument.js +64 -0
  22. package/js/OutputDocumentServer.js +22 -0
  23. package/js/PDFDocument.js +144 -0
  24. package/js/PageElementWriter.js +155 -0
  25. package/js/PageSize.js +74 -0
  26. package/js/Printer.js +291 -0
  27. package/js/Renderer.js +383 -0
  28. package/js/SVGMeasure.js +69 -0
  29. package/js/StyleContextStack.js +168 -0
  30. package/js/TableProcessor.js +548 -0
  31. package/js/TextBreaker.js +166 -0
  32. package/js/TextDecorator.js +143 -0
  33. package/js/TextInlines.js +206 -0
  34. package/js/URLResolver.js +43 -0
  35. package/js/base.js +52 -0
  36. package/js/browser-extensions/OutputDocumentBrowser.js +81 -0
  37. package/js/browser-extensions/fonts/Roboto.js +38 -0
  38. package/js/browser-extensions/index.js +53 -0
  39. package/js/browser-extensions/pdfMake.js +3 -0
  40. package/js/browser-extensions/standard-fonts/Courier.js +38 -0
  41. package/js/browser-extensions/standard-fonts/Helvetica.js +38 -0
  42. package/js/browser-extensions/standard-fonts/Symbol.js +23 -0
  43. package/js/browser-extensions/standard-fonts/Times.js +38 -0
  44. package/js/browser-extensions/standard-fonts/ZapfDingbats.js +23 -0
  45. package/js/browser-extensions/virtual-fs-cjs.js +3 -0
  46. package/js/columnCalculator.js +148 -0
  47. package/js/helpers/node.js +98 -0
  48. package/js/helpers/tools.js +46 -0
  49. package/js/helpers/variableType.js +59 -0
  50. package/js/index.js +15 -0
  51. package/js/qrEnc.js +721 -0
  52. package/js/standardPageSizes.js +56 -0
  53. package/js/tableLayouts.js +98 -0
  54. package/js/virtual-fs.js +60 -0
  55. package/package.json +25 -24
  56. package/src/DocMeasure.js +28 -7
  57. package/src/DocPreprocessor.js +25 -6
  58. package/src/DocumentContext.js +62 -33
  59. package/src/ElementWriter.js +30 -7
  60. package/src/LayoutBuilder.js +557 -120
  61. package/src/OutputDocument.js +23 -37
  62. package/src/OutputDocumentServer.js +6 -11
  63. package/src/PDFDocument.js +1 -1
  64. package/src/PageElementWriter.js +21 -2
  65. package/src/Printer.js +134 -131
  66. package/src/Renderer.js +13 -15
  67. package/src/SVGMeasure.js +2 -2
  68. package/src/StyleContextStack.js +7 -44
  69. package/src/TableProcessor.js +62 -22
  70. package/src/TextBreaker.js +24 -5
  71. package/src/TextInlines.js +1 -1
  72. package/src/URLResolver.js +24 -58
  73. package/src/base.js +1 -1
  74. package/src/browser-extensions/OutputDocumentBrowser.js +33 -71
  75. package/src/browser-extensions/index.js +3 -3
  76. package/src/browser-extensions/pdfMake.js +0 -14
  77. package/src/browser-extensions/standard-fonts/Courier.js +4 -4
  78. package/src/browser-extensions/standard-fonts/Helvetica.js +4 -4
  79. package/src/browser-extensions/standard-fonts/Symbol.js +1 -1
  80. package/src/browser-extensions/standard-fonts/Times.js +4 -4
  81. package/src/browser-extensions/standard-fonts/ZapfDingbats.js +1 -1
  82. package/src/columnCalculator.js +24 -3
  83. package/src/helpers/tools.js +5 -0
  84. package/src/helpers/variableType.js +11 -0
  85. package/src/index.js +1 -1
  86. package/standard-fonts/Helvetica.js +0 -1
  87. package/src/browser-extensions/URLBrowserResolver.js +0 -84
package/js/Line.js ADDED
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ class Line {
6
+ /**
7
+ * @param {number} maxWidth Maximum width this line can have
8
+ */
9
+ constructor(maxWidth) {
10
+ this.maxWidth = maxWidth;
11
+ this.leadingCut = 0;
12
+ this.trailingCut = 0;
13
+ this.inlineWidths = 0;
14
+ this.inlines = [];
15
+ }
16
+
17
+ /**
18
+ * @param {object} inline
19
+ */
20
+ addInline(inline) {
21
+ if (this.inlines.length === 0) {
22
+ this.leadingCut = inline.leadingCut || 0;
23
+ }
24
+ this.trailingCut = inline.trailingCut || 0;
25
+ inline.x = this.inlineWidths - this.leadingCut;
26
+ this.inlines.push(inline);
27
+ this.inlineWidths += inline.width;
28
+ if (inline.lineEnd) {
29
+ this.newLineForced = true;
30
+ }
31
+ }
32
+
33
+ /**
34
+ * @returns {number}
35
+ */
36
+ getHeight() {
37
+ let max = 0;
38
+ this.inlines.forEach(item => {
39
+ max = Math.max(max, item.height || 0);
40
+ });
41
+ return max;
42
+ }
43
+
44
+ /**
45
+ * @returns {number}
46
+ */
47
+ getAscenderHeight() {
48
+ let y = 0;
49
+ this.inlines.forEach(inline => {
50
+ y = Math.max(y, inline.font.ascender / 1000 * inline.fontSize);
51
+ });
52
+ return y;
53
+ }
54
+
55
+ /**
56
+ * @returns {number}
57
+ */
58
+ getWidth() {
59
+ return this.inlineWidths - this.leadingCut - this.trailingCut;
60
+ }
61
+
62
+ /**
63
+ * @returns {number}
64
+ */
65
+ getAvailableWidth() {
66
+ return this.maxWidth - this.getWidth();
67
+ }
68
+
69
+ /**
70
+ * @param {object} inline
71
+ * @param {Array} nextInlines
72
+ * @returns {boolean}
73
+ */
74
+ hasEnoughSpaceForInline(inline, nextInlines = []) {
75
+ if (this.inlines.length === 0) {
76
+ return true;
77
+ }
78
+ if (this.newLineForced) {
79
+ return false;
80
+ }
81
+ let inlineWidth = inline.width;
82
+ let inlineTrailingCut = inline.trailingCut || 0;
83
+ if (inline.noNewLine) {
84
+ for (let i = 0, l = nextInlines.length; i < l; i++) {
85
+ let nextInline = nextInlines[i];
86
+ inlineWidth += nextInline.width;
87
+ inlineTrailingCut += nextInline.trailingCut || 0;
88
+ if (!nextInline.noNewLine) {
89
+ break;
90
+ }
91
+ }
92
+ }
93
+ return this.inlineWidths + inlineWidth - this.leadingCut - inlineTrailingCut <= this.maxWidth;
94
+ }
95
+ clone() {
96
+ let result = new Line(this.maxWidth);
97
+ for (let key in this) {
98
+ if (this.hasOwnProperty(key)) {
99
+ result[key] = this[key];
100
+ }
101
+ }
102
+ return result;
103
+ }
104
+ }
105
+ var _default = exports.default = Line;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ class OutputDocument {
6
+ /**
7
+ * @param {Promise<object>} pdfDocumentPromise
8
+ */
9
+ constructor(pdfDocumentPromise) {
10
+ this.bufferSize = 1073741824;
11
+ this.pdfDocumentPromise = pdfDocumentPromise;
12
+ this.bufferPromise = null;
13
+ }
14
+
15
+ /**
16
+ * @returns {Promise<object>}
17
+ */
18
+ getStream() {
19
+ return this.pdfDocumentPromise;
20
+ }
21
+
22
+ /**
23
+ * @returns {Promise<Buffer>}
24
+ */
25
+ getBuffer() {
26
+ const getBufferInternal = async () => {
27
+ const stream = await this.getStream();
28
+ return new Promise(resolve => {
29
+ let chunks = [];
30
+ stream.on('readable', () => {
31
+ let chunk;
32
+ while ((chunk = stream.read(this.bufferSize)) !== null) {
33
+ chunks.push(chunk);
34
+ }
35
+ });
36
+ stream.on('end', () => {
37
+ resolve(Buffer.concat(chunks));
38
+ });
39
+ stream.end();
40
+ });
41
+ };
42
+ if (this.bufferPromise === null) {
43
+ this.bufferPromise = getBufferInternal();
44
+ }
45
+ return this.bufferPromise;
46
+ }
47
+
48
+ /**
49
+ * @returns {Promise<string>}
50
+ */
51
+ async getBase64() {
52
+ const buffer = await this.getBuffer();
53
+ return buffer.toString('base64');
54
+ }
55
+
56
+ /**
57
+ * @returns {Promise<string>}
58
+ */
59
+ async getDataUrl() {
60
+ const data = await this.getBase64();
61
+ return 'data:application/pdf;base64,' + data;
62
+ }
63
+ }
64
+ var _default = exports.default = OutputDocument;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _OutputDocument = _interopRequireDefault(require("./OutputDocument"));
6
+ var _fs = _interopRequireDefault(require("fs"));
7
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
8
+ class OutputDocumentServer extends _OutputDocument.default {
9
+ /**
10
+ * @param {string} filename
11
+ * @returns {Promise}
12
+ */
13
+ async write(filename) {
14
+ const stream = await this.getStream();
15
+ return new Promise(resolve => {
16
+ stream.pipe(_fs.default.createWriteStream(filename));
17
+ stream.on('end', resolve);
18
+ stream.end();
19
+ });
20
+ }
21
+ }
22
+ var _default = exports.default = OutputDocumentServer;
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _pdfkit = _interopRequireDefault(require("pdfkit"));
6
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
7
+ const typeName = (bold, italics) => {
8
+ let type = 'normal';
9
+ if (bold && italics) {
10
+ type = 'bolditalics';
11
+ } else if (bold) {
12
+ type = 'bold';
13
+ } else if (italics) {
14
+ type = 'italics';
15
+ }
16
+ return type;
17
+ };
18
+ class PDFDocument extends _pdfkit.default {
19
+ constructor(fonts = {}, images = {}, patterns = {}, attachments = {}, options = {}, virtualfs = null) {
20
+ super(options);
21
+ this.fonts = {};
22
+ this.fontCache = {};
23
+ for (let font in fonts) {
24
+ if (fonts.hasOwnProperty(font)) {
25
+ let fontDef = fonts[font];
26
+ this.fonts[font] = {
27
+ normal: fontDef.normal,
28
+ bold: fontDef.bold,
29
+ italics: fontDef.italics,
30
+ bolditalics: fontDef.bolditalics
31
+ };
32
+ }
33
+ }
34
+ this.patterns = {};
35
+ for (let pattern in patterns) {
36
+ if (patterns.hasOwnProperty(pattern)) {
37
+ let patternDef = patterns[pattern];
38
+ this.patterns[pattern] = this.pattern(patternDef.boundingBox, patternDef.xStep, patternDef.yStep, patternDef.pattern, patternDef.colored);
39
+ }
40
+ }
41
+ this.images = images;
42
+ this.attachments = attachments;
43
+ this.virtualfs = virtualfs;
44
+ }
45
+ getFontType(bold, italics) {
46
+ return typeName(bold, italics);
47
+ }
48
+ getFontFile(familyName, bold, italics) {
49
+ let type = this.getFontType(bold, italics);
50
+ if (!this.fonts[familyName] || !this.fonts[familyName][type]) {
51
+ return null;
52
+ }
53
+ return this.fonts[familyName][type];
54
+ }
55
+ provideFont(familyName, bold, italics) {
56
+ let type = this.getFontType(bold, italics);
57
+ if (this.getFontFile(familyName, bold, italics) === null) {
58
+ throw new Error(`Font '${familyName}' in style '${type}' is not defined in the font section of the document definition.`);
59
+ }
60
+ this.fontCache[familyName] = this.fontCache[familyName] || {};
61
+ if (!this.fontCache[familyName][type]) {
62
+ let def = this.fonts[familyName][type];
63
+ if (!Array.isArray(def)) {
64
+ def = [def];
65
+ }
66
+ if (this.virtualfs && this.virtualfs.existsSync(def[0])) {
67
+ def[0] = this.virtualfs.readFileSync(def[0]);
68
+ }
69
+ this.fontCache[familyName][type] = this.font(...def)._font;
70
+ }
71
+ return this.fontCache[familyName][type];
72
+ }
73
+ provideImage(src) {
74
+ const realImageSrc = src => {
75
+ let image = this.images[src];
76
+ if (!image) {
77
+ return src;
78
+ }
79
+ if (this.virtualfs && this.virtualfs.existsSync(image)) {
80
+ return this.virtualfs.readFileSync(image);
81
+ }
82
+ let index = image.indexOf('base64,');
83
+ if (index < 0) {
84
+ return this.images[src];
85
+ }
86
+ return Buffer.from(image.substring(index + 7), 'base64');
87
+ };
88
+ if (this._imageRegistry[src]) {
89
+ return this._imageRegistry[src];
90
+ }
91
+ let image;
92
+ try {
93
+ image = this.openImage(realImageSrc(src));
94
+ if (!image) {
95
+ throw new Error('No image');
96
+ }
97
+ } catch (error) {
98
+ throw new Error(`Invalid image: ${error.toString()}\nImages dictionary should contain dataURL entries (or local file paths in node.js)`);
99
+ }
100
+ image.embed(this);
101
+ this._imageRegistry[src] = image;
102
+ return image;
103
+ }
104
+
105
+ /**
106
+ * @param {Array} color pdfmake format: [<pattern name>, <color>]
107
+ * @returns {Array} pdfkit format: [<pattern object>, <color>]
108
+ */
109
+ providePattern(color) {
110
+ if (Array.isArray(color) && color.length === 2) {
111
+ return [this.patterns[color[0]], color[1]];
112
+ }
113
+ return null;
114
+ }
115
+ provideAttachment(src) {
116
+ const checkRequired = obj => {
117
+ if (!obj) {
118
+ throw new Error('No attachment');
119
+ }
120
+ if (!obj.src) {
121
+ throw new Error('The "src" key is required for attachments');
122
+ }
123
+ return obj;
124
+ };
125
+ if (typeof src === 'object') {
126
+ return checkRequired(src);
127
+ }
128
+ let attachment = checkRequired(this.attachments[src]);
129
+ if (this.virtualfs && this.virtualfs.existsSync(attachment.src)) {
130
+ return this.virtualfs.readFileSync(attachment.src);
131
+ }
132
+ return attachment;
133
+ }
134
+ setOpenActionAsPrint() {
135
+ let printActionRef = this.ref({
136
+ Type: 'Action',
137
+ S: 'Named',
138
+ N: 'Print'
139
+ });
140
+ this._root.data.OpenAction = printActionRef;
141
+ printActionRef.end();
142
+ }
143
+ }
144
+ var _default = exports.default = PDFDocument;
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.default = void 0;
5
+ var _ElementWriter = _interopRequireDefault(require("./ElementWriter"));
6
+ var _PageSize = require("./PageSize");
7
+ var _DocumentContext = _interopRequireDefault(require("./DocumentContext"));
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ /**
10
+ * An extended ElementWriter which can handle:
11
+ * - page-breaks (it adds new pages when there's not enough space left),
12
+ * - repeatable fragments (like table-headers, which are repeated everytime
13
+ * a page-break occurs)
14
+ * - transactions (used for unbreakable-blocks when we want to make sure
15
+ * whole block will be rendered on the same page)
16
+ */
17
+ class PageElementWriter extends _ElementWriter.default {
18
+ /**
19
+ * @param {DocumentContext} context
20
+ */
21
+ constructor(context) {
22
+ super(context);
23
+ this.transactionLevel = 0;
24
+ this.repeatables = [];
25
+ }
26
+ addLine(line, dontUpdateContextPosition, index) {
27
+ return this._fitOnPage(() => super.addLine(line, dontUpdateContextPosition, index));
28
+ }
29
+ addImage(image, index) {
30
+ return this._fitOnPage(() => super.addImage(image, index));
31
+ }
32
+ addCanvas(image, index) {
33
+ return this._fitOnPage(() => super.addCanvas(image, index));
34
+ }
35
+ addSVG(image, index) {
36
+ return this._fitOnPage(() => super.addSVG(image, index));
37
+ }
38
+ addQr(qr, index) {
39
+ return this._fitOnPage(() => super.addQr(qr, index));
40
+ }
41
+ addAttachment(attachment, index) {
42
+ return this._fitOnPage(() => super.addAttachment(attachment, index));
43
+ }
44
+ addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
45
+ return super.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
46
+ }
47
+ beginClip(width, height) {
48
+ return super.beginClip(width, height);
49
+ }
50
+ endClip() {
51
+ return super.endClip();
52
+ }
53
+ addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition) {
54
+ return this._fitOnPage(() => super.addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition));
55
+ }
56
+ moveToNextPage(pageOrientation) {
57
+ let nextPage = this.context().moveToNextPage(pageOrientation);
58
+
59
+ // moveToNextPage is called multiple times for table, because is called for each column
60
+ // and repeatables are inserted only in the first time. If columns are used, is needed
61
+ // call for table in first column and then for table in the second column (is other repeatables).
62
+ this.repeatables.forEach(function (rep) {
63
+ if (rep.insertedOnPages[this.context().page] === undefined) {
64
+ rep.insertedOnPages[this.context().page] = true;
65
+ this.addFragment(rep, true);
66
+ } else {
67
+ this.context().moveDown(rep.height);
68
+ }
69
+ }, this);
70
+ this.emit('pageChanged', {
71
+ prevPage: nextPage.prevPage,
72
+ prevY: nextPage.prevY,
73
+ y: this.context().y
74
+ });
75
+ }
76
+ addPage(pageSize, pageOrientation, pageMargin, customProperties = {}) {
77
+ let prevPage = this.page;
78
+ let prevY = this.y;
79
+ this.context().addPage((0, _PageSize.normalizePageSize)(pageSize, pageOrientation), (0, _PageSize.normalizePageMargin)(pageMargin), customProperties);
80
+ this.emit('pageChanged', {
81
+ prevPage: prevPage,
82
+ prevY: prevY,
83
+ y: this.context().y
84
+ });
85
+ }
86
+ beginUnbreakableBlock(width, height) {
87
+ if (this.transactionLevel++ === 0) {
88
+ this.originalX = this.context().x;
89
+ this.pushContext(width, height);
90
+ }
91
+ }
92
+ commitUnbreakableBlock(forcedX, forcedY) {
93
+ if (--this.transactionLevel === 0) {
94
+ let unbreakableContext = this.context();
95
+ this.popContext();
96
+ let nbPages = unbreakableContext.pages.length;
97
+ if (nbPages > 0) {
98
+ // no support for multi-page unbreakableBlocks
99
+ let fragment = unbreakableContext.pages[0];
100
+ fragment.xOffset = forcedX;
101
+ fragment.yOffset = forcedY;
102
+
103
+ //TODO: vectors can influence height in some situations
104
+ if (nbPages > 1) {
105
+ // on out-of-context blocs (headers, footers, background) height should be the whole DocumentContext height
106
+ if (forcedX !== undefined || forcedY !== undefined) {
107
+ fragment.height = unbreakableContext.getCurrentPage().pageSize.height - unbreakableContext.pageMargins.top - unbreakableContext.pageMargins.bottom;
108
+ } else {
109
+ fragment.height = this.context().getCurrentPage().pageSize.height - this.context().pageMargins.top - this.context().pageMargins.bottom;
110
+ for (let i = 0, l = this.repeatables.length; i < l; i++) {
111
+ fragment.height -= this.repeatables[i].height;
112
+ }
113
+ }
114
+ } else {
115
+ fragment.height = unbreakableContext.y;
116
+ }
117
+ if (forcedX !== undefined || forcedY !== undefined) {
118
+ super.addFragment(fragment, true, true, true);
119
+ } else {
120
+ this.addFragment(fragment);
121
+ }
122
+ }
123
+ }
124
+ }
125
+ currentBlockToRepeatable() {
126
+ let unbreakableContext = this.context();
127
+ let rep = {
128
+ items: []
129
+ };
130
+ unbreakableContext.pages[0].items.forEach(item => {
131
+ rep.items.push(item);
132
+ });
133
+ rep.xOffset = this.originalX;
134
+
135
+ //TODO: vectors can influence height in some situations
136
+ rep.height = unbreakableContext.y;
137
+ rep.insertedOnPages = [];
138
+ return rep;
139
+ }
140
+ pushToRepeatables(rep) {
141
+ this.repeatables.push(rep);
142
+ }
143
+ popFromRepeatables() {
144
+ this.repeatables.pop();
145
+ }
146
+ _fitOnPage(addFct) {
147
+ let position = addFct();
148
+ if (!position) {
149
+ this.moveToNextPage();
150
+ position = addFct();
151
+ }
152
+ return position;
153
+ }
154
+ }
155
+ var _default = exports.default = PageElementWriter;
package/js/PageSize.js ADDED
@@ -0,0 +1,74 @@
1
+ "use strict";
2
+
3
+ exports.__esModule = true;
4
+ exports.normalizePageMargin = normalizePageMargin;
5
+ exports.normalizePageSize = normalizePageSize;
6
+ var _standardPageSizes = _interopRequireDefault(require("./standardPageSizes"));
7
+ var _variableType = require("./helpers/variableType");
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function normalizePageSize(pageSize, pageOrientation) {
10
+ function isNeedSwapPageSizes(pageOrientation) {
11
+ if ((0, _variableType.isString)(pageOrientation)) {
12
+ pageOrientation = pageOrientation.toLowerCase();
13
+ return pageOrientation === 'portrait' && size.width > size.height || pageOrientation === 'landscape' && size.width < size.height;
14
+ }
15
+ return false;
16
+ }
17
+ function pageSizeToWidthAndHeight(pageSize) {
18
+ if ((0, _variableType.isString)(pageSize)) {
19
+ let size = _standardPageSizes.default[pageSize.toUpperCase()];
20
+ if (!size) {
21
+ throw new Error(`Page size ${pageSize} not recognized`);
22
+ }
23
+ return {
24
+ width: size[0],
25
+ height: size[1]
26
+ };
27
+ }
28
+ return pageSize;
29
+ }
30
+
31
+ // if pageSize.height is set to auto, set the height to infinity so there are no page breaks.
32
+ if (pageSize && pageSize.height === 'auto') {
33
+ pageSize.height = Infinity;
34
+ }
35
+ let size = pageSizeToWidthAndHeight(pageSize || 'A4');
36
+ if (isNeedSwapPageSizes(pageOrientation)) {
37
+ // swap page sizes
38
+ size = {
39
+ width: size.height,
40
+ height: size.width
41
+ };
42
+ }
43
+ size.orientation = size.width > size.height ? 'landscape' : 'portrait';
44
+ return size;
45
+ }
46
+ function normalizePageMargin(margin) {
47
+ if ((0, _variableType.isNumber)(margin)) {
48
+ margin = {
49
+ left: margin,
50
+ right: margin,
51
+ top: margin,
52
+ bottom: margin
53
+ };
54
+ } else if (Array.isArray(margin)) {
55
+ if (margin.length === 2) {
56
+ margin = {
57
+ left: margin[0],
58
+ top: margin[1],
59
+ right: margin[0],
60
+ bottom: margin[1]
61
+ };
62
+ } else if (margin.length === 4) {
63
+ margin = {
64
+ left: margin[0],
65
+ top: margin[1],
66
+ right: margin[2],
67
+ bottom: margin[3]
68
+ };
69
+ } else {
70
+ throw new Error('Invalid pageMargins definition');
71
+ }
72
+ }
73
+ return margin;
74
+ }