pdfmake 0.3.0-beta.1 → 0.3.0-beta.10
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 +61 -1
- package/LICENSE +1 -1
- package/README.md +3 -1
- package/build/pdfmake.js +65039 -73250
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/build/vfs_fonts.js +4 -4
- package/eslint.config.mjs +52 -0
- package/fonts/Roboto/Roboto-Italic.ttf +0 -0
- package/fonts/Roboto/Roboto-Medium.ttf +0 -0
- package/fonts/Roboto/Roboto-MediumItalic.ttf +0 -0
- package/fonts/Roboto/Roboto-Regular.ttf +0 -0
- package/js/3rd-party/svg-to-pdfkit/source.js +247 -922
- package/js/3rd-party/svg-to-pdfkit.js +2 -6
- package/js/DocMeasure.js +24 -148
- package/js/DocPreprocessor.js +8 -55
- package/js/DocumentContext.js +44 -62
- package/js/ElementWriter.js +38 -73
- package/js/LayoutBuilder.js +225 -177
- package/js/Line.js +7 -27
- package/js/OutputDocument.js +6 -16
- package/js/OutputDocumentServer.js +2 -9
- package/js/PDFDocument.js +24 -43
- package/js/PageElementWriter.js +12 -33
- package/js/PageSize.js +3 -17
- package/js/Printer.js +102 -49
- package/js/Renderer.js +37 -95
- package/js/SVGMeasure.js +3 -23
- package/js/StyleContextStack.js +13 -55
- package/js/TableProcessor.js +58 -124
- package/js/TextBreaker.js +4 -47
- package/js/TextDecorator.js +3 -41
- package/js/TextInlines.js +10 -52
- package/js/URLResolver.js +18 -24
- package/js/base.js +3 -20
- package/js/browser-extensions/OutputDocumentBrowser.js +7 -20
- package/js/browser-extensions/URLBrowserResolver.js +7 -20
- package/js/browser-extensions/fonts/Roboto.js +0 -4
- package/js/browser-extensions/index.js +2 -19
- package/js/browser-extensions/pdfMake.js +0 -14
- package/js/browser-extensions/standard-fonts/Courier.js +0 -4
- package/js/browser-extensions/standard-fonts/Helvetica.js +0 -4
- package/js/browser-extensions/standard-fonts/Symbol.js +0 -4
- package/js/browser-extensions/standard-fonts/Times.js +0 -4
- package/js/browser-extensions/standard-fonts/ZapfDingbats.js +0 -4
- package/js/columnCalculator.js +30 -24
- package/js/helpers/node.js +3 -27
- package/js/helpers/tools.js +0 -8
- package/js/helpers/variableType.js +15 -8
- package/js/index.js +0 -6
- package/js/qrEnc.js +133 -222
- package/js/standardPageSizes.js +2 -3
- package/js/tableLayouts.js +4 -33
- package/js/virtual-fs.js +4 -21
- package/package.json +25 -22
- package/src/DocMeasure.js +19 -6
- package/src/DocPreprocessor.js +6 -0
- package/src/DocumentContext.js +35 -20
- package/src/ElementWriter.js +41 -4
- package/src/LayoutBuilder.js +201 -18
- package/src/OutputDocument.js +1 -1
- package/src/PDFDocument.js +27 -1
- package/src/PageElementWriter.js +4 -0
- package/src/Printer.js +93 -7
- package/src/Renderer.js +35 -0
- package/src/StyleContextStack.js +3 -44
- package/src/TableProcessor.js +27 -5
- package/src/TextDecorator.js +1 -1
- package/src/URLResolver.js +16 -8
- package/src/browser-extensions/URLBrowserResolver.js +6 -3
- package/src/browser-extensions/index.js +1 -1
- package/src/browser-extensions/pdfMake.js +0 -14
- package/src/columnCalculator.js +24 -3
- package/src/helpers/variableType.js +11 -0
- package/src/qrEnc.js +5 -3
package/js/base.js
CHANGED
|
@@ -2,27 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
|
|
6
5
|
var _Printer = _interopRequireDefault(require("./Printer"));
|
|
7
|
-
|
|
8
6
|
var _virtualFs = _interopRequireDefault(require("./virtual-fs"));
|
|
9
|
-
|
|
10
7
|
var _tools = require("./helpers/tools");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
9
|
class pdfmake {
|
|
15
10
|
constructor() {
|
|
16
11
|
this.virtualfs = _virtualFs.default;
|
|
17
12
|
this.urlResolver = null;
|
|
18
13
|
}
|
|
14
|
+
|
|
19
15
|
/**
|
|
20
16
|
* @param {object} docDefinition
|
|
21
17
|
* @param {?object} options
|
|
22
18
|
* @returns {object}
|
|
23
19
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
20
|
createPdf(docDefinition, options = {}) {
|
|
27
21
|
options.progressCallback = this.progressCallback;
|
|
28
22
|
options.tableLayouts = this.tableLayouts;
|
|
@@ -30,40 +24,29 @@ class pdfmake {
|
|
|
30
24
|
const pdfDocumentPromise = printer.createPdfKitDocument(docDefinition, options);
|
|
31
25
|
return this._transformToDocument(pdfDocumentPromise);
|
|
32
26
|
}
|
|
33
|
-
|
|
34
27
|
setProgressCallback(callback) {
|
|
35
28
|
this.progressCallback = callback;
|
|
36
29
|
}
|
|
37
|
-
|
|
38
30
|
addTableLayouts(tableLayouts) {
|
|
39
31
|
this.tableLayouts = (0, _tools.pack)(this.tableLayouts, tableLayouts);
|
|
40
32
|
}
|
|
41
|
-
|
|
42
33
|
setTableLayouts(tableLayouts) {
|
|
43
34
|
this.tableLayouts = tableLayouts;
|
|
44
35
|
}
|
|
45
|
-
|
|
46
36
|
clearTableLayouts() {
|
|
47
37
|
this.tableLayouts = {};
|
|
48
38
|
}
|
|
49
|
-
|
|
50
39
|
addFonts(fonts) {
|
|
51
40
|
this.fonts = (0, _tools.pack)(this.fonts, fonts);
|
|
52
41
|
}
|
|
53
|
-
|
|
54
42
|
setFonts(fonts) {
|
|
55
43
|
this.fonts = fonts;
|
|
56
44
|
}
|
|
57
|
-
|
|
58
45
|
clearFonts() {
|
|
59
46
|
this.fonts = {};
|
|
60
47
|
}
|
|
61
|
-
|
|
62
48
|
_transformToDocument(doc) {
|
|
63
49
|
return doc;
|
|
64
50
|
}
|
|
65
|
-
|
|
66
51
|
}
|
|
67
|
-
|
|
68
|
-
var _default = pdfmake;
|
|
69
|
-
exports.default = _default;
|
|
52
|
+
var _default = exports.default = pdfmake;
|
|
@@ -2,13 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
|
|
6
5
|
var _OutputDocument = _interopRequireDefault(require("../OutputDocument"));
|
|
7
|
-
|
|
8
6
|
var _fileSaver = require("file-saver");
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
7
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
8
|
/**
|
|
13
9
|
* @returns {Window}
|
|
14
10
|
*/
|
|
@@ -16,14 +12,11 @@ const openWindow = () => {
|
|
|
16
12
|
// we have to open the window immediately and store the reference
|
|
17
13
|
// otherwise popup blockers will stop us
|
|
18
14
|
let win = window.open('', '_blank');
|
|
19
|
-
|
|
20
15
|
if (win === null) {
|
|
21
16
|
throw new Error('Open PDF in new window blocked by browser');
|
|
22
17
|
}
|
|
23
|
-
|
|
24
18
|
return win;
|
|
25
19
|
};
|
|
26
|
-
|
|
27
20
|
class OutputDocumentBrowser extends _OutputDocument.default {
|
|
28
21
|
/**
|
|
29
22
|
* @returns {Promise<Blob>}
|
|
@@ -44,12 +37,11 @@ class OutputDocumentBrowser extends _OutputDocument.default {
|
|
|
44
37
|
});
|
|
45
38
|
});
|
|
46
39
|
}
|
|
40
|
+
|
|
47
41
|
/**
|
|
48
42
|
* @param {string} filename
|
|
49
43
|
* @returns {Promise}
|
|
50
44
|
*/
|
|
51
|
-
|
|
52
|
-
|
|
53
45
|
download(filename = 'file.pdf') {
|
|
54
46
|
return new Promise((resolve, reject) => {
|
|
55
47
|
this.getBlob().then(blob => {
|
|
@@ -64,24 +56,23 @@ class OutputDocumentBrowser extends _OutputDocument.default {
|
|
|
64
56
|
});
|
|
65
57
|
});
|
|
66
58
|
}
|
|
59
|
+
|
|
67
60
|
/**
|
|
68
61
|
* @param {Window} win
|
|
69
62
|
* @returns {Promise}
|
|
70
63
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
64
|
open(win = null) {
|
|
74
65
|
return new Promise((resolve, reject) => {
|
|
75
66
|
if (!win) {
|
|
76
67
|
win = openWindow();
|
|
77
68
|
}
|
|
78
|
-
|
|
79
69
|
this.getBlob().then(blob => {
|
|
80
70
|
try {
|
|
81
71
|
let urlCreator = window.URL || window.webkitURL;
|
|
82
72
|
let pdfUrl = urlCreator.createObjectURL(blob);
|
|
83
|
-
win.location.href = pdfUrl;
|
|
73
|
+
win.location.href = pdfUrl;
|
|
84
74
|
|
|
75
|
+
//
|
|
85
76
|
resolve();
|
|
86
77
|
/* temporarily disabled
|
|
87
78
|
if (win === window) {
|
|
@@ -104,12 +95,11 @@ class OutputDocumentBrowser extends _OutputDocument.default {
|
|
|
104
95
|
});
|
|
105
96
|
});
|
|
106
97
|
}
|
|
98
|
+
|
|
107
99
|
/**
|
|
108
100
|
* @param {Window} win
|
|
109
101
|
* @returns {Promise}
|
|
110
102
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
103
|
print(win = null) {
|
|
114
104
|
return new Promise((resolve, reject) => {
|
|
115
105
|
this.getStream().then(stream => {
|
|
@@ -124,8 +114,5 @@ class OutputDocumentBrowser extends _OutputDocument.default {
|
|
|
124
114
|
});
|
|
125
115
|
});
|
|
126
116
|
}
|
|
127
|
-
|
|
128
117
|
}
|
|
129
|
-
|
|
130
|
-
var _default = OutputDocumentBrowser;
|
|
131
|
-
exports.default = _default;
|
|
118
|
+
var _default = exports.default = OutputDocumentBrowser;
|
|
@@ -2,62 +2,54 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
|
|
6
|
-
const fetchUrl = url => {
|
|
5
|
+
const fetchUrl = (url, headers = {}) => {
|
|
7
6
|
return new Promise((resolve, reject) => {
|
|
8
7
|
const xhr = new XMLHttpRequest();
|
|
9
8
|
xhr.open('GET', url, true);
|
|
9
|
+
for (let headerName in headers) {
|
|
10
|
+
xhr.setRequestHeader(headerName, headers[headerName]);
|
|
11
|
+
}
|
|
10
12
|
xhr.responseType = 'arraybuffer';
|
|
11
|
-
|
|
12
13
|
xhr.onreadystatechange = () => {
|
|
13
14
|
if (xhr.readyState !== 4) {
|
|
14
15
|
return;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
17
|
const ok = xhr.status >= 200 && xhr.status < 300;
|
|
18
|
-
|
|
19
18
|
if (!ok) {
|
|
20
19
|
setTimeout(() => {
|
|
21
20
|
reject(new TypeError(`Failed to fetch (url: "${url}")`));
|
|
22
21
|
}, 0);
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
|
-
|
|
26
24
|
xhr.onload = () => {
|
|
27
25
|
const ok = xhr.status >= 200 && xhr.status < 300;
|
|
28
|
-
|
|
29
26
|
if (ok) {
|
|
30
27
|
resolve(xhr.response);
|
|
31
28
|
}
|
|
32
29
|
};
|
|
33
|
-
|
|
34
30
|
xhr.onerror = () => {
|
|
35
31
|
setTimeout(() => {
|
|
36
32
|
reject(new TypeError(`Network request failed (url: "${url}")`));
|
|
37
33
|
}, 0);
|
|
38
34
|
};
|
|
39
|
-
|
|
40
35
|
xhr.ontimeout = () => {
|
|
41
36
|
setTimeout(() => {
|
|
42
37
|
reject(new TypeError(`Network request failed (url: "${url}")`));
|
|
43
38
|
}, 0);
|
|
44
39
|
};
|
|
45
|
-
|
|
46
40
|
xhr.send();
|
|
47
41
|
});
|
|
48
42
|
};
|
|
49
|
-
|
|
50
43
|
class URLBrowserResolver {
|
|
51
44
|
constructor(fs) {
|
|
52
45
|
this.fs = fs;
|
|
53
46
|
this.resolving = {};
|
|
54
47
|
}
|
|
55
|
-
|
|
56
|
-
resolve(url) {
|
|
48
|
+
resolve(url, headers = {}) {
|
|
57
49
|
if (!this.resolving[url]) {
|
|
58
50
|
this.resolving[url] = new Promise((resolve, reject) => {
|
|
59
51
|
if (url.toLowerCase().indexOf('https://') === 0 || url.toLowerCase().indexOf('http://') === 0) {
|
|
60
|
-
fetchUrl(url).then(buffer => {
|
|
52
|
+
fetchUrl(url, headers).then(buffer => {
|
|
61
53
|
this.fs.writeFileSync(url, buffer);
|
|
62
54
|
resolve();
|
|
63
55
|
}, result => {
|
|
@@ -69,10 +61,8 @@ class URLBrowserResolver {
|
|
|
69
61
|
}
|
|
70
62
|
});
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
return this.resolving[url];
|
|
74
65
|
}
|
|
75
|
-
|
|
76
66
|
resolved() {
|
|
77
67
|
return new Promise((resolve, reject) => {
|
|
78
68
|
Promise.all(Object.values(this.resolving)).then(() => {
|
|
@@ -82,8 +72,5 @@ class URLBrowserResolver {
|
|
|
82
72
|
});
|
|
83
73
|
});
|
|
84
74
|
}
|
|
85
|
-
|
|
86
75
|
}
|
|
87
|
-
|
|
88
|
-
var _default = URLBrowserResolver;
|
|
89
|
-
exports.default = _default;
|
|
76
|
+
var _default = exports.default = URLBrowserResolver;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
|
-
|
|
5
4
|
var fontContainer = {
|
|
6
5
|
vfs: {
|
|
7
6
|
'Roboto-Regular.ttf': {
|
|
@@ -30,13 +29,10 @@ var fontContainer = {
|
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
|
|
34
32
|
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
35
|
-
|
|
36
33
|
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
37
34
|
_global.pdfMake.addFontContainer(fontContainer);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
if (typeof module !== 'undefined') {
|
|
41
37
|
module.exports = fontContainer;
|
|
42
38
|
}
|
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
|
|
6
5
|
var _base = _interopRequireDefault(require("../base"));
|
|
7
|
-
|
|
8
6
|
var _OutputDocumentBrowser = _interopRequireDefault(require("./OutputDocumentBrowser"));
|
|
9
|
-
|
|
10
7
|
var _URLBrowserResolver = _interopRequireDefault(require("./URLBrowserResolver"));
|
|
11
|
-
|
|
12
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
13
|
-
|
|
14
9
|
var _configurator = _interopRequireDefault(require("core-js/configurator"));
|
|
15
|
-
|
|
16
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
-
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
11
|
// core-js: Polyfills will be used only if natives completely unavailable.
|
|
19
12
|
(0, _configurator.default)({
|
|
20
13
|
useNative: ['Promise']
|
|
@@ -27,25 +20,21 @@ let defaultClientFonts = {
|
|
|
27
20
|
bolditalics: 'Roboto-MediumItalic.ttf'
|
|
28
21
|
}
|
|
29
22
|
};
|
|
30
|
-
|
|
31
23
|
class pdfmake extends _base.default {
|
|
32
24
|
constructor() {
|
|
33
25
|
super();
|
|
34
26
|
this.urlResolver = new _URLBrowserResolver.default(this.virtualfs);
|
|
35
27
|
this.fonts = defaultClientFonts;
|
|
36
28
|
}
|
|
37
|
-
|
|
38
29
|
addFontContainer(fontContainer) {
|
|
39
30
|
this.addVirtualFileSystem(fontContainer.vfs);
|
|
40
31
|
this.addFonts(fontContainer.fonts);
|
|
41
32
|
}
|
|
42
|
-
|
|
43
33
|
addVirtualFileSystem(vfs) {
|
|
44
34
|
for (let key in vfs) {
|
|
45
35
|
if (vfs.hasOwnProperty(key)) {
|
|
46
36
|
let data;
|
|
47
37
|
let encoding;
|
|
48
|
-
|
|
49
38
|
if (typeof vfs[key] === 'object') {
|
|
50
39
|
data = vfs[key].data;
|
|
51
40
|
encoding = vfs[key].encoding || 'base64';
|
|
@@ -53,18 +42,12 @@ class pdfmake extends _base.default {
|
|
|
53
42
|
data = vfs[key];
|
|
54
43
|
encoding = 'base64';
|
|
55
44
|
}
|
|
56
|
-
|
|
57
45
|
_fs.default.writeFileSync(key, data, encoding);
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
48
|
}
|
|
61
|
-
|
|
62
49
|
_transformToDocument(doc) {
|
|
63
50
|
return new _OutputDocumentBrowser.default(doc);
|
|
64
51
|
}
|
|
65
|
-
|
|
66
52
|
}
|
|
67
|
-
|
|
68
|
-
var _default = new pdfmake();
|
|
69
|
-
|
|
70
|
-
exports.default = _default;
|
|
53
|
+
var _default = exports.default = new pdfmake();
|
|
@@ -1,17 +1,3 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const isBrowserSupported = () => {
|
|
4
|
-
if (typeof window === 'undefined' || typeof window.navigator === 'undefined') {
|
|
5
|
-
// Enviroment is not browser.
|
|
6
|
-
return true;
|
|
7
|
-
} // Internet Explorer 10 and older is not supported.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return window.navigator.userAgent.indexOf("MSIE") === -1;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
if (!isBrowserSupported()) {
|
|
14
|
-
throw new Error('pdfmake: Internet Explorer 10 and older is not supported. Upgrade to version 11 or use modern browser.');
|
|
15
|
-
}
|
|
16
|
-
|
|
17
3
|
module.exports = require('./index').default;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
|
-
|
|
5
4
|
var fontContainer = {
|
|
6
5
|
vfs: {
|
|
7
6
|
'data/Courier.afm': {
|
|
@@ -30,13 +29,10 @@ var fontContainer = {
|
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
|
|
34
32
|
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
35
|
-
|
|
36
33
|
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
37
34
|
_global.pdfMake.addFontContainer(fontContainer);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
if (typeof module !== 'undefined') {
|
|
41
37
|
module.exports = fontContainer;
|
|
42
38
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
|
-
|
|
5
4
|
var fontContainer = {
|
|
6
5
|
vfs: {
|
|
7
6
|
'data/Helvetica.afm': {
|
|
@@ -30,13 +29,10 @@ var fontContainer = {
|
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
|
|
34
32
|
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
35
|
-
|
|
36
33
|
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
37
34
|
_global.pdfMake.addFontContainer(fontContainer);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
if (typeof module !== 'undefined') {
|
|
41
37
|
module.exports = fontContainer;
|
|
42
38
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
|
-
|
|
5
4
|
var fontContainer = {
|
|
6
5
|
vfs: {
|
|
7
6
|
'data/Symbol.afm': {
|
|
@@ -15,13 +14,10 @@ var fontContainer = {
|
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
};
|
|
18
|
-
|
|
19
17
|
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
20
|
-
|
|
21
18
|
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
22
19
|
_global.pdfMake.addFontContainer(fontContainer);
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
if (typeof module !== 'undefined') {
|
|
26
22
|
module.exports = fontContainer;
|
|
27
23
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
|
-
|
|
5
4
|
var fontContainer = {
|
|
6
5
|
vfs: {
|
|
7
6
|
'data/Times-Roman.afm': {
|
|
@@ -30,13 +29,10 @@ var fontContainer = {
|
|
|
30
29
|
}
|
|
31
30
|
}
|
|
32
31
|
};
|
|
33
|
-
|
|
34
32
|
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
35
|
-
|
|
36
33
|
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
37
34
|
_global.pdfMake.addFontContainer(fontContainer);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
if (typeof module !== 'undefined') {
|
|
41
37
|
module.exports = fontContainer;
|
|
42
38
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var fs = require('fs');
|
|
4
|
-
|
|
5
4
|
var fontContainer = {
|
|
6
5
|
vfs: {
|
|
7
6
|
'data/ZapfDingbats.afm': {
|
|
@@ -15,13 +14,10 @@ var fontContainer = {
|
|
|
15
14
|
}
|
|
16
15
|
}
|
|
17
16
|
};
|
|
18
|
-
|
|
19
17
|
var _global = typeof window === 'object' ? window : typeof global === 'object' ? global : typeof self === 'object' ? self : void 0;
|
|
20
|
-
|
|
21
18
|
if (typeof _global.pdfMake !== 'undefined' && typeof _global.pdfMake.addFontContainer !== 'undefined') {
|
|
22
19
|
_global.pdfMake.addFontContainer(fontContainer);
|
|
23
20
|
}
|
|
24
|
-
|
|
25
21
|
if (typeof module !== 'undefined') {
|
|
26
22
|
module.exports = fontContainer;
|
|
27
23
|
}
|
package/js/columnCalculator.js
CHANGED
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
|
|
6
5
|
var _variableType = require("./helpers/variableType");
|
|
7
|
-
|
|
8
|
-
function buildColumnWidths(columns, availableWidth) {
|
|
6
|
+
function buildColumnWidths(columns, availableWidth, offsetTotal = 0, tableNode) {
|
|
9
7
|
let autoColumns = [];
|
|
10
8
|
let autoMin = 0;
|
|
11
9
|
let autoMax = 0;
|
|
@@ -27,26 +25,43 @@ function buildColumnWidths(columns, availableWidth) {
|
|
|
27
25
|
fixedColumns.push(column);
|
|
28
26
|
}
|
|
29
27
|
});
|
|
30
|
-
fixedColumns.forEach(col => {
|
|
28
|
+
fixedColumns.forEach((col, colIndex) => {
|
|
31
29
|
// width specified as %
|
|
32
30
|
if ((0, _variableType.isString)(col.width) && /\d+%/.test(col.width)) {
|
|
33
|
-
|
|
31
|
+
// In tables we have to take into consideration the reserved width for paddings and borders
|
|
32
|
+
let reservedWidth = 0;
|
|
33
|
+
if (tableNode) {
|
|
34
|
+
const paddingLeft = tableNode._layout.paddingLeft(colIndex, tableNode);
|
|
35
|
+
const paddingRight = tableNode._layout.paddingRight(colIndex, tableNode);
|
|
36
|
+
const borderLeft = tableNode._layout.vLineWidth(colIndex, tableNode);
|
|
37
|
+
const borderRight = tableNode._layout.vLineWidth(colIndex + 1, tableNode);
|
|
38
|
+
if (colIndex === 0) {
|
|
39
|
+
// first column assumes whole borderLeft and half of border right
|
|
40
|
+
reservedWidth = paddingLeft + paddingRight + borderLeft + borderRight / 2;
|
|
41
|
+
} else if (colIndex === fixedColumns.length - 1) {
|
|
42
|
+
// last column assumes whole borderRight and half of border left
|
|
43
|
+
reservedWidth = paddingLeft + paddingRight + borderLeft / 2 + borderRight;
|
|
44
|
+
} else {
|
|
45
|
+
// Columns in the middle assume half of each border
|
|
46
|
+
reservedWidth = paddingLeft + paddingRight + borderLeft / 2 + borderRight / 2;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const totalAvailableWidth = initial_availableWidth + offsetTotal;
|
|
50
|
+
col.width = parseFloat(col.width) * totalAvailableWidth / 100 - reservedWidth;
|
|
34
51
|
}
|
|
35
|
-
|
|
36
52
|
if (col.width < col._minWidth && col.elasticWidth) {
|
|
37
53
|
col._calcWidth = col._minWidth;
|
|
38
54
|
} else {
|
|
39
55
|
col._calcWidth = col.width;
|
|
40
56
|
}
|
|
41
|
-
|
|
42
57
|
availableWidth -= col._calcWidth;
|
|
43
|
-
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// http://www.freesoft.org/CIE/RFC/1942/18.htm
|
|
44
61
|
// http://www.w3.org/TR/CSS2/tables.html#width-layout
|
|
45
62
|
// http://dev.w3.org/csswg/css3-tables-algorithms/Overview.src.htm
|
|
46
|
-
|
|
47
63
|
let minW = autoMin + starMaxMin * starColumns.length;
|
|
48
64
|
let maxW = autoMax + starMaxMax * starColumns.length;
|
|
49
|
-
|
|
50
65
|
if (minW >= availableWidth) {
|
|
51
66
|
// case 1 - there's no way to fit all columns within available width
|
|
52
67
|
// that's actually pretty bad situation with PDF as we have no horizontal scroll
|
|
@@ -75,7 +90,6 @@ function buildColumnWidths(columns, availableWidth) {
|
|
|
75
90
|
availableWidth -= col._calcWidth;
|
|
76
91
|
});
|
|
77
92
|
}
|
|
78
|
-
|
|
79
93
|
if (starColumns.length > 0) {
|
|
80
94
|
let starSize = availableWidth / starColumns.length;
|
|
81
95
|
starColumns.forEach(col => {
|
|
@@ -84,16 +98,14 @@ function buildColumnWidths(columns, availableWidth) {
|
|
|
84
98
|
}
|
|
85
99
|
}
|
|
86
100
|
}
|
|
87
|
-
|
|
88
101
|
function isAutoColumn(column) {
|
|
89
102
|
return column.width === 'auto';
|
|
90
103
|
}
|
|
91
|
-
|
|
92
104
|
function isStarColumn(column) {
|
|
93
105
|
return column.width === null || column.width === undefined || column.width === '*' || column.width === 'star';
|
|
94
|
-
}
|
|
95
|
-
|
|
106
|
+
}
|
|
96
107
|
|
|
108
|
+
//TODO: refactor and reuse in measureTable
|
|
97
109
|
function measureMinMax(columns) {
|
|
98
110
|
let result = {
|
|
99
111
|
min: 0,
|
|
@@ -104,10 +116,8 @@ function measureMinMax(columns) {
|
|
|
104
116
|
max: 0
|
|
105
117
|
};
|
|
106
118
|
let starCount = 0;
|
|
107
|
-
|
|
108
119
|
for (let i = 0, l = columns.length; i < l; i++) {
|
|
109
120
|
let c = columns[i];
|
|
110
|
-
|
|
111
121
|
if (isStarColumn(c)) {
|
|
112
122
|
maxStar.min = Math.max(maxStar.min, c._minWidth);
|
|
113
123
|
maxStar.max = Math.max(maxStar.max, c._maxWidth);
|
|
@@ -120,23 +130,19 @@ function measureMinMax(columns) {
|
|
|
120
130
|
result.max += c.width !== undefined && c.width || c._maxWidth;
|
|
121
131
|
}
|
|
122
132
|
}
|
|
123
|
-
|
|
124
133
|
if (starCount) {
|
|
125
134
|
result.min += starCount * maxStar.min;
|
|
126
135
|
result.max += starCount * maxStar.max;
|
|
127
136
|
}
|
|
128
|
-
|
|
129
137
|
return result;
|
|
130
138
|
}
|
|
139
|
+
|
|
131
140
|
/**
|
|
132
141
|
* Calculates column widths
|
|
133
142
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var _default = {
|
|
143
|
+
var _default = exports.default = {
|
|
137
144
|
buildColumnWidths: buildColumnWidths,
|
|
138
145
|
measureMinMax: measureMinMax,
|
|
139
146
|
isAutoColumn: isAutoColumn,
|
|
140
147
|
isStarColumn: isStarColumn
|
|
141
|
-
};
|
|
142
|
-
exports.default = _default;
|
|
148
|
+
};
|