pdfmake 0.3.2 → 0.3.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 +18 -0
- package/LICENSE +21 -21
- package/README.md +75 -78
- package/build/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/build/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/build/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/build/fonts/Roboto.js +27 -0
- package/build/pdfmake.js +64813 -64584
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/standard-fonts/Courier.js +27 -27
- package/build/standard-fonts/Helvetica.js +27 -27
- package/build/standard-fonts/Symbol.js +21 -21
- package/build/standard-fonts/Times.js +27 -27
- package/build/standard-fonts/ZapfDingbats.js +21 -21
- package/build/vfs_fonts.js +5 -5
- package/build-vfs.js +44 -44
- package/fonts/Roboto.js +8 -8
- package/js/3rd-party/svg-to-pdfkit/source.js +1 -1
- package/js/DocMeasure.js +11 -6
- package/js/DocumentContext.js +8 -3
- package/js/ElementWriter.js +42 -16
- package/js/LayoutBuilder.js +144 -78
- package/js/Line.js +16 -16
- package/js/OutputDocument.js +10 -10
- package/js/OutputDocumentServer.js +3 -3
- package/js/PDFDocument.js +3 -3
- package/js/PageElementWriter.js +15 -9
- package/js/Printer.js +28 -28
- package/js/Renderer.js +40 -8
- package/js/SVGMeasure.js +10 -10
- package/js/StyleContextStack.js +74 -51
- package/js/TableProcessor.js +14 -0
- package/js/TextBreaker.js +17 -17
- package/js/TextDecorator.js +12 -3
- package/js/TextInlines.js +34 -33
- package/js/base.js +4 -4
- package/js/browser-extensions/OutputDocumentBrowser.js +24 -24
- package/js/columnCalculator.js +2 -2
- package/js/helpers/node.js +47 -23
- package/js/helpers/variableType.js +18 -18
- package/js/qrEnc.js +38 -38
- package/js/virtual-fs.js +11 -11
- package/package.json +12 -12
- package/src/3rd-party/svg-to-pdfkit/LICENSE +9 -9
- package/src/3rd-party/svg-to-pdfkit/source.js +2745 -2745
- package/src/3rd-party/svg-to-pdfkit.js +3 -3
- package/src/DocMeasure.js +745 -738
- package/src/DocPreprocessor.js +283 -283
- package/src/DocumentContext.js +345 -338
- package/src/ElementWriter.js +441 -417
- package/src/LayoutBuilder.js +1336 -1258
- package/src/Line.js +114 -114
- package/src/OutputDocument.js +64 -64
- package/src/OutputDocumentServer.js +32 -32
- package/src/PDFDocument.js +174 -174
- package/src/PageElementWriter.js +187 -179
- package/src/PageSize.js +53 -53
- package/src/Printer.js +306 -306
- package/src/Renderer.js +445 -409
- package/src/SVGMeasure.js +109 -109
- package/src/StyleContextStack.js +208 -179
- package/src/TableProcessor.js +620 -602
- package/src/TextBreaker.js +168 -168
- package/src/TextDecorator.js +175 -161
- package/src/TextInlines.js +224 -223
- package/src/URLResolver.js +43 -43
- package/src/base.js +70 -70
- package/src/browser-extensions/OutputDocumentBrowser.js +80 -80
- package/src/browser-extensions/fonts/Roboto.js +27 -27
- package/src/browser-extensions/index.js +55 -55
- package/src/browser-extensions/pdfMake.js +1 -1
- package/src/browser-extensions/standard-fonts/Courier.js +27 -27
- package/src/browser-extensions/standard-fonts/Helvetica.js +27 -27
- package/src/browser-extensions/standard-fonts/Symbol.js +21 -21
- package/src/browser-extensions/standard-fonts/Times.js +27 -27
- package/src/browser-extensions/standard-fonts/ZapfDingbats.js +21 -21
- package/src/browser-extensions/virtual-fs-cjs.js +1 -1
- package/src/columnCalculator.js +154 -154
- package/src/helpers/node.js +134 -110
- package/src/helpers/tools.js +44 -44
- package/src/helpers/variableType.js +50 -50
- package/src/index.js +16 -16
- package/src/qrEnc.js +796 -796
- package/src/standardPageSizes.js +52 -52
- package/src/tableLayouts.js +100 -100
- package/src/virtual-fs.js +66 -66
- package/standard-fonts/Courier.js +8 -8
- package/standard-fonts/Helvetica.js +8 -8
- package/standard-fonts/Symbol.js +5 -5
- package/standard-fonts/Times.js +8 -8
- package/standard-fonts/ZapfDingbats.js +5 -5
package/src/PageElementWriter.js
CHANGED
|
@@ -1,179 +1,187 @@
|
|
|
1
|
-
import ElementWriter from './ElementWriter';
|
|
2
|
-
import { normalizePageSize, normalizePageMargin } from './PageSize';
|
|
3
|
-
import DocumentContext from './DocumentContext';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* An extended ElementWriter which can handle:
|
|
7
|
-
* - page-breaks (it adds new pages when there's not enough space left),
|
|
8
|
-
* - repeatable fragments (like table-headers, which are repeated everytime
|
|
9
|
-
* a page-break occurs)
|
|
10
|
-
* - transactions (used for unbreakable-blocks when we want to make sure
|
|
11
|
-
* whole block will be rendered on the same page)
|
|
12
|
-
*/
|
|
13
|
-
class PageElementWriter extends ElementWriter {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @param {DocumentContext} context
|
|
17
|
-
*/
|
|
18
|
-
constructor(context) {
|
|
19
|
-
super(context);
|
|
20
|
-
this.transactionLevel = 0;
|
|
21
|
-
this.repeatables = [];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
addLine(line, dontUpdateContextPosition, index) {
|
|
25
|
-
return this._fitOnPage(() => super.addLine(line, dontUpdateContextPosition, index));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
addImage(image, index) {
|
|
29
|
-
return this._fitOnPage(() => super.addImage(image, index));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
addCanvas(image, index) {
|
|
33
|
-
return this._fitOnPage(() => super.addCanvas(image, index));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
addSVG(image, index) {
|
|
37
|
-
return this._fitOnPage(() => super.addSVG(image, index));
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
addQr(qr, index) {
|
|
41
|
-
return this._fitOnPage(() => super.addQr(qr, index));
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
addAttachment(attachment, index) {
|
|
45
|
-
return this._fitOnPage(() => super.addAttachment(attachment, index));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
|
|
49
|
-
return super.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
beginClip(width, height) {
|
|
53
|
-
return super.beginClip(width, height);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
endClip() {
|
|
57
|
-
return super.endClip();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
this.
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
1
|
+
import ElementWriter from './ElementWriter';
|
|
2
|
+
import { normalizePageSize, normalizePageMargin } from './PageSize';
|
|
3
|
+
import DocumentContext from './DocumentContext';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* An extended ElementWriter which can handle:
|
|
7
|
+
* - page-breaks (it adds new pages when there's not enough space left),
|
|
8
|
+
* - repeatable fragments (like table-headers, which are repeated everytime
|
|
9
|
+
* a page-break occurs)
|
|
10
|
+
* - transactions (used for unbreakable-blocks when we want to make sure
|
|
11
|
+
* whole block will be rendered on the same page)
|
|
12
|
+
*/
|
|
13
|
+
class PageElementWriter extends ElementWriter {
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @param {DocumentContext} context
|
|
17
|
+
*/
|
|
18
|
+
constructor(context) {
|
|
19
|
+
super(context);
|
|
20
|
+
this.transactionLevel = 0;
|
|
21
|
+
this.repeatables = [];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
addLine(line, dontUpdateContextPosition, index) {
|
|
25
|
+
return this._fitOnPage(() => super.addLine(line, dontUpdateContextPosition, index));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
addImage(image, index) {
|
|
29
|
+
return this._fitOnPage(() => super.addImage(image, index));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
addCanvas(image, index) {
|
|
33
|
+
return this._fitOnPage(() => super.addCanvas(image, index));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
addSVG(image, index) {
|
|
37
|
+
return this._fitOnPage(() => super.addSVG(image, index));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
addQr(qr, index) {
|
|
41
|
+
return this._fitOnPage(() => super.addQr(qr, index));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
addAttachment(attachment, index) {
|
|
45
|
+
return this._fitOnPage(() => super.addAttachment(attachment, index));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
addVector(vector, ignoreContextX, ignoreContextY, index, forcePage) {
|
|
49
|
+
return super.addVector(vector, ignoreContextX, ignoreContextY, index, forcePage);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
beginClip(width, height) {
|
|
53
|
+
return super.beginClip(width, height);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
endClip() {
|
|
57
|
+
return super.endClip();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
beginVerticalAlignment(verticalAlignment) {
|
|
61
|
+
return super.beginVerticalAlignment(verticalAlignment);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
endVerticalAlignment(verticalAlignment) {
|
|
65
|
+
return super.endVerticalAlignment(verticalAlignment);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition) {
|
|
69
|
+
return this._fitOnPage(() => super.addFragment(fragment, useBlockXOffset, useBlockYOffset, dontUpdateContextPosition));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
moveToNextPage(pageOrientation) {
|
|
73
|
+
let nextPage = this.context().moveToNextPage(pageOrientation);
|
|
74
|
+
|
|
75
|
+
// moveToNextPage is called multiple times for table, because is called for each column
|
|
76
|
+
// and repeatables are inserted only in the first time. If columns are used, is needed
|
|
77
|
+
// call for table in first column and then for table in the second column (is other repeatables).
|
|
78
|
+
this.repeatables.forEach(function (rep) {
|
|
79
|
+
if (rep.insertedOnPages[this.context().page] === undefined) {
|
|
80
|
+
rep.insertedOnPages[this.context().page] = true;
|
|
81
|
+
this.addFragment(rep, true);
|
|
82
|
+
} else {
|
|
83
|
+
this.context().moveDown(rep.height);
|
|
84
|
+
}
|
|
85
|
+
}, this);
|
|
86
|
+
|
|
87
|
+
this.emit('pageChanged', {
|
|
88
|
+
prevPage: nextPage.prevPage,
|
|
89
|
+
prevY: nextPage.prevY,
|
|
90
|
+
y: this.context().y
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
addPage(pageSize, pageOrientation, pageMargin, customProperties = {}) {
|
|
95
|
+
let prevPage = this.page;
|
|
96
|
+
let prevY = this.y;
|
|
97
|
+
|
|
98
|
+
this.context().addPage(normalizePageSize(pageSize, pageOrientation), normalizePageMargin(pageMargin), customProperties);
|
|
99
|
+
|
|
100
|
+
this.emit('pageChanged', {
|
|
101
|
+
prevPage: prevPage,
|
|
102
|
+
prevY: prevY,
|
|
103
|
+
y: this.context().y
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
beginUnbreakableBlock(width, height) {
|
|
108
|
+
if (this.transactionLevel++ === 0) {
|
|
109
|
+
this.originalX = this.context().x;
|
|
110
|
+
this.pushContext(width, height);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
commitUnbreakableBlock(forcedX, forcedY) {
|
|
115
|
+
if (--this.transactionLevel === 0) {
|
|
116
|
+
let unbreakableContext = this.context();
|
|
117
|
+
this.popContext();
|
|
118
|
+
|
|
119
|
+
let nbPages = unbreakableContext.pages.length;
|
|
120
|
+
if (nbPages > 0) {
|
|
121
|
+
// no support for multi-page unbreakableBlocks
|
|
122
|
+
let fragment = unbreakableContext.pages[0];
|
|
123
|
+
fragment.xOffset = forcedX;
|
|
124
|
+
fragment.yOffset = forcedY;
|
|
125
|
+
|
|
126
|
+
//TODO: vectors can influence height in some situations
|
|
127
|
+
if (nbPages > 1) {
|
|
128
|
+
// on out-of-context blocs (headers, footers, background) height should be the whole DocumentContext height
|
|
129
|
+
if (forcedX !== undefined || forcedY !== undefined) {
|
|
130
|
+
fragment.height = unbreakableContext.getCurrentPage().pageSize.height - unbreakableContext.pageMargins.top - unbreakableContext.pageMargins.bottom;
|
|
131
|
+
} else {
|
|
132
|
+
fragment.height = this.context().getCurrentPage().pageSize.height - this.context().pageMargins.top - this.context().pageMargins.bottom;
|
|
133
|
+
for (let i = 0, l = this.repeatables.length; i < l; i++) {
|
|
134
|
+
fragment.height -= this.repeatables[i].height;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} else {
|
|
138
|
+
fragment.height = unbreakableContext.y;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (forcedX !== undefined || forcedY !== undefined) {
|
|
142
|
+
super.addFragment(fragment, true, true, true);
|
|
143
|
+
} else {
|
|
144
|
+
this.addFragment(fragment);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
currentBlockToRepeatable() {
|
|
151
|
+
let unbreakableContext = this.context();
|
|
152
|
+
let rep = { items: [] };
|
|
153
|
+
|
|
154
|
+
unbreakableContext.pages[0].items.forEach(item => {
|
|
155
|
+
rep.items.push(item);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
rep.xOffset = this.originalX;
|
|
159
|
+
|
|
160
|
+
//TODO: vectors can influence height in some situations
|
|
161
|
+
rep.height = unbreakableContext.y;
|
|
162
|
+
|
|
163
|
+
rep.insertedOnPages = [];
|
|
164
|
+
|
|
165
|
+
return rep;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
pushToRepeatables(rep) {
|
|
169
|
+
this.repeatables.push(rep);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
popFromRepeatables() {
|
|
173
|
+
this.repeatables.pop();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
_fitOnPage(addFct) {
|
|
177
|
+
let position = addFct();
|
|
178
|
+
if (!position) {
|
|
179
|
+
this.moveToNextPage();
|
|
180
|
+
position = addFct();
|
|
181
|
+
}
|
|
182
|
+
return position;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export default PageElementWriter;
|
package/src/PageSize.js
CHANGED
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import sizes from './standardPageSizes';
|
|
2
|
-
import { isString, isNumber } from './helpers/variableType';
|
|
3
|
-
|
|
4
|
-
export function normalizePageSize(pageSize, pageOrientation) {
|
|
5
|
-
function isNeedSwapPageSizes(pageOrientation) {
|
|
6
|
-
if (isString(pageOrientation)) {
|
|
7
|
-
pageOrientation = pageOrientation.toLowerCase();
|
|
8
|
-
return ((pageOrientation === 'portrait') && (size.width > size.height)) ||
|
|
9
|
-
((pageOrientation === 'landscape') && (size.width < size.height));
|
|
10
|
-
}
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function pageSizeToWidthAndHeight(pageSize) {
|
|
15
|
-
if (isString(pageSize)) {
|
|
16
|
-
let size = sizes[pageSize.toUpperCase()];
|
|
17
|
-
if (!size) {
|
|
18
|
-
throw new Error(`Page size ${pageSize} not recognized`);
|
|
19
|
-
}
|
|
20
|
-
return { width: size[0], height: size[1] };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return pageSize;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// if pageSize.height is set to auto, set the height to infinity so there are no page breaks.
|
|
27
|
-
if (pageSize && pageSize.height === 'auto') {
|
|
28
|
-
pageSize.height = Infinity;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
let size = pageSizeToWidthAndHeight(pageSize || 'A4');
|
|
32
|
-
if (isNeedSwapPageSizes(pageOrientation)) { // swap page sizes
|
|
33
|
-
size = { width: size.height, height: size.width };
|
|
34
|
-
}
|
|
35
|
-
size.orientation = size.width > size.height ? 'landscape' : 'portrait';
|
|
36
|
-
return size;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function normalizePageMargin(margin) {
|
|
40
|
-
if (isNumber(margin)) {
|
|
41
|
-
margin = { left: margin, right: margin, top: margin, bottom: margin };
|
|
42
|
-
} else if (Array.isArray(margin)) {
|
|
43
|
-
if (margin.length === 2) {
|
|
44
|
-
margin = { left: margin[0], top: margin[1], right: margin[0], bottom: margin[1] };
|
|
45
|
-
} else if (margin.length === 4) {
|
|
46
|
-
margin = { left: margin[0], top: margin[1], right: margin[2], bottom: margin[3] };
|
|
47
|
-
} else {
|
|
48
|
-
throw new Error('Invalid pageMargins definition');
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return margin;
|
|
53
|
-
}
|
|
1
|
+
import sizes from './standardPageSizes';
|
|
2
|
+
import { isString, isNumber } from './helpers/variableType';
|
|
3
|
+
|
|
4
|
+
export function normalizePageSize(pageSize, pageOrientation) {
|
|
5
|
+
function isNeedSwapPageSizes(pageOrientation) {
|
|
6
|
+
if (isString(pageOrientation)) {
|
|
7
|
+
pageOrientation = pageOrientation.toLowerCase();
|
|
8
|
+
return ((pageOrientation === 'portrait') && (size.width > size.height)) ||
|
|
9
|
+
((pageOrientation === 'landscape') && (size.width < size.height));
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function pageSizeToWidthAndHeight(pageSize) {
|
|
15
|
+
if (isString(pageSize)) {
|
|
16
|
+
let size = sizes[pageSize.toUpperCase()];
|
|
17
|
+
if (!size) {
|
|
18
|
+
throw new Error(`Page size ${pageSize} not recognized`);
|
|
19
|
+
}
|
|
20
|
+
return { width: size[0], height: size[1] };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return pageSize;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// if pageSize.height is set to auto, set the height to infinity so there are no page breaks.
|
|
27
|
+
if (pageSize && pageSize.height === 'auto') {
|
|
28
|
+
pageSize.height = Infinity;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let size = pageSizeToWidthAndHeight(pageSize || 'A4');
|
|
32
|
+
if (isNeedSwapPageSizes(pageOrientation)) { // swap page sizes
|
|
33
|
+
size = { width: size.height, height: size.width };
|
|
34
|
+
}
|
|
35
|
+
size.orientation = size.width > size.height ? 'landscape' : 'portrait';
|
|
36
|
+
return size;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function normalizePageMargin(margin) {
|
|
40
|
+
if (isNumber(margin)) {
|
|
41
|
+
margin = { left: margin, right: margin, top: margin, bottom: margin };
|
|
42
|
+
} else if (Array.isArray(margin)) {
|
|
43
|
+
if (margin.length === 2) {
|
|
44
|
+
margin = { left: margin[0], top: margin[1], right: margin[0], bottom: margin[1] };
|
|
45
|
+
} else if (margin.length === 4) {
|
|
46
|
+
margin = { left: margin[0], top: margin[1], right: margin[2], bottom: margin[3] };
|
|
47
|
+
} else {
|
|
48
|
+
throw new Error('Invalid pageMargins definition');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return margin;
|
|
53
|
+
}
|