pdfkit 0.2.4 → 0.2.8
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/README.md +3 -2
- package/js/document.js +3 -3
- package/js/font.js +49 -3
- package/js/image/jpeg.js +6 -2
- package/js/image/png.js +6 -2
- package/js/line_wrapper.js +4 -1
- package/js/mixins/text.js +3 -4
- package/js/mixins/vector.js +2 -2
- package/js/object.js +21 -2
- package/js/reference.js +5 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,12 +19,14 @@ Installation uses the [npm](http://npmjs.org/) package manager. Just type the f
|
|
|
19
19
|
* Path operations
|
|
20
20
|
* SVG path parser for easy path creation
|
|
21
21
|
* Transformations
|
|
22
|
+
* Linear and radial gradients
|
|
22
23
|
* Text
|
|
23
24
|
* Line wrapping
|
|
24
25
|
* Text alignments
|
|
25
26
|
* Bulleted lists
|
|
26
27
|
* Font embedding
|
|
27
28
|
* Supports TrueType (.ttf), TrueType Collections (.ttc), and Datafork TrueType (.dfont) fonts
|
|
29
|
+
* Font subsetting
|
|
28
30
|
* Image embedding
|
|
29
31
|
* Supports JPEG and PNG files (including indexed PNGs, and PNGs with transparency)
|
|
30
32
|
* Annotations
|
|
@@ -36,10 +38,9 @@ Installation uses the [npm](http://npmjs.org/) package manager. Just type the f
|
|
|
36
38
|
|
|
37
39
|
## Coming soon!
|
|
38
40
|
|
|
39
|
-
*
|
|
41
|
+
* Patterns fills
|
|
40
42
|
* Outlines
|
|
41
43
|
* PDF Security
|
|
42
|
-
* Font subsetting
|
|
43
44
|
* Higher level APIs for creating tables and laying out content
|
|
44
45
|
* More performance optimizations
|
|
45
46
|
* Even more awesomeness, perhaps written by you! Please fork this repository and send me pull requests.
|
package/js/document.js
CHANGED
|
@@ -127,7 +127,7 @@
|
|
|
127
127
|
_ref = this.info;
|
|
128
128
|
for (key in _ref) {
|
|
129
129
|
val = _ref[key];
|
|
130
|
-
if (typeof val === 'string') this.info[key] = PDFObject.s(val);
|
|
130
|
+
if (typeof val === 'string') this.info[key] = PDFObject.s(val, true);
|
|
131
131
|
}
|
|
132
132
|
return this.embedFonts(function() {
|
|
133
133
|
return _this.embedImages(function() {
|
|
@@ -156,7 +156,7 @@
|
|
|
156
156
|
PDFDocument.prototype.generateBody = function(out, fn) {
|
|
157
157
|
var id, offset, proceed, ref, refs;
|
|
158
158
|
var _this = this;
|
|
159
|
-
offset = out.join('\n').length;
|
|
159
|
+
offset = out.join('\n').length + 1;
|
|
160
160
|
refs = (function() {
|
|
161
161
|
var _ref, _results;
|
|
162
162
|
_ref = this.store.objects;
|
|
@@ -201,7 +201,7 @@
|
|
|
201
201
|
PDFDocument.prototype.generateTrailer = function(out) {
|
|
202
202
|
var trailer;
|
|
203
203
|
trailer = PDFObject.convert({
|
|
204
|
-
Size: this.store.length,
|
|
204
|
+
Size: this.store.length + 1,
|
|
205
205
|
Root: this.store.root,
|
|
206
206
|
Info: this._info
|
|
207
207
|
});
|
package/js/font.js
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
zlib = require('zlib');
|
|
18
18
|
|
|
19
19
|
PDFFont = (function() {
|
|
20
|
-
var toUnicodeCmap;
|
|
20
|
+
var WIN_ANSI_MAP, encodeWinAnsi, toUnicodeCmap;
|
|
21
21
|
|
|
22
22
|
function PDFFont(document, filename, family, id) {
|
|
23
23
|
var _ref;
|
|
@@ -50,9 +50,54 @@
|
|
|
50
50
|
return this.embedTTF(fn);
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
+
WIN_ANSI_MAP = {
|
|
54
|
+
402: 131,
|
|
55
|
+
8211: 150,
|
|
56
|
+
8212: 151,
|
|
57
|
+
8216: 145,
|
|
58
|
+
8217: 146,
|
|
59
|
+
8218: 130,
|
|
60
|
+
8220: 147,
|
|
61
|
+
8221: 148,
|
|
62
|
+
8222: 132,
|
|
63
|
+
8224: 134,
|
|
64
|
+
8225: 135,
|
|
65
|
+
8226: 149,
|
|
66
|
+
8230: 133,
|
|
67
|
+
8364: 128,
|
|
68
|
+
8240: 137,
|
|
69
|
+
8249: 139,
|
|
70
|
+
8250: 155,
|
|
71
|
+
710: 136,
|
|
72
|
+
8482: 153,
|
|
73
|
+
338: 140,
|
|
74
|
+
339: 156,
|
|
75
|
+
732: 152,
|
|
76
|
+
352: 138,
|
|
77
|
+
353: 154,
|
|
78
|
+
376: 159,
|
|
79
|
+
381: 142,
|
|
80
|
+
382: 158
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
encodeWinAnsi = function(text) {
|
|
84
|
+
var char, i, string, _ref;
|
|
85
|
+
string = '';
|
|
86
|
+
for (i = 0, _ref = text.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
|
|
87
|
+
char = text.charCodeAt(i);
|
|
88
|
+
char = WIN_ANSI_MAP[char] || char;
|
|
89
|
+
string += String.fromCharCode(char);
|
|
90
|
+
}
|
|
91
|
+
return string;
|
|
92
|
+
};
|
|
93
|
+
|
|
53
94
|
PDFFont.prototype.encode = function(text) {
|
|
54
95
|
var _ref;
|
|
55
|
-
|
|
96
|
+
if (this.isAFM) {
|
|
97
|
+
return encodeWinAnsi(text);
|
|
98
|
+
} else {
|
|
99
|
+
return ((_ref = this.subset) != null ? _ref.encodeText(text) : void 0) || text;
|
|
100
|
+
}
|
|
56
101
|
};
|
|
57
102
|
|
|
58
103
|
PDFFont.prototype.registerTTF = function() {
|
|
@@ -202,7 +247,8 @@
|
|
|
202
247
|
return this.ref = this.document.ref({
|
|
203
248
|
Type: 'Font',
|
|
204
249
|
BaseFont: this.filename,
|
|
205
|
-
Subtype: 'Type1'
|
|
250
|
+
Subtype: 'Type1',
|
|
251
|
+
Encoding: 'WinAnsiEncoding'
|
|
206
252
|
});
|
|
207
253
|
};
|
|
208
254
|
|
package/js/image/jpeg.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
(function() {
|
|
2
|
-
var Data, JPEG, fs;
|
|
2
|
+
var Data, JPEG, fs, setImmediate;
|
|
3
3
|
var __hasProp = Object.prototype.hasOwnProperty, __indexOf = Array.prototype.indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (__hasProp.call(this, i) && this[i] === item) return i; } return -1; };
|
|
4
4
|
|
|
5
5
|
fs = require('fs');
|
|
6
6
|
|
|
7
7
|
Data = '../data';
|
|
8
8
|
|
|
9
|
+
setImmediate = setImmediate != null ? setImmediate : process.nextTick;
|
|
10
|
+
|
|
9
11
|
JPEG = (function() {
|
|
10
12
|
|
|
11
13
|
function JPEG(data) {
|
|
@@ -54,7 +56,9 @@
|
|
|
54
56
|
obj.data['Decode'] = [1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0];
|
|
55
57
|
}
|
|
56
58
|
obj.add(this.data.data);
|
|
57
|
-
return
|
|
59
|
+
return setImmediate(function() {
|
|
60
|
+
return fn(obj);
|
|
61
|
+
});
|
|
58
62
|
};
|
|
59
63
|
|
|
60
64
|
return JPEG;
|
package/js/image/png.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
(function() {
|
|
2
|
-
var PNG, PNGImage, zlib;
|
|
2
|
+
var PNG, PNGImage, setImmediate, zlib;
|
|
3
3
|
|
|
4
4
|
zlib = require('zlib');
|
|
5
5
|
|
|
6
6
|
PNG = require('png-js');
|
|
7
7
|
|
|
8
|
+
setImmediate = setImmediate != null ? setImmediate : process.nextTick;
|
|
9
|
+
|
|
8
10
|
PNGImage = (function() {
|
|
9
11
|
|
|
10
12
|
function PNGImage(data) {
|
|
@@ -84,7 +86,9 @@
|
|
|
84
86
|
obj.data['SMask'] = sMask;
|
|
85
87
|
}
|
|
86
88
|
obj.add(this.imgData);
|
|
87
|
-
return
|
|
89
|
+
return setImmediate(function() {
|
|
90
|
+
return fn(obj);
|
|
91
|
+
});
|
|
88
92
|
};
|
|
89
93
|
|
|
90
94
|
PNGImage.prototype.splitAlphaChannel = function(fn) {
|
package/js/line_wrapper.js
CHANGED
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
this.lineWidth = (options.width - (this.columnGap * (this.columns - 1))) / this.columns;
|
|
46
46
|
this.startY = this.document.y;
|
|
47
47
|
this.column = 1;
|
|
48
|
-
this.maxY = this.startY + options.height
|
|
48
|
+
this.maxY = this.startY + options.height;
|
|
49
49
|
nextY = this.document.y + this.document.currentLineHeight(true);
|
|
50
50
|
if (this.document.y > this.maxY || nextY > this.maxY) this.nextSection();
|
|
51
51
|
wordWidths = {};
|
|
@@ -86,12 +86,15 @@
|
|
|
86
86
|
};
|
|
87
87
|
|
|
88
88
|
LineWrapper.prototype.nextSection = function(options) {
|
|
89
|
+
var x;
|
|
89
90
|
this.emit('sectionEnd', options, this);
|
|
90
91
|
if (++this.column > this.columns) {
|
|
92
|
+
x = this.document.x;
|
|
91
93
|
this.document.addPage();
|
|
92
94
|
this.column = 1;
|
|
93
95
|
this.startY = this.document.page.margins.top;
|
|
94
96
|
this.maxY = this.document.page.maxY();
|
|
97
|
+
this.document.x = x;
|
|
95
98
|
this.emit('pageBreak', options, this);
|
|
96
99
|
} else {
|
|
97
100
|
this.document.x += this.lineWidth + this.columnGap;
|
package/js/mixins/text.js
CHANGED
|
@@ -123,10 +123,9 @@
|
|
|
123
123
|
}
|
|
124
124
|
return opts;
|
|
125
125
|
})();
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
} else {
|
|
126
|
+
if (x != null) this.x = x;
|
|
127
|
+
if (y != null) this.y = y;
|
|
128
|
+
if (options.lineBreak !== false) {
|
|
130
129
|
margins = this.page.margins;
|
|
131
130
|
if ((_ref = options.width) == null) {
|
|
132
131
|
options.width = this.page.width - this.x - margins.right;
|
package/js/mixins/vector.js
CHANGED
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
return this.addContent("" + m + " M");
|
|
48
48
|
},
|
|
49
49
|
dash: function(length, options) {
|
|
50
|
-
var phase, space;
|
|
50
|
+
var phase, space, _ref;
|
|
51
51
|
if (options == null) options = {};
|
|
52
52
|
if (length == null) return this;
|
|
53
|
-
space = options.space
|
|
53
|
+
space = (_ref = options.space) != null ? _ref : length;
|
|
54
54
|
phase = options.phase || 0;
|
|
55
55
|
return this.addContent("[" + length + " " + space + "] " + phase + " d");
|
|
56
56
|
},
|
package/js/object.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
var PDFObject, PDFReference;
|
|
9
9
|
|
|
10
10
|
PDFObject = (function() {
|
|
11
|
-
var pad;
|
|
11
|
+
var pad, swapBytes;
|
|
12
12
|
|
|
13
13
|
function PDFObject() {}
|
|
14
14
|
|
|
@@ -50,8 +50,27 @@
|
|
|
50
50
|
}
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
swapBytes = function(buff) {
|
|
54
|
+
var a, i, l, _ref;
|
|
55
|
+
l = buff.length;
|
|
56
|
+
if (l & 0x01) {
|
|
57
|
+
throw new Error("Buffer length must be even");
|
|
58
|
+
} else {
|
|
59
|
+
for (i = 0, _ref = l - 1; i < _ref; i += 2) {
|
|
60
|
+
a = buff[i];
|
|
61
|
+
buff[i] = buff[i + 1];
|
|
62
|
+
buff[i + 1] = a;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return buff;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
PDFObject.s = function(string, swap) {
|
|
69
|
+
if (swap == null) swap = false;
|
|
54
70
|
string = string.replace(/\\/g, '\\\\\\\\').replace(/\(/g, '\\(').replace(/\)/g, '\\)').replace(/</g, '<').replace(/>/g, '>').replace(/&/g, '&');
|
|
71
|
+
if (swap) {
|
|
72
|
+
string = swapBytes(new Buffer('\ufeff' + string, 'ucs-2')).toString('binary');
|
|
73
|
+
}
|
|
55
74
|
return {
|
|
56
75
|
isString: true,
|
|
57
76
|
toString: function() {
|
package/js/reference.js
CHANGED
|
@@ -5,10 +5,12 @@
|
|
|
5
5
|
By Devon Govett
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
var PDFObject, PDFReference, zlib;
|
|
8
|
+
var PDFObject, PDFReference, setImmediate, zlib;
|
|
9
9
|
|
|
10
10
|
zlib = require('zlib');
|
|
11
11
|
|
|
12
|
+
setImmediate = setImmediate != null ? setImmediate : process.nextTick;
|
|
13
|
+
|
|
12
14
|
PDFReference = (function() {
|
|
13
15
|
|
|
14
16
|
function PDFReference(id, data) {
|
|
@@ -69,11 +71,11 @@
|
|
|
69
71
|
} else {
|
|
70
72
|
this.finalizedStream = data;
|
|
71
73
|
this.data.Length = this.finalizedStream.length;
|
|
72
|
-
return fn
|
|
74
|
+
return setImmediate(fn);
|
|
73
75
|
}
|
|
74
76
|
} else {
|
|
75
77
|
this.finalizedStream = '';
|
|
76
|
-
return fn
|
|
78
|
+
return setImmediate(fn);
|
|
77
79
|
}
|
|
78
80
|
};
|
|
79
81
|
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "pdfkit",
|
|
3
3
|
"description": "A PDF generation library for Node.js",
|
|
4
4
|
"keywords": ["pdf", "pdf writer", "pdf generator", "graphics", "document", "vector"],
|
|
5
|
-
"version": "0.2.
|
|
5
|
+
"version": "0.2.8",
|
|
6
6
|
"homepage": "http://pdfkit.org/",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Devon Govett",
|