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/PDFDocument.js
CHANGED
|
@@ -1,174 +1,174 @@
|
|
|
1
|
-
import PDFKit from 'pdfkit';
|
|
2
|
-
|
|
3
|
-
const typeName = (bold, italics) => {
|
|
4
|
-
let type = 'normal';
|
|
5
|
-
if (bold && italics) {
|
|
6
|
-
type = 'bolditalics';
|
|
7
|
-
} else if (bold) {
|
|
8
|
-
type = 'bold';
|
|
9
|
-
} else if (italics) {
|
|
10
|
-
type = 'italics';
|
|
11
|
-
}
|
|
12
|
-
return type;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
class PDFDocument extends PDFKit {
|
|
16
|
-
constructor(fonts = {}, images = {}, patterns = {}, attachments = {}, options = {}, virtualfs = null) {
|
|
17
|
-
super(options);
|
|
18
|
-
|
|
19
|
-
this.fonts = {};
|
|
20
|
-
this.fontCache = {};
|
|
21
|
-
for (let font in fonts) {
|
|
22
|
-
if (fonts.hasOwnProperty(font)) {
|
|
23
|
-
let fontDef = fonts[font];
|
|
24
|
-
|
|
25
|
-
this.fonts[font] = {
|
|
26
|
-
normal: fontDef.normal,
|
|
27
|
-
bold: fontDef.bold,
|
|
28
|
-
italics: fontDef.italics,
|
|
29
|
-
bolditalics: fontDef.bolditalics
|
|
30
|
-
};
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
this.images = images;
|
|
44
|
-
this.attachments = attachments;
|
|
45
|
-
this.virtualfs = virtualfs;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getFontType(bold, italics) {
|
|
49
|
-
return typeName(bold, italics);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getFontFile(familyName, bold, italics) {
|
|
53
|
-
let type = this.getFontType(bold, italics);
|
|
54
|
-
if (!this.fonts[familyName] || !this.fonts[familyName][type]) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return this.fonts[familyName][type];
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
provideFont(familyName, bold, italics) {
|
|
62
|
-
let type = this.getFontType(bold, italics);
|
|
63
|
-
if (this.getFontFile(familyName, bold, italics) === null) {
|
|
64
|
-
throw new Error(`Font '${familyName}' in style '${type}' is not defined in the font section of the document definition.`);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.fontCache[familyName] = this.fontCache[familyName] || {};
|
|
68
|
-
|
|
69
|
-
if (!this.fontCache[familyName][type]) {
|
|
70
|
-
let def = this.fonts[familyName][type];
|
|
71
|
-
if (!Array.isArray(def)) {
|
|
72
|
-
def = [def];
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
if (this.virtualfs && this.virtualfs.existsSync(def[0])) {
|
|
76
|
-
def[0] = this.virtualfs.readFileSync(def[0]);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this.fontCache[familyName][type] = this.font(...def)._font;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return this.fontCache[familyName][type];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
provideImage(src) {
|
|
86
|
-
const realImageSrc = src => {
|
|
87
|
-
let image = this.images[src];
|
|
88
|
-
|
|
89
|
-
if (!image) {
|
|
90
|
-
return src;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (this.virtualfs && this.virtualfs.existsSync(image)) {
|
|
94
|
-
return this.virtualfs.readFileSync(image);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
let index = image.indexOf('base64,');
|
|
98
|
-
if (index < 0) {
|
|
99
|
-
return this.images[src];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return Buffer.from(image.substring(index + 7), 'base64');
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
if (this._imageRegistry[src]) {
|
|
106
|
-
return this._imageRegistry[src];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
let image;
|
|
110
|
-
|
|
111
|
-
try {
|
|
112
|
-
image = this.openImage(realImageSrc(src));
|
|
113
|
-
if (!image) {
|
|
114
|
-
throw new Error('No image');
|
|
115
|
-
}
|
|
116
|
-
} catch (error) {
|
|
117
|
-
throw new Error(`Invalid image: ${error.toString()}\nImages dictionary should contain dataURL entries (or local file paths in node.js)`);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
image.embed(this);
|
|
121
|
-
this._imageRegistry[src] = image;
|
|
122
|
-
|
|
123
|
-
return image;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* @param {Array} color pdfmake format: [<pattern name>, <color>]
|
|
128
|
-
* @returns {Array} pdfkit format: [<pattern object>, <color>]
|
|
129
|
-
*/
|
|
130
|
-
providePattern(color) {
|
|
131
|
-
if (Array.isArray(color) && color.length === 2) {
|
|
132
|
-
return [this.patterns[color[0]], color[1]];
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
provideAttachment(src) {
|
|
139
|
-
const checkRequired = obj => {
|
|
140
|
-
if (!obj) {
|
|
141
|
-
throw new Error('No attachment');
|
|
142
|
-
}
|
|
143
|
-
if (!obj.src) {
|
|
144
|
-
throw new Error('The "src" key is required for attachments');
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return obj;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
if (typeof src === 'object') {
|
|
151
|
-
return checkRequired(src);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
let attachment = checkRequired(this.attachments[src]);
|
|
155
|
-
|
|
156
|
-
if (this.virtualfs && this.virtualfs.existsSync(attachment.src)) {
|
|
157
|
-
return this.virtualfs.readFileSync(attachment.src);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return attachment;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
setOpenActionAsPrint() {
|
|
164
|
-
let printActionRef = this.ref({
|
|
165
|
-
Type: 'Action',
|
|
166
|
-
S: 'Named',
|
|
167
|
-
N: 'Print'
|
|
168
|
-
});
|
|
169
|
-
this._root.data.OpenAction = printActionRef;
|
|
170
|
-
printActionRef.end();
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export default PDFDocument;
|
|
1
|
+
import PDFKit from 'pdfkit';
|
|
2
|
+
|
|
3
|
+
const typeName = (bold, italics) => {
|
|
4
|
+
let type = 'normal';
|
|
5
|
+
if (bold && italics) {
|
|
6
|
+
type = 'bolditalics';
|
|
7
|
+
} else if (bold) {
|
|
8
|
+
type = 'bold';
|
|
9
|
+
} else if (italics) {
|
|
10
|
+
type = 'italics';
|
|
11
|
+
}
|
|
12
|
+
return type;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
class PDFDocument extends PDFKit {
|
|
16
|
+
constructor(fonts = {}, images = {}, patterns = {}, attachments = {}, options = {}, virtualfs = null) {
|
|
17
|
+
super(options);
|
|
18
|
+
|
|
19
|
+
this.fonts = {};
|
|
20
|
+
this.fontCache = {};
|
|
21
|
+
for (let font in fonts) {
|
|
22
|
+
if (fonts.hasOwnProperty(font)) {
|
|
23
|
+
let fontDef = fonts[font];
|
|
24
|
+
|
|
25
|
+
this.fonts[font] = {
|
|
26
|
+
normal: fontDef.normal,
|
|
27
|
+
bold: fontDef.bold,
|
|
28
|
+
italics: fontDef.italics,
|
|
29
|
+
bolditalics: fontDef.bolditalics
|
|
30
|
+
};
|
|
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
|
+
|
|
42
|
+
|
|
43
|
+
this.images = images;
|
|
44
|
+
this.attachments = attachments;
|
|
45
|
+
this.virtualfs = virtualfs;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getFontType(bold, italics) {
|
|
49
|
+
return typeName(bold, italics);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getFontFile(familyName, bold, italics) {
|
|
53
|
+
let type = this.getFontType(bold, italics);
|
|
54
|
+
if (!this.fonts[familyName] || !this.fonts[familyName][type]) {
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return this.fonts[familyName][type];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
provideFont(familyName, bold, italics) {
|
|
62
|
+
let type = this.getFontType(bold, italics);
|
|
63
|
+
if (this.getFontFile(familyName, bold, italics) === null) {
|
|
64
|
+
throw new Error(`Font '${familyName}' in style '${type}' is not defined in the font section of the document definition.`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.fontCache[familyName] = this.fontCache[familyName] || {};
|
|
68
|
+
|
|
69
|
+
if (!this.fontCache[familyName][type]) {
|
|
70
|
+
let def = this.fonts[familyName][type];
|
|
71
|
+
if (!Array.isArray(def)) {
|
|
72
|
+
def = [def];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.virtualfs && this.virtualfs.existsSync(def[0])) {
|
|
76
|
+
def[0] = this.virtualfs.readFileSync(def[0]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this.fontCache[familyName][type] = this.font(...def)._font;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return this.fontCache[familyName][type];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
provideImage(src) {
|
|
86
|
+
const realImageSrc = src => {
|
|
87
|
+
let image = this.images[src];
|
|
88
|
+
|
|
89
|
+
if (!image) {
|
|
90
|
+
return src;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (this.virtualfs && this.virtualfs.existsSync(image)) {
|
|
94
|
+
return this.virtualfs.readFileSync(image);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let index = image.indexOf('base64,');
|
|
98
|
+
if (index < 0) {
|
|
99
|
+
return this.images[src];
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return Buffer.from(image.substring(index + 7), 'base64');
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
if (this._imageRegistry[src]) {
|
|
106
|
+
return this._imageRegistry[src];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let image;
|
|
110
|
+
|
|
111
|
+
try {
|
|
112
|
+
image = this.openImage(realImageSrc(src));
|
|
113
|
+
if (!image) {
|
|
114
|
+
throw new Error('No image');
|
|
115
|
+
}
|
|
116
|
+
} catch (error) {
|
|
117
|
+
throw new Error(`Invalid image: ${error.toString()}\nImages dictionary should contain dataURL entries (or local file paths in node.js)`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
image.embed(this);
|
|
121
|
+
this._imageRegistry[src] = image;
|
|
122
|
+
|
|
123
|
+
return image;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @param {Array} color pdfmake format: [<pattern name>, <color>]
|
|
128
|
+
* @returns {Array} pdfkit format: [<pattern object>, <color>]
|
|
129
|
+
*/
|
|
130
|
+
providePattern(color) {
|
|
131
|
+
if (Array.isArray(color) && color.length === 2) {
|
|
132
|
+
return [this.patterns[color[0]], color[1]];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
provideAttachment(src) {
|
|
139
|
+
const checkRequired = obj => {
|
|
140
|
+
if (!obj) {
|
|
141
|
+
throw new Error('No attachment');
|
|
142
|
+
}
|
|
143
|
+
if (!obj.src) {
|
|
144
|
+
throw new Error('The "src" key is required for attachments');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return obj;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
if (typeof src === 'object') {
|
|
151
|
+
return checkRequired(src);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let attachment = checkRequired(this.attachments[src]);
|
|
155
|
+
|
|
156
|
+
if (this.virtualfs && this.virtualfs.existsSync(attachment.src)) {
|
|
157
|
+
return this.virtualfs.readFileSync(attachment.src);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return attachment;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
setOpenActionAsPrint() {
|
|
164
|
+
let printActionRef = this.ref({
|
|
165
|
+
Type: 'Action',
|
|
166
|
+
S: 'Named',
|
|
167
|
+
N: 'Print'
|
|
168
|
+
});
|
|
169
|
+
this._root.data.OpenAction = printActionRef;
|
|
170
|
+
printActionRef.end();
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export default PDFDocument;
|