pdfmake 0.2.11 → 0.2.12
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 +4 -0
- package/build/pdfmake.js +60 -56
- package/build/pdfmake.js.map +1 -1
- package/build/pdfmake.min.js +2 -2
- package/build/pdfmake.min.js.map +1 -1
- package/package.json +1 -1
- package/src/imageMeasure.js +55 -51
package/package.json
CHANGED
package/src/imageMeasure.js
CHANGED
|
@@ -1,51 +1,55 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var fs = require('fs');
|
|
4
|
-
|
|
5
|
-
function ImageMeasure(pdfKitDoc, imageDictionary) {
|
|
6
|
-
this.pdfKitDoc = pdfKitDoc;
|
|
7
|
-
this.imageDictionary = imageDictionary || {};
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
ImageMeasure.prototype.measureImage = function (src) {
|
|
11
|
-
var image;
|
|
12
|
-
var that = this;
|
|
13
|
-
|
|
14
|
-
if (!this.pdfKitDoc._imageRegistry[src]) {
|
|
15
|
-
try {
|
|
16
|
-
image = this.pdfKitDoc.openImage(realImageSrc(src));
|
|
17
|
-
if (!image) {
|
|
18
|
-
throw 'No image';
|
|
19
|
-
}
|
|
20
|
-
} catch (error) {
|
|
21
|
-
throw 'Invalid image: ' + error.toString() + '\nImages dictionary should contain dataURL entries (or local file paths in node.js)';
|
|
22
|
-
}
|
|
23
|
-
image.embed(this.pdfKitDoc);
|
|
24
|
-
this.pdfKitDoc._imageRegistry[src] = image;
|
|
25
|
-
} else {
|
|
26
|
-
image = this.pdfKitDoc._imageRegistry[src];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return { width: image.width, height: image.height };
|
|
30
|
-
|
|
31
|
-
function realImageSrc(src) {
|
|
32
|
-
var img = that.imageDictionary[src];
|
|
33
|
-
|
|
34
|
-
if (!img) {
|
|
35
|
-
return src;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var fs = require('fs');
|
|
4
|
+
|
|
5
|
+
function ImageMeasure(pdfKitDoc, imageDictionary) {
|
|
6
|
+
this.pdfKitDoc = pdfKitDoc;
|
|
7
|
+
this.imageDictionary = imageDictionary || {};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
ImageMeasure.prototype.measureImage = function (src) {
|
|
11
|
+
var image;
|
|
12
|
+
var that = this;
|
|
13
|
+
|
|
14
|
+
if (!this.pdfKitDoc._imageRegistry[src]) {
|
|
15
|
+
try {
|
|
16
|
+
image = this.pdfKitDoc.openImage(realImageSrc(src));
|
|
17
|
+
if (!image) {
|
|
18
|
+
throw 'No image';
|
|
19
|
+
}
|
|
20
|
+
} catch (error) {
|
|
21
|
+
throw 'Invalid image: ' + error.toString() + '\nImages dictionary should contain dataURL entries (or local file paths in node.js)';
|
|
22
|
+
}
|
|
23
|
+
image.embed(this.pdfKitDoc);
|
|
24
|
+
this.pdfKitDoc._imageRegistry[src] = image;
|
|
25
|
+
} else {
|
|
26
|
+
image = this.pdfKitDoc._imageRegistry[src];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return { width: image.width, height: image.height };
|
|
30
|
+
|
|
31
|
+
function realImageSrc(src) {
|
|
32
|
+
var img = that.imageDictionary[src];
|
|
33
|
+
|
|
34
|
+
if (!img) {
|
|
35
|
+
return src;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (typeof img === 'object') {
|
|
39
|
+
throw 'Not supported image definition: ' + JSON.stringify(img);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (fs.existsSync(img)) {
|
|
43
|
+
return fs.readFileSync(img);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var index = img.indexOf('base64,');
|
|
47
|
+
if (index < 0) {
|
|
48
|
+
return that.imageDictionary[src];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return Buffer.from(img.substring(index + 7), 'base64');
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
module.exports = ImageMeasure;
|