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/Line.js
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
|
-
class Line {
|
|
2
|
-
/**
|
|
3
|
-
* @param {number} maxWidth Maximum width this line can have
|
|
4
|
-
*/
|
|
5
|
-
constructor(maxWidth) {
|
|
6
|
-
this.maxWidth = maxWidth;
|
|
7
|
-
this.leadingCut = 0;
|
|
8
|
-
this.trailingCut = 0;
|
|
9
|
-
this.inlineWidths = 0;
|
|
10
|
-
this.inlines = [];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {object} inline
|
|
15
|
-
*/
|
|
16
|
-
addInline(inline) {
|
|
17
|
-
if (this.inlines.length === 0) {
|
|
18
|
-
this.leadingCut = inline.leadingCut || 0;
|
|
19
|
-
}
|
|
20
|
-
this.trailingCut = inline.trailingCut || 0;
|
|
21
|
-
|
|
22
|
-
inline.x = this.inlineWidths - this.leadingCut;
|
|
23
|
-
|
|
24
|
-
this.inlines.push(inline);
|
|
25
|
-
this.inlineWidths += inline.width;
|
|
26
|
-
|
|
27
|
-
if (inline.lineEnd) {
|
|
28
|
-
this.newLineForced = true;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* @returns {number}
|
|
34
|
-
*/
|
|
35
|
-
getHeight() {
|
|
36
|
-
let max = 0;
|
|
37
|
-
|
|
38
|
-
this.inlines.forEach(item => {
|
|
39
|
-
max = Math.max(max, item.height || 0);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return max;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @returns {number}
|
|
47
|
-
*/
|
|
48
|
-
getAscenderHeight() {
|
|
49
|
-
let y = 0;
|
|
50
|
-
|
|
51
|
-
this.inlines.forEach(inline => {
|
|
52
|
-
y = Math.max(y, inline.font.ascender / 1000 * inline.fontSize);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return y;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @returns {number}
|
|
60
|
-
*/
|
|
61
|
-
getWidth() {
|
|
62
|
-
return this.inlineWidths - this.leadingCut - this.trailingCut;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* @returns {number}
|
|
67
|
-
*/
|
|
68
|
-
getAvailableWidth() {
|
|
69
|
-
return this.maxWidth - this.getWidth();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* @param {object} inline
|
|
74
|
-
* @param {Array} nextInlines
|
|
75
|
-
* @returns {boolean}
|
|
76
|
-
*/
|
|
77
|
-
hasEnoughSpaceForInline(inline, nextInlines = []) {
|
|
78
|
-
if (this.inlines.length === 0) {
|
|
79
|
-
return true;
|
|
80
|
-
}
|
|
81
|
-
if (this.newLineForced) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
let inlineWidth = inline.width;
|
|
86
|
-
let inlineTrailingCut = inline.trailingCut || 0;
|
|
87
|
-
if (inline.noNewLine) {
|
|
88
|
-
for (let i = 0, l = nextInlines.length; i < l; i++) {
|
|
89
|
-
let nextInline = nextInlines[i];
|
|
90
|
-
inlineWidth += nextInline.width;
|
|
91
|
-
inlineTrailingCut += nextInline.trailingCut || 0;
|
|
92
|
-
if (!nextInline.noNewLine) {
|
|
93
|
-
break;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return (this.inlineWidths + inlineWidth - this.leadingCut - inlineTrailingCut) <= this.maxWidth;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
clone() {
|
|
102
|
-
let result = new Line(this.maxWidth);
|
|
103
|
-
|
|
104
|
-
for (let key in this) {
|
|
105
|
-
if (this.hasOwnProperty(key)) {
|
|
106
|
-
result[key] = this[key];
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return result;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export default Line;
|
|
1
|
+
class Line {
|
|
2
|
+
/**
|
|
3
|
+
* @param {number} maxWidth Maximum width this line can have
|
|
4
|
+
*/
|
|
5
|
+
constructor(maxWidth) {
|
|
6
|
+
this.maxWidth = maxWidth;
|
|
7
|
+
this.leadingCut = 0;
|
|
8
|
+
this.trailingCut = 0;
|
|
9
|
+
this.inlineWidths = 0;
|
|
10
|
+
this.inlines = [];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {object} inline
|
|
15
|
+
*/
|
|
16
|
+
addInline(inline) {
|
|
17
|
+
if (this.inlines.length === 0) {
|
|
18
|
+
this.leadingCut = inline.leadingCut || 0;
|
|
19
|
+
}
|
|
20
|
+
this.trailingCut = inline.trailingCut || 0;
|
|
21
|
+
|
|
22
|
+
inline.x = this.inlineWidths - this.leadingCut;
|
|
23
|
+
|
|
24
|
+
this.inlines.push(inline);
|
|
25
|
+
this.inlineWidths += inline.width;
|
|
26
|
+
|
|
27
|
+
if (inline.lineEnd) {
|
|
28
|
+
this.newLineForced = true;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @returns {number}
|
|
34
|
+
*/
|
|
35
|
+
getHeight() {
|
|
36
|
+
let max = 0;
|
|
37
|
+
|
|
38
|
+
this.inlines.forEach(item => {
|
|
39
|
+
max = Math.max(max, item.height || 0);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
return max;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @returns {number}
|
|
47
|
+
*/
|
|
48
|
+
getAscenderHeight() {
|
|
49
|
+
let y = 0;
|
|
50
|
+
|
|
51
|
+
this.inlines.forEach(inline => {
|
|
52
|
+
y = Math.max(y, inline.font.ascender / 1000 * inline.fontSize);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return y;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @returns {number}
|
|
60
|
+
*/
|
|
61
|
+
getWidth() {
|
|
62
|
+
return this.inlineWidths - this.leadingCut - this.trailingCut;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @returns {number}
|
|
67
|
+
*/
|
|
68
|
+
getAvailableWidth() {
|
|
69
|
+
return this.maxWidth - this.getWidth();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @param {object} inline
|
|
74
|
+
* @param {Array} nextInlines
|
|
75
|
+
* @returns {boolean}
|
|
76
|
+
*/
|
|
77
|
+
hasEnoughSpaceForInline(inline, nextInlines = []) {
|
|
78
|
+
if (this.inlines.length === 0) {
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
if (this.newLineForced) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
let inlineWidth = inline.width;
|
|
86
|
+
let inlineTrailingCut = inline.trailingCut || 0;
|
|
87
|
+
if (inline.noNewLine) {
|
|
88
|
+
for (let i = 0, l = nextInlines.length; i < l; i++) {
|
|
89
|
+
let nextInline = nextInlines[i];
|
|
90
|
+
inlineWidth += nextInline.width;
|
|
91
|
+
inlineTrailingCut += nextInline.trailingCut || 0;
|
|
92
|
+
if (!nextInline.noNewLine) {
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return (this.inlineWidths + inlineWidth - this.leadingCut - inlineTrailingCut) <= this.maxWidth;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
clone() {
|
|
102
|
+
let result = new Line(this.maxWidth);
|
|
103
|
+
|
|
104
|
+
for (let key in this) {
|
|
105
|
+
if (this.hasOwnProperty(key)) {
|
|
106
|
+
result[key] = this[key];
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default Line;
|
package/src/OutputDocument.js
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
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
|
-
const getBufferInternal = (async () => {
|
|
24
|
-
const stream = await this.getStream();
|
|
25
|
-
return new Promise((resolve) => {
|
|
26
|
-
let chunks = [];
|
|
27
|
-
stream.on('readable', () => {
|
|
28
|
-
let chunk;
|
|
29
|
-
while ((chunk = stream.read(this.bufferSize)) !== null) {
|
|
30
|
-
chunks.push(chunk);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
stream.on('end', () => {
|
|
34
|
-
resolve(Buffer.concat(chunks));
|
|
35
|
-
});
|
|
36
|
-
stream.end();
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (this.bufferPromise === null) {
|
|
41
|
-
this.bufferPromise = getBufferInternal();
|
|
42
|
-
}
|
|
43
|
-
return this.bufferPromise;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @returns {Promise<string>}
|
|
48
|
-
*/
|
|
49
|
-
async getBase64() {
|
|
50
|
-
const buffer = await this.getBuffer();
|
|
51
|
-
return buffer.toString('base64');
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @returns {Promise<string>}
|
|
56
|
-
*/
|
|
57
|
-
async getDataUrl() {
|
|
58
|
-
const data = await this.getBase64();
|
|
59
|
-
return 'data:application/pdf;base64,' + data;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
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
|
+
const getBufferInternal = (async () => {
|
|
24
|
+
const stream = await this.getStream();
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
let chunks = [];
|
|
27
|
+
stream.on('readable', () => {
|
|
28
|
+
let chunk;
|
|
29
|
+
while ((chunk = stream.read(this.bufferSize)) !== null) {
|
|
30
|
+
chunks.push(chunk);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
stream.on('end', () => {
|
|
34
|
+
resolve(Buffer.concat(chunks));
|
|
35
|
+
});
|
|
36
|
+
stream.end();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (this.bufferPromise === null) {
|
|
41
|
+
this.bufferPromise = getBufferInternal();
|
|
42
|
+
}
|
|
43
|
+
return this.bufferPromise;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @returns {Promise<string>}
|
|
48
|
+
*/
|
|
49
|
+
async getBase64() {
|
|
50
|
+
const buffer = await this.getBuffer();
|
|
51
|
+
return buffer.toString('base64');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @returns {Promise<string>}
|
|
56
|
+
*/
|
|
57
|
+
async getDataUrl() {
|
|
58
|
+
const data = await this.getBase64();
|
|
59
|
+
return 'data:application/pdf;base64,' + data;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default OutputDocument;
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import OutputDocument from './OutputDocument';
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
|
|
4
|
-
class OutputDocumentServer extends OutputDocument {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @param {string} filename
|
|
8
|
-
* @returns {Promise}
|
|
9
|
-
*/
|
|
10
|
-
async write(filename) {
|
|
11
|
-
const stream = await this.getStream();
|
|
12
|
-
const writeStream = fs.createWriteStream(filename);
|
|
13
|
-
|
|
14
|
-
const streamEnded = new Promise((resolve, reject) => {
|
|
15
|
-
stream.on('end', resolve);
|
|
16
|
-
stream.on('error', reject);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
const writeClosed = new Promise((resolve, reject) => {
|
|
20
|
-
writeStream.on('close', resolve);
|
|
21
|
-
writeStream.on('error', reject);
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
stream.pipe(writeStream);
|
|
25
|
-
stream.end();
|
|
26
|
-
|
|
27
|
-
await Promise.all([streamEnded, writeClosed]);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export default OutputDocumentServer;
|
|
1
|
+
import OutputDocument from './OutputDocument';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
|
|
4
|
+
class OutputDocumentServer extends OutputDocument {
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @param {string} filename
|
|
8
|
+
* @returns {Promise}
|
|
9
|
+
*/
|
|
10
|
+
async write(filename) {
|
|
11
|
+
const stream = await this.getStream();
|
|
12
|
+
const writeStream = fs.createWriteStream(filename);
|
|
13
|
+
|
|
14
|
+
const streamEnded = new Promise((resolve, reject) => {
|
|
15
|
+
stream.on('end', resolve);
|
|
16
|
+
stream.on('error', reject);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const writeClosed = new Promise((resolve, reject) => {
|
|
20
|
+
writeStream.on('close', resolve);
|
|
21
|
+
writeStream.on('error', reject);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
stream.pipe(writeStream);
|
|
25
|
+
stream.end();
|
|
26
|
+
|
|
27
|
+
await Promise.all([streamEnded, writeClosed]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export default OutputDocumentServer;
|