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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pdfmake",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "Client/server side PDF printing in pure JavaScript",
5
5
  "main": "src/printer.js",
6
6
  "browser": "build/pdfmake.js",
@@ -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 (fs.existsSync(img)) {
39
- return fs.readFileSync(img);
40
- }
41
-
42
- var index = img.indexOf('base64,');
43
- if (index < 0) {
44
- return that.imageDictionary[src];
45
- }
46
-
47
- return Buffer.from(img.substring(index + 7), 'base64');
48
- }
49
- };
50
-
51
- module.exports = ImageMeasure;
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;