pdfmake 0.3.0-beta.5 → 0.3.0-beta.7
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 +14 -0
- package/LICENSE +1 -1
- package/build/pdfmake.js +64098 -63969
- 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 +5 -6
- 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 +0 -2
- package/js/3rd-party/svg-to-pdfkit.js +1 -2
- package/js/DocMeasure.js +4 -2
- package/js/DocPreprocessor.js +1 -2
- package/js/DocumentContext.js +1 -2
- package/js/ElementWriter.js +1 -2
- package/js/LayoutBuilder.js +1 -2
- package/js/Line.js +1 -2
- package/js/OutputDocument.js +11 -12
- package/js/OutputDocumentServer.js +1 -2
- package/js/PDFDocument.js +1 -2
- package/js/PageElementWriter.js +1 -2
- package/js/Printer.js +2 -2
- package/js/Renderer.js +1 -2
- package/js/SVGMeasure.js +1 -2
- package/js/StyleContextStack.js +1 -3
- package/js/TableProcessor.js +4 -2
- package/js/TextBreaker.js +1 -2
- package/js/TextDecorator.js +2 -3
- package/js/TextInlines.js +1 -2
- package/js/URLResolver.js +1 -2
- package/js/base.js +1 -2
- package/js/browser-extensions/OutputDocumentBrowser.js +1 -2
- package/js/browser-extensions/URLBrowserResolver.js +1 -2
- package/js/browser-extensions/index.js +1 -2
- package/js/columnCalculator.js +2 -3
- package/js/qrEnc.js +7 -7
- package/js/standardPageSizes.js +2 -3
- package/js/tableLayouts.js +3 -5
- package/js/virtual-fs.js +1 -2
- package/package.json +22 -21
- package/src/DocMeasure.js +3 -0
- package/src/OutputDocument.js +78 -78
- package/src/Printer.js +1 -0
- package/src/TableProcessor.js +4 -0
- package/src/TextDecorator.js +1 -1
- package/src/qrEnc.js +5 -3
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -2722,7 +2722,6 @@ var SVGtoPDF = function (doc, svg, x, y, options) {
|
|
|
2722
2722
|
}
|
|
2723
2723
|
r2 = Math.max(r2, d * multiplier * (1 + 1e-6)); // fix for edge-case gradients see issue #84
|
|
2724
2724
|
}
|
|
2725
|
-
|
|
2726
2725
|
if (spread === 'reflect' || spread === 'repeat') {
|
|
2727
2726
|
let inv = inverseMatrix(matrix),
|
|
2728
2727
|
corner1 = transformPoint([bBox[0], bBox[1]], inv),
|
|
@@ -2740,7 +2739,6 @@ var SVGtoPDF = function (doc, svg, x, y, options) {
|
|
|
2740
2739
|
nBefore = Math.ceil(nBefore + 0.5);
|
|
2741
2740
|
nTotal = nBefore + 1 + nAfter; // How many times the gradient needs to be repeated to fill the object bounding box
|
|
2742
2741
|
}
|
|
2743
|
-
|
|
2744
2742
|
if (this.name === 'linearGradient') {
|
|
2745
2743
|
grad = doc.linearGradient(x1 - nBefore * (x2 - x1), y1 - nBefore * (y2 - y1), x2 + nAfter * (x2 - x1), y2 + nAfter * (y2 - y1));
|
|
2746
2744
|
} else {
|
|
@@ -4,5 +4,4 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.default = void 0;
|
|
5
5
|
var _source = _interopRequireDefault(require("./svg-to-pdfkit/source.js"));
|
|
6
6
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7
|
-
var _default = _source.default;
|
|
8
|
-
exports.default = _default;
|
|
7
|
+
var _default = exports.default = _source.default;
|
package/js/DocMeasure.js
CHANGED
|
@@ -77,6 +77,9 @@ class DocMeasure {
|
|
|
77
77
|
let factor = dimensions.width / dimensions.height > node.fit[0] / node.fit[1] ? node.fit[0] / dimensions.width : node.fit[1] / dimensions.height;
|
|
78
78
|
node._width = node._minWidth = node._maxWidth = dimensions.width * factor;
|
|
79
79
|
node._height = dimensions.height * factor;
|
|
80
|
+
} else if (node.cover) {
|
|
81
|
+
node._width = node._minWidth = node._maxWidth = node.cover.width;
|
|
82
|
+
node._height = node._minHeight = node._maxHeight = node.cover.height;
|
|
80
83
|
} else {
|
|
81
84
|
node._width = node._minWidth = node._maxWidth = node.width || dimensions.width;
|
|
82
85
|
node._height = node.height || dimensions.height * node._width / dimensions.width;
|
|
@@ -621,5 +624,4 @@ class DocMeasure {
|
|
|
621
624
|
return node;
|
|
622
625
|
}
|
|
623
626
|
}
|
|
624
|
-
var _default = DocMeasure;
|
|
625
|
-
exports.default = _default;
|
|
627
|
+
var _default = exports.default = DocMeasure;
|
package/js/DocPreprocessor.js
CHANGED
package/js/DocumentContext.js
CHANGED
package/js/ElementWriter.js
CHANGED
package/js/LayoutBuilder.js
CHANGED
package/js/Line.js
CHANGED
package/js/OutputDocument.js
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
5
|
class OutputDocument {
|
|
6
|
-
/**
|
|
7
|
-
* @param {Promise<object>} pdfDocumentPromise
|
|
6
|
+
/**
|
|
7
|
+
* @param {Promise<object>} pdfDocumentPromise
|
|
8
8
|
*/
|
|
9
9
|
constructor(pdfDocumentPromise) {
|
|
10
10
|
this.bufferSize = 1073741824;
|
|
@@ -12,15 +12,15 @@ class OutputDocument {
|
|
|
12
12
|
this.bufferPromise = null;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
/**
|
|
16
|
-
* @returns {Promise<object>}
|
|
15
|
+
/**
|
|
16
|
+
* @returns {Promise<object>}
|
|
17
17
|
*/
|
|
18
18
|
getStream() {
|
|
19
19
|
return this.pdfDocumentPromise;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
/**
|
|
23
|
-
* @returns {Promise<Buffer>}
|
|
22
|
+
/**
|
|
23
|
+
* @returns {Promise<Buffer>}
|
|
24
24
|
*/
|
|
25
25
|
getBuffer() {
|
|
26
26
|
if (this.bufferPromise === null) {
|
|
@@ -47,8 +47,8 @@ class OutputDocument {
|
|
|
47
47
|
return this.bufferPromise;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
51
|
-
* @returns {Promise<string>}
|
|
50
|
+
/**
|
|
51
|
+
* @returns {Promise<string>}
|
|
52
52
|
*/
|
|
53
53
|
getBase64() {
|
|
54
54
|
return new Promise((resolve, reject) => {
|
|
@@ -60,8 +60,8 @@ class OutputDocument {
|
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
/**
|
|
64
|
-
* @returns {Promise<string>}
|
|
63
|
+
/**
|
|
64
|
+
* @returns {Promise<string>}
|
|
65
65
|
*/
|
|
66
66
|
getDataUrl() {
|
|
67
67
|
return new Promise((resolve, reject) => {
|
|
@@ -73,5 +73,4 @@ class OutputDocument {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
-
var _default = OutputDocument;
|
|
77
|
-
exports.default = _default;
|
|
76
|
+
var _default = exports.default = OutputDocument;
|
package/js/PDFDocument.js
CHANGED
package/js/PageElementWriter.js
CHANGED
package/js/Printer.js
CHANGED
|
@@ -63,6 +63,7 @@ class PdfPrinter {
|
|
|
63
63
|
userPassword: docDefinition.userPassword,
|
|
64
64
|
ownerPassword: docDefinition.ownerPassword,
|
|
65
65
|
permissions: docDefinition.permissions,
|
|
66
|
+
lang: docDefinition.language,
|
|
66
67
|
fontLayoutCache: typeof options.fontLayoutCache === 'boolean' ? options.fontLayoutCache : true,
|
|
67
68
|
bufferPages: options.bufferPages || false,
|
|
68
69
|
autoFirstPage: false,
|
|
@@ -287,5 +288,4 @@ function calculatePageHeight(pages, margins) {
|
|
|
287
288
|
height += fixedMargins.bottom;
|
|
288
289
|
return height;
|
|
289
290
|
}
|
|
290
|
-
var _default = PdfPrinter;
|
|
291
|
-
exports.default = _default;
|
|
291
|
+
var _default = exports.default = PdfPrinter;
|
package/js/Renderer.js
CHANGED
package/js/SVGMeasure.js
CHANGED
package/js/StyleContextStack.js
CHANGED
|
@@ -83,7 +83,6 @@ class StyleContextStack {
|
|
|
83
83
|
// 'evenRowCellBorder',
|
|
84
84
|
// 'tableBorder'
|
|
85
85
|
];
|
|
86
|
-
|
|
87
86
|
let styleOverrideObject = {};
|
|
88
87
|
let pushStyleOverrideObject = false;
|
|
89
88
|
styleProperties.forEach(key => {
|
|
@@ -178,5 +177,4 @@ class StyleContextStack {
|
|
|
178
177
|
return destination;
|
|
179
178
|
}
|
|
180
179
|
}
|
|
181
|
-
var _default = StyleContextStack;
|
|
182
|
-
exports.default = _default;
|
|
180
|
+
var _default = exports.default = StyleContextStack;
|
package/js/TableProcessor.js
CHANGED
|
@@ -97,6 +97,9 @@ class TableProcessor {
|
|
|
97
97
|
this.rowSpanData = prepareRowSpanData();
|
|
98
98
|
this.cleanUpRepeatables = false;
|
|
99
99
|
this.headerRows = tableNode.table.headerRows || 0;
|
|
100
|
+
if (this.headerRows > tableNode.table.body.length) {
|
|
101
|
+
throw new Error(`Too few rows in the table. Property headerRows requires at least ${this.headerRows}, contains only ${tableNode.table.body.length}`);
|
|
102
|
+
}
|
|
100
103
|
this.rowsWithoutPageBreak = this.headerRows + (tableNode.table.keepWithHeaderRows || 0);
|
|
101
104
|
this.dontBreakRows = tableNode.table.dontBreakRows || false;
|
|
102
105
|
if (this.rowsWithoutPageBreak) {
|
|
@@ -505,5 +508,4 @@ class TableProcessor {
|
|
|
505
508
|
}
|
|
506
509
|
}
|
|
507
510
|
}
|
|
508
|
-
var _default = TableProcessor;
|
|
509
|
-
exports.default = _default;
|
|
511
|
+
var _default = exports.default = TableProcessor;
|
package/js/TextBreaker.js
CHANGED
package/js/TextDecorator.js
CHANGED
|
@@ -97,7 +97,7 @@ class TextDecorator {
|
|
|
97
97
|
y += lineAscent - ascent * 0.25;
|
|
98
98
|
break;
|
|
99
99
|
default:
|
|
100
|
-
throw new Error(`
|
|
100
|
+
throw new Error(`Unknown decoration : ${group.decoration}`);
|
|
101
101
|
}
|
|
102
102
|
this.pdfDocument.save();
|
|
103
103
|
if (group.decorationStyle === 'double') {
|
|
@@ -140,5 +140,4 @@ class TextDecorator {
|
|
|
140
140
|
this.pdfDocument.restore();
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
var _default = TextDecorator;
|
|
144
|
-
exports.default = _default;
|
|
143
|
+
var _default = exports.default = TextDecorator;
|
package/js/TextInlines.js
CHANGED
package/js/URLResolver.js
CHANGED
package/js/base.js
CHANGED
package/js/columnCalculator.js
CHANGED
|
@@ -121,10 +121,9 @@ function measureMinMax(columns) {
|
|
|
121
121
|
/**
|
|
122
122
|
* Calculates column widths
|
|
123
123
|
*/
|
|
124
|
-
var _default = {
|
|
124
|
+
var _default = exports.default = {
|
|
125
125
|
buildColumnWidths: buildColumnWidths,
|
|
126
126
|
measureMinMax: measureMinMax,
|
|
127
127
|
isAutoColumn: isAutoColumn,
|
|
128
128
|
isStarColumn: isStarColumn
|
|
129
|
-
};
|
|
130
|
-
exports.default = _default;
|
|
129
|
+
};
|
package/js/qrEnc.js
CHANGED
|
@@ -483,7 +483,6 @@ var putformatinfo = function (matrix, reserved, ecclevel, mask) {
|
|
|
483
483
|
// we don't have to mark those bits reserved; always done
|
|
484
484
|
// in makebasematrix above.
|
|
485
485
|
}
|
|
486
|
-
|
|
487
486
|
return matrix;
|
|
488
487
|
};
|
|
489
488
|
|
|
@@ -675,11 +674,13 @@ function buildCanvas(data, options) {
|
|
|
675
674
|
var canvas = [];
|
|
676
675
|
var background = options.background || '#fff';
|
|
677
676
|
var foreground = options.foreground || '#000';
|
|
677
|
+
var padding = options.padding || 0;
|
|
678
678
|
//var margin = options.margin || 4;
|
|
679
679
|
var matrix = generateFrame(data, options);
|
|
680
680
|
var n = matrix.length;
|
|
681
681
|
var modSize = Math.floor(options.fit ? options.fit / n : 5);
|
|
682
|
-
var size = n * modSize;
|
|
682
|
+
var size = n * modSize + modSize * padding * 2;
|
|
683
|
+
var paddingXY = modSize * padding;
|
|
683
684
|
canvas.push({
|
|
684
685
|
type: 'rect',
|
|
685
686
|
x: 0,
|
|
@@ -694,8 +695,8 @@ function buildCanvas(data, options) {
|
|
|
694
695
|
if (matrix[i][j]) {
|
|
695
696
|
canvas.push({
|
|
696
697
|
type: 'rect',
|
|
697
|
-
x: modSize * j,
|
|
698
|
-
y: modSize * i,
|
|
698
|
+
x: modSize * j + paddingXY,
|
|
699
|
+
y: modSize * i + paddingXY,
|
|
699
700
|
w: modSize,
|
|
700
701
|
h: modSize,
|
|
701
702
|
lineWidth: 0,
|
|
@@ -715,7 +716,6 @@ function measure(node) {
|
|
|
715
716
|
node._width = node._height = node._minWidth = node._maxWidth = node._minHeight = node._maxHeight = cd.size;
|
|
716
717
|
return node;
|
|
717
718
|
}
|
|
718
|
-
var _default = {
|
|
719
|
+
var _default = exports.default = {
|
|
719
720
|
measure: measure
|
|
720
|
-
};
|
|
721
|
-
exports.default = _default;
|
|
721
|
+
};
|
package/js/standardPageSizes.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
4
|
exports.default = void 0;
|
|
5
|
-
var _default = {
|
|
5
|
+
var _default = exports.default = {
|
|
6
6
|
'4A0': [4767.87, 6740.79],
|
|
7
7
|
'2A0': [3370.39, 4767.87],
|
|
8
8
|
A0: [2383.94, 3370.39],
|
|
@@ -53,5 +53,4 @@ var _default = {
|
|
|
53
53
|
LEGAL: [612.00, 1008.00],
|
|
54
54
|
LETTER: [612.00, 792.00],
|
|
55
55
|
TABLOID: [792.00, 1224.00]
|
|
56
|
-
};
|
|
57
|
-
exports.default = _default;
|
|
56
|
+
};
|
package/js/tableLayouts.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.__esModule = true;
|
|
|
4
4
|
exports.tableLayouts = exports.defaultTableLayout = void 0;
|
|
5
5
|
/*eslint no-unused-vars: ["error", {"args": "none"}]*/
|
|
6
6
|
|
|
7
|
-
const tableLayouts = {
|
|
7
|
+
const tableLayouts = exports.tableLayouts = {
|
|
8
8
|
noBorders: {
|
|
9
9
|
hLineWidth(i) {
|
|
10
10
|
return 0;
|
|
@@ -57,8 +57,7 @@ const tableLayouts = {
|
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
};
|
|
60
|
-
exports.
|
|
61
|
-
const defaultTableLayout = {
|
|
60
|
+
const defaultTableLayout = exports.defaultTableLayout = {
|
|
62
61
|
hLineWidth(i, node) {
|
|
63
62
|
return 1;
|
|
64
63
|
},
|
|
@@ -96,5 +95,4 @@ const defaultTableLayout = {
|
|
|
96
95
|
return 1;
|
|
97
96
|
},
|
|
98
97
|
defaultBorder: true
|
|
99
|
-
};
|
|
100
|
-
exports.defaultTableLayout = defaultTableLayout;
|
|
98
|
+
};
|
package/js/virtual-fs.js
CHANGED
|
@@ -57,5 +57,4 @@ class VirtualFileSystem {
|
|
|
57
57
|
this.storage[normalizedFilename] = encoding || typeof content === 'string' ? new Buffer(content, encoding) : content;
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
|
-
var _default = new VirtualFileSystem();
|
|
61
|
-
exports.default = _default;
|
|
60
|
+
var _default = exports.default = new VirtualFileSystem();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pdfmake",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.7",
|
|
4
4
|
"description": "Client/server side PDF printing in pure JavaScript",
|
|
5
5
|
"main": "js/index.js",
|
|
6
6
|
"esnext": "src/index.js",
|
|
@@ -10,42 +10,43 @@
|
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@foliojs-fork/linebreak": "^1.1.1",
|
|
13
|
-
"@foliojs-fork/pdfkit": "^0.
|
|
13
|
+
"@foliojs-fork/pdfkit": "^0.14.0",
|
|
14
14
|
"iconv-lite": "^0.6.3",
|
|
15
|
-
"xmldoc": "^1.
|
|
15
|
+
"xmldoc": "^1.3.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
|
-
"@babel/cli": "^7.
|
|
19
|
-
"@babel/core": "^7.
|
|
20
|
-
"@babel/plugin-transform-modules-commonjs": "^7.
|
|
21
|
-
"@babel/preset-env": "^7.
|
|
22
|
-
"assert": "^2.
|
|
23
|
-
"babel-loader": "^
|
|
18
|
+
"@babel/cli": "^7.23.4",
|
|
19
|
+
"@babel/core": "^7.23.6",
|
|
20
|
+
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
|
|
21
|
+
"@babel/preset-env": "^7.23.6",
|
|
22
|
+
"assert": "^2.1.0",
|
|
23
|
+
"babel-loader": "^9.1.3",
|
|
24
24
|
"brfs": "^2.0.2",
|
|
25
25
|
"browserify-zlib": "^0.2.0",
|
|
26
26
|
"buffer": "6.0.3",
|
|
27
27
|
"core-js": "3.19.0",
|
|
28
|
-
"eslint": "^8.
|
|
29
|
-
"eslint-plugin-jsdoc": "^
|
|
30
|
-
"expose-loader": "^
|
|
28
|
+
"eslint": "^8.55.0",
|
|
29
|
+
"eslint-plugin-jsdoc": "^46.9.1",
|
|
30
|
+
"expose-loader": "^4.1.0",
|
|
31
31
|
"file-saver": "^2.0.5",
|
|
32
|
-
"mocha": "^
|
|
32
|
+
"mocha": "^10.2.0",
|
|
33
33
|
"npm-run-all": "^4.1.5",
|
|
34
34
|
"process": "^0.11.10",
|
|
35
|
-
"rewire": "^
|
|
36
|
-
"shx": "^0.3.
|
|
37
|
-
"sinon": "^
|
|
35
|
+
"rewire": "^7.0.0",
|
|
36
|
+
"shx": "^0.3.4",
|
|
37
|
+
"sinon": "^17.0.1",
|
|
38
|
+
"source-map-loader": "^4.0.1",
|
|
38
39
|
"stream-browserify": "^3.0.0",
|
|
39
40
|
"string-replace-webpack-plugin": "^0.1.3",
|
|
40
41
|
"svg-to-pdfkit": "^0.1.8",
|
|
41
|
-
"terser-webpack-plugin": "^5.3.
|
|
42
|
+
"terser-webpack-plugin": "^5.3.9",
|
|
42
43
|
"transform-loader": "^0.2.4",
|
|
43
|
-
"util": "^0.12.
|
|
44
|
-
"webpack": "^5.
|
|
45
|
-
"webpack-cli": "^
|
|
44
|
+
"util": "^0.12.5",
|
|
45
|
+
"webpack": "^5.89.0",
|
|
46
|
+
"webpack-cli": "^5.1.4"
|
|
46
47
|
},
|
|
47
48
|
"engines": {
|
|
48
|
-
"node": ">=
|
|
49
|
+
"node": ">=16"
|
|
49
50
|
},
|
|
50
51
|
"scripts": {
|
|
51
52
|
"test": "run-s build mocha lint",
|
package/src/DocMeasure.js
CHANGED
|
@@ -85,6 +85,9 @@ class DocMeasure {
|
|
|
85
85
|
let factor = (dimensions.width / dimensions.height > node.fit[0] / node.fit[1]) ? node.fit[0] / dimensions.width : node.fit[1] / dimensions.height;
|
|
86
86
|
node._width = node._minWidth = node._maxWidth = dimensions.width * factor;
|
|
87
87
|
node._height = dimensions.height * factor;
|
|
88
|
+
} else if (node.cover) {
|
|
89
|
+
node._width = node._minWidth = node._maxWidth = node.cover.width;
|
|
90
|
+
node._height = node._minHeight = node._maxHeight = node.cover.height;
|
|
88
91
|
} else {
|
|
89
92
|
node._width = node._minWidth = node._maxWidth = node.width || dimensions.width;
|
|
90
93
|
node._height = node.height || (dimensions.height * node._width / dimensions.width);
|
package/src/OutputDocument.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
class OutputDocument {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param {Promise<object>} pdfDocumentPromise
|
|
5
|
-
*/
|
|
6
|
-
constructor(pdfDocumentPromise) {
|
|
7
|
-
this.bufferSize = 1073741824;
|
|
8
|
-
this.pdfDocumentPromise = pdfDocumentPromise;
|
|
9
|
-
this.bufferPromise = null;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @returns {Promise<object>}
|
|
14
|
-
*/
|
|
15
|
-
getStream() {
|
|
16
|
-
return this.pdfDocumentPromise;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* @returns {Promise<Buffer>}
|
|
21
|
-
*/
|
|
22
|
-
getBuffer() {
|
|
23
|
-
if (this.bufferPromise === null) {
|
|
24
|
-
this.bufferPromise = new Promise((resolve, reject) => {
|
|
25
|
-
this.getStream().then(stream => {
|
|
26
|
-
|
|
27
|
-
let chunks = [];
|
|
28
|
-
let result;
|
|
29
|
-
stream.on('readable', () => {
|
|
30
|
-
let chunk;
|
|
31
|
-
while ((chunk = stream.read(this.bufferSize)) !== null) {
|
|
32
|
-
chunks.push(chunk);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
stream.on('end', () => {
|
|
36
|
-
result = Buffer.concat(chunks);
|
|
37
|
-
resolve(result);
|
|
38
|
-
});
|
|
39
|
-
stream.end();
|
|
40
|
-
|
|
41
|
-
}, result => {
|
|
42
|
-
reject(result);
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return this.bufferPromise;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* @returns {Promise<string>}
|
|
52
|
-
*/
|
|
53
|
-
getBase64() {
|
|
54
|
-
return new Promise((resolve, reject) => {
|
|
55
|
-
this.getBuffer().then(buffer => {
|
|
56
|
-
resolve(buffer.toString('base64'));
|
|
57
|
-
}, result => {
|
|
58
|
-
reject(result);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @returns {Promise<string>}
|
|
65
|
-
*/
|
|
66
|
-
getDataUrl() {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
this.getBase64().then(data => {
|
|
69
|
-
resolve('data:application/pdf;base64,' + data);
|
|
70
|
-
}, result => {
|
|
71
|
-
reject(result);
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export default OutputDocument;
|
|
1
|
+
class OutputDocument {
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @param {Promise<object>} pdfDocumentPromise
|
|
5
|
+
*/
|
|
6
|
+
constructor(pdfDocumentPromise) {
|
|
7
|
+
this.bufferSize = 1073741824;
|
|
8
|
+
this.pdfDocumentPromise = pdfDocumentPromise;
|
|
9
|
+
this.bufferPromise = null;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* @returns {Promise<object>}
|
|
14
|
+
*/
|
|
15
|
+
getStream() {
|
|
16
|
+
return this.pdfDocumentPromise;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @returns {Promise<Buffer>}
|
|
21
|
+
*/
|
|
22
|
+
getBuffer() {
|
|
23
|
+
if (this.bufferPromise === null) {
|
|
24
|
+
this.bufferPromise = new Promise((resolve, reject) => {
|
|
25
|
+
this.getStream().then(stream => {
|
|
26
|
+
|
|
27
|
+
let chunks = [];
|
|
28
|
+
let result;
|
|
29
|
+
stream.on('readable', () => {
|
|
30
|
+
let chunk;
|
|
31
|
+
while ((chunk = stream.read(this.bufferSize)) !== null) {
|
|
32
|
+
chunks.push(chunk);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
stream.on('end', () => {
|
|
36
|
+
result = Buffer.concat(chunks);
|
|
37
|
+
resolve(result);
|
|
38
|
+
});
|
|
39
|
+
stream.end();
|
|
40
|
+
|
|
41
|
+
}, result => {
|
|
42
|
+
reject(result);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return this.bufferPromise;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @returns {Promise<string>}
|
|
52
|
+
*/
|
|
53
|
+
getBase64() {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
this.getBuffer().then(buffer => {
|
|
56
|
+
resolve(buffer.toString('base64'));
|
|
57
|
+
}, result => {
|
|
58
|
+
reject(result);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @returns {Promise<string>}
|
|
65
|
+
*/
|
|
66
|
+
getDataUrl() {
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
this.getBase64().then(data => {
|
|
69
|
+
resolve('data:application/pdf;base64,' + data);
|
|
70
|
+
}, result => {
|
|
71
|
+
reject(result);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default OutputDocument;
|