pdfkit 0.8.2 → 0.10.0

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.
Files changed (50) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/LICENSE +7 -7
  3. package/README.md +175 -171
  4. package/js/{font/data → data}/Courier-Bold.afm +342 -342
  5. package/js/{font/data → data}/Courier-BoldOblique.afm +342 -342
  6. package/js/{font/data → data}/Courier-Oblique.afm +342 -342
  7. package/js/{font/data → data}/Courier.afm +342 -342
  8. package/js/{font/data → data}/Helvetica-Bold.afm +2827 -2827
  9. package/js/{font/data → data}/Helvetica-BoldOblique.afm +2827 -2827
  10. package/js/{font/data → data}/Helvetica-Oblique.afm +3051 -3051
  11. package/js/{font/data → data}/Helvetica.afm +3051 -3051
  12. package/js/{font/data → data}/Symbol.afm +213 -213
  13. package/js/{font/data → data}/Times-Bold.afm +2588 -2588
  14. package/js/{font/data → data}/Times-BoldItalic.afm +2384 -2384
  15. package/js/{font/data → data}/Times-Italic.afm +2667 -2667
  16. package/js/{font/data → data}/Times-Roman.afm +2419 -2419
  17. package/js/{font/data → data}/ZapfDingbats.afm +225 -225
  18. package/js/pdfkit.es5.js +5724 -0
  19. package/js/pdfkit.es5.js.map +1 -0
  20. package/js/pdfkit.esnext.js +5144 -0
  21. package/js/pdfkit.esnext.js.map +1 -0
  22. package/js/pdfkit.js +5112 -0
  23. package/js/pdfkit.js.map +1 -0
  24. package/js/pdfkit.standalone.js +68105 -0
  25. package/js/virtual-fs.js +70 -0
  26. package/package.json +85 -55
  27. package/.npmignore +0 -8
  28. package/Makefile +0 -30
  29. package/js/data.js +0 -192
  30. package/js/document.js +0 -247
  31. package/js/font/afm.js +0 -170
  32. package/js/font/data/MustRead.html +0 -19
  33. package/js/font/embedded.js +0 -234
  34. package/js/font/standard.js +0 -124
  35. package/js/font.js +0 -75
  36. package/js/gradient.js +0 -240
  37. package/js/image/jpeg.js +0 -78
  38. package/js/image/png.js +0 -158
  39. package/js/image.js +0 -53
  40. package/js/line_wrapper.js +0 -252
  41. package/js/mixins/annotations.js +0 -133
  42. package/js/mixins/color.js +0 -304
  43. package/js/mixins/fonts.js +0 -69
  44. package/js/mixins/images.js +0 -111
  45. package/js/mixins/text.js +0 -337
  46. package/js/mixins/vector.js +0 -265
  47. package/js/object.js +0 -114
  48. package/js/page.js +0 -170
  49. package/js/path.js +0 -366
  50. package/js/reference.js +0 -109
@@ -0,0 +1,70 @@
1
+ 'use strict';
2
+
3
+ var VirtualFileSystem =
4
+ /*#__PURE__*/
5
+ function () {
6
+ function VirtualFileSystem() {
7
+ this.fileData = {};
8
+ }
9
+
10
+ var _proto = VirtualFileSystem.prototype;
11
+
12
+ _proto.readFileSync = function readFileSync(fileName, options) {
13
+ if (options === void 0) {
14
+ options = {};
15
+ }
16
+
17
+ var encoding = typeof options === 'string' ? options : options.encoding;
18
+ var virtualFileName = normalizeFilename(fileName);
19
+ var data = this.fileData[virtualFileName];
20
+
21
+ if (data == null) {
22
+ throw new Error("File '" + virtualFileName + "' not found in virtual file system");
23
+ }
24
+
25
+ if (encoding) {
26
+ // return a string
27
+ return typeof data === 'string' ? data : data.toString();
28
+ }
29
+
30
+ return new Buffer(data, typeof data === 'string' ? 'base64' : undefined);
31
+ };
32
+
33
+ _proto.writeFileSync = function writeFileSync(fileName, content) {
34
+ this.fileData[normalizeFilename(fileName)] = content;
35
+ };
36
+
37
+ _proto.bindFileData = function bindFileData(data, options) {
38
+ if (data === void 0) {
39
+ data = {};
40
+ }
41
+
42
+ if (options === void 0) {
43
+ options = {};
44
+ }
45
+
46
+ if (options.reset) {
47
+ this.fileData = data;
48
+ } else {
49
+ Object.assign(this.fileData, data);
50
+ }
51
+ };
52
+
53
+ return VirtualFileSystem;
54
+ }();
55
+
56
+ function normalizeFilename(fileName) {
57
+ if (fileName.indexOf(__dirname) === 0) {
58
+ fileName = fileName.substring(__dirname.length);
59
+ }
60
+
61
+ if (fileName.indexOf('/') === 0) {
62
+ fileName = fileName.substring(1);
63
+ }
64
+
65
+ return fileName;
66
+ }
67
+
68
+ var virtualFs = new VirtualFileSystem();
69
+
70
+ module.exports = virtualFs;
package/package.json CHANGED
@@ -1,55 +1,85 @@
1
- {
2
- "name": "pdfkit",
3
- "description": "A PDF generation library for Node.js",
4
- "keywords": [
5
- "pdf",
6
- "pdf writer",
7
- "pdf generator",
8
- "graphics",
9
- "document",
10
- "vector"
11
- ],
12
- "version": "0.8.2",
13
- "homepage": "http://pdfkit.org/",
14
- "author": {
15
- "name": "Devon Govett",
16
- "email": "devongovett@gmail.com",
17
- "url": "http://badassjs.com/"
18
- },
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/devongovett/pdfkit.git"
22
- },
23
- "bugs": "http://github.com/devongovett/pdfkit/issues",
24
- "devDependencies": {
25
- "blob-stream": "^0.1.2",
26
- "brace": "^0.2.1",
27
- "brfs": "~1.0.1",
28
- "browserify": "^3.39.0",
29
- "codemirror": "~3.20.0",
30
- "coffee-script": ">=1.0.1",
31
- "coffeeify": "^0.6.0",
32
- "exorcist": "^0.1.5",
33
- "iconv-lite": "^0.4.13",
34
- "jade": "~1.1.5",
35
- "markdown": "~0.5.0"
36
- },
37
- "dependencies": {
38
- "fontkit": "^1.0.0",
39
- "linebreak": "^0.3.0",
40
- "png-js": ">=0.1.0"
41
- },
42
- "scripts": {
43
- "prepublish": "make js",
44
- "postpublish": "make clean"
45
- },
46
- "main": "js/document",
47
- "browserify": {
48
- "transform": [
49
- "brfs"
50
- ]
51
- },
52
- "engine": [
53
- "node >= v0.10.0"
54
- ]
55
- }
1
+ {
2
+ "name": "pdfkit",
3
+ "description": "A PDF generation library for Node.js",
4
+ "keywords": [
5
+ "pdf",
6
+ "pdf writer",
7
+ "pdf generator",
8
+ "graphics",
9
+ "document",
10
+ "vector"
11
+ ],
12
+ "version": "0.10.0",
13
+ "homepage": "http://pdfkit.org/",
14
+ "author": {
15
+ "name": "Devon Govett",
16
+ "email": "devongovett@gmail.com",
17
+ "url": "http://badassjs.com/"
18
+ },
19
+ "license": "MIT",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "https://github.com/foliojs/pdfkit.git"
23
+ },
24
+ "bugs": "https://github.com/foliojs/pdfkit/issues",
25
+ "devDependencies": {
26
+ "@babel/core": "^7.0.0",
27
+ "@babel/plugin-external-helpers": "^7.0.0",
28
+ "@babel/preset-env": "^7.0.0",
29
+ "babel-jest": "^24.7.1",
30
+ "blob-stream": "^0.1.2",
31
+ "brace": "^0.2.1",
32
+ "brfs": "~2.0.1",
33
+ "browserify": "^16.2.3",
34
+ "codemirror": "~3.20.0",
35
+ "eslint": "^5.3.0",
36
+ "iconv-lite": "^0.4.13",
37
+ "jest": "^24.7.1",
38
+ "markdown": "~0.5.0",
39
+ "prettier": "1.15.3",
40
+ "pug": "^2.0.3",
41
+ "rollup": "^1.11.0",
42
+ "rollup-plugin-babel": "^4.0.1",
43
+ "rollup-plugin-cpy": "^1.0.0"
44
+ },
45
+ "dependencies": {
46
+ "crypto-js": "^3.1.9-1",
47
+ "fontkit": "^1.0.0",
48
+ "linebreak": "^0.3.0",
49
+ "png-js": ">=0.1.0"
50
+ },
51
+ "scripts": {
52
+ "prepublishOnly": "npm run build",
53
+ "build": "rollup -c && browserify --standalone PDFDocument js/pdfkit.js > js/pdfkit.standalone.js",
54
+ "demo": "cd demo && node test.js",
55
+ "browser-demo": "browserify demo/browser.js > demo/bundle.js",
56
+ "pdf-guide": "node docs/generate.js",
57
+ "website": "node docs/generate_website.js",
58
+ "docs": "npm run pdf-guide && npm run website && npm run browser-demo",
59
+ "prettier": "prettier {lib,tests,demo,docs}/**/*.js",
60
+ "test": "jest -i",
61
+ "test:integration": "jest integration/ -i",
62
+ "test:unit": "jest unit/ -i"
63
+ },
64
+ "main": "js/pdfkit.js",
65
+ "module": "js/pdfkit.es5.js",
66
+ "esnext": "js/pdfkit.esnext.js",
67
+ "browserify": {
68
+ "transform": [
69
+ "brfs"
70
+ ]
71
+ },
72
+ "engine": [
73
+ "node >= v6.0.0"
74
+ ],
75
+ "jest": {
76
+ "testPathIgnorePatterns": [
77
+ "/node_modules/",
78
+ "<rootDir>/demo/"
79
+ ],
80
+ "testURL": "http://localhost/",
81
+ "setupFilesAfterEnv": [
82
+ "<rootDir>/tests/unit/setupTests.js"
83
+ ]
84
+ }
85
+ }
package/.npmignore DELETED
@@ -1,8 +0,0 @@
1
- node-zlib/
2
- node-modules/
3
- demo/
4
- src/
5
- lib/
6
- docs/
7
- playground/
8
- index.js
package/Makefile DELETED
@@ -1,30 +0,0 @@
1
- .PHONY: js
2
-
3
- js:
4
- ./node_modules/.bin/coffee -o js -c lib/
5
- cp -r lib/font/data js/font/data
6
-
7
- browser: lib/**/*.coffee
8
- mkdir -p build/
9
- ./node_modules/.bin/browserify \
10
- --standalone PDFDocument \
11
- --debug \
12
- --transform coffeeify \
13
- --extension .coffee \
14
- lib/document.coffee \
15
- | ./node_modules/.bin/exorcist build/pdfkit.js.map > build/pdfkit.js
16
-
17
- browser-demo: js demo/browser.js
18
- ./node_modules/.bin/browserify demo/browser.js > demo/bundle.js
19
-
20
- docs: pdf-guide website browser-demo
21
-
22
- pdf-guide:
23
- ./node_modules/.bin/coffee docs/generate.coffee
24
-
25
- website:
26
- mkdir -p docs/img
27
- ./node_modules/.bin/coffee docs/generate_website.coffee
28
-
29
- clean:
30
- rm -rf js build demo/bundle.js
package/js/data.js DELETED
@@ -1,192 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
- (function() {
3
- var Data;
4
-
5
- Data = (function() {
6
- function Data(data) {
7
- this.data = data != null ? data : [];
8
- this.pos = 0;
9
- this.length = this.data.length;
10
- }
11
-
12
- Data.prototype.readByte = function() {
13
- return this.data[this.pos++];
14
- };
15
-
16
- Data.prototype.writeByte = function(byte) {
17
- return this.data[this.pos++] = byte;
18
- };
19
-
20
- Data.prototype.byteAt = function(index) {
21
- return this.data[index];
22
- };
23
-
24
- Data.prototype.readBool = function() {
25
- return !!this.readByte();
26
- };
27
-
28
- Data.prototype.writeBool = function(val) {
29
- return this.writeByte(val ? 1 : 0);
30
- };
31
-
32
- Data.prototype.readUInt32 = function() {
33
- var b1, b2, b3, b4;
34
- b1 = this.readByte() * 0x1000000;
35
- b2 = this.readByte() << 16;
36
- b3 = this.readByte() << 8;
37
- b4 = this.readByte();
38
- return b1 + b2 + b3 + b4;
39
- };
40
-
41
- Data.prototype.writeUInt32 = function(val) {
42
- this.writeByte((val >>> 24) & 0xff);
43
- this.writeByte((val >> 16) & 0xff);
44
- this.writeByte((val >> 8) & 0xff);
45
- return this.writeByte(val & 0xff);
46
- };
47
-
48
- Data.prototype.readInt32 = function() {
49
- var int;
50
- int = this.readUInt32();
51
- if (int >= 0x80000000) {
52
- return int - 0x100000000;
53
- } else {
54
- return int;
55
- }
56
- };
57
-
58
- Data.prototype.writeInt32 = function(val) {
59
- if (val < 0) {
60
- val += 0x100000000;
61
- }
62
- return this.writeUInt32(val);
63
- };
64
-
65
- Data.prototype.readUInt16 = function() {
66
- var b1, b2;
67
- b1 = this.readByte() << 8;
68
- b2 = this.readByte();
69
- return b1 | b2;
70
- };
71
-
72
- Data.prototype.writeUInt16 = function(val) {
73
- this.writeByte((val >> 8) & 0xff);
74
- return this.writeByte(val & 0xff);
75
- };
76
-
77
- Data.prototype.readInt16 = function() {
78
- var int;
79
- int = this.readUInt16();
80
- if (int >= 0x8000) {
81
- return int - 0x10000;
82
- } else {
83
- return int;
84
- }
85
- };
86
-
87
- Data.prototype.writeInt16 = function(val) {
88
- if (val < 0) {
89
- val += 0x10000;
90
- }
91
- return this.writeUInt16(val);
92
- };
93
-
94
- Data.prototype.readString = function(length) {
95
- var i, j, ref, ret;
96
- ret = [];
97
- for (i = j = 0, ref = length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
98
- ret[i] = String.fromCharCode(this.readByte());
99
- }
100
- return ret.join('');
101
- };
102
-
103
- Data.prototype.writeString = function(val) {
104
- var i, j, ref, results;
105
- results = [];
106
- for (i = j = 0, ref = val.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
107
- results.push(this.writeByte(val.charCodeAt(i)));
108
- }
109
- return results;
110
- };
111
-
112
- Data.prototype.stringAt = function(pos, length) {
113
- this.pos = pos;
114
- return this.readString(length);
115
- };
116
-
117
- Data.prototype.readShort = function() {
118
- return this.readInt16();
119
- };
120
-
121
- Data.prototype.writeShort = function(val) {
122
- return this.writeInt16(val);
123
- };
124
-
125
- Data.prototype.readLongLong = function() {
126
- var b1, b2, b3, b4, b5, b6, b7, b8;
127
- b1 = this.readByte();
128
- b2 = this.readByte();
129
- b3 = this.readByte();
130
- b4 = this.readByte();
131
- b5 = this.readByte();
132
- b6 = this.readByte();
133
- b7 = this.readByte();
134
- b8 = this.readByte();
135
- if (b1 & 0x80) {
136
- return ((b1 ^ 0xff) * 0x100000000000000 + (b2 ^ 0xff) * 0x1000000000000 + (b3 ^ 0xff) * 0x10000000000 + (b4 ^ 0xff) * 0x100000000 + (b5 ^ 0xff) * 0x1000000 + (b6 ^ 0xff) * 0x10000 + (b7 ^ 0xff) * 0x100 + (b8 ^ 0xff) + 1) * -1;
137
- }
138
- return b1 * 0x100000000000000 + b2 * 0x1000000000000 + b3 * 0x10000000000 + b4 * 0x100000000 + b5 * 0x1000000 + b6 * 0x10000 + b7 * 0x100 + b8;
139
- };
140
-
141
- Data.prototype.writeLongLong = function(val) {
142
- var high, low;
143
- high = Math.floor(val / 0x100000000);
144
- low = val & 0xffffffff;
145
- this.writeByte((high >> 24) & 0xff);
146
- this.writeByte((high >> 16) & 0xff);
147
- this.writeByte((high >> 8) & 0xff);
148
- this.writeByte(high & 0xff);
149
- this.writeByte((low >> 24) & 0xff);
150
- this.writeByte((low >> 16) & 0xff);
151
- this.writeByte((low >> 8) & 0xff);
152
- return this.writeByte(low & 0xff);
153
- };
154
-
155
- Data.prototype.readInt = function() {
156
- return this.readInt32();
157
- };
158
-
159
- Data.prototype.writeInt = function(val) {
160
- return this.writeInt32(val);
161
- };
162
-
163
- Data.prototype.slice = function(start, end) {
164
- return this.data.slice(start, end);
165
- };
166
-
167
- Data.prototype.read = function(bytes) {
168
- var buf, i, j, ref;
169
- buf = [];
170
- for (i = j = 0, ref = bytes; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
171
- buf.push(this.readByte());
172
- }
173
- return buf;
174
- };
175
-
176
- Data.prototype.write = function(bytes) {
177
- var byte, j, len, results;
178
- results = [];
179
- for (j = 0, len = bytes.length; j < len; j++) {
180
- byte = bytes[j];
181
- results.push(this.writeByte(byte));
182
- }
183
- return results;
184
- };
185
-
186
- return Data;
187
-
188
- })();
189
-
190
- module.exports = Data;
191
-
192
- }).call(this);
package/js/document.js DELETED
@@ -1,247 +0,0 @@
1
- // Generated by CoffeeScript 1.12.1
2
-
3
- /*
4
- PDFDocument - represents an entire PDF document
5
- By Devon Govett
6
- */
7
-
8
- (function() {
9
- var PDFDocument, PDFObject, PDFPage, PDFReference, fs, stream,
10
- extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
11
- hasProp = {}.hasOwnProperty;
12
-
13
- stream = require('stream');
14
-
15
- fs = require('fs');
16
-
17
- PDFObject = require('./object');
18
-
19
- PDFReference = require('./reference');
20
-
21
- PDFPage = require('./page');
22
-
23
- PDFDocument = (function(superClass) {
24
- var mixin;
25
-
26
- extend(PDFDocument, superClass);
27
-
28
- function PDFDocument(options1) {
29
- var key, ref1, ref2, val;
30
- this.options = options1 != null ? options1 : {};
31
- PDFDocument.__super__.constructor.apply(this, arguments);
32
- this.version = 1.3;
33
- this.compress = (ref1 = this.options.compress) != null ? ref1 : true;
34
- this._pageBuffer = [];
35
- this._pageBufferStart = 0;
36
- this._offsets = [];
37
- this._waiting = 0;
38
- this._ended = false;
39
- this._offset = 0;
40
- this._root = this.ref({
41
- Type: 'Catalog',
42
- Pages: this.ref({
43
- Type: 'Pages',
44
- Count: 0,
45
- Kids: []
46
- })
47
- });
48
- this.page = null;
49
- this.initColor();
50
- this.initVector();
51
- this.initFonts();
52
- this.initText();
53
- this.initImages();
54
- this.info = {
55
- Producer: 'PDFKit',
56
- Creator: 'PDFKit',
57
- CreationDate: new Date()
58
- };
59
- if (this.options.info) {
60
- ref2 = this.options.info;
61
- for (key in ref2) {
62
- val = ref2[key];
63
- this.info[key] = val;
64
- }
65
- }
66
- this._write("%PDF-" + this.version);
67
- this._write("%\xFF\xFF\xFF\xFF");
68
- if (this.options.autoFirstPage !== false) {
69
- this.addPage();
70
- }
71
- }
72
-
73
- mixin = function(methods) {
74
- var method, name, results;
75
- results = [];
76
- for (name in methods) {
77
- method = methods[name];
78
- results.push(PDFDocument.prototype[name] = method);
79
- }
80
- return results;
81
- };
82
-
83
- mixin(require('./mixins/color'));
84
-
85
- mixin(require('./mixins/vector'));
86
-
87
- mixin(require('./mixins/fonts'));
88
-
89
- mixin(require('./mixins/text'));
90
-
91
- mixin(require('./mixins/images'));
92
-
93
- mixin(require('./mixins/annotations'));
94
-
95
- PDFDocument.prototype.addPage = function(options) {
96
- var pages;
97
- if (options == null) {
98
- options = this.options;
99
- }
100
- if (!this.options.bufferPages) {
101
- this.flushPages();
102
- }
103
- this.page = new PDFPage(this, options);
104
- this._pageBuffer.push(this.page);
105
- pages = this._root.data.Pages.data;
106
- pages.Kids.push(this.page.dictionary);
107
- pages.Count++;
108
- this.x = this.page.margins.left;
109
- this.y = this.page.margins.top;
110
- this._ctm = [1, 0, 0, 1, 0, 0];
111
- this.transform(1, 0, 0, -1, 0, this.page.height);
112
- this.emit('pageAdded');
113
- return this;
114
- };
115
-
116
- PDFDocument.prototype.bufferedPageRange = function() {
117
- return {
118
- start: this._pageBufferStart,
119
- count: this._pageBuffer.length
120
- };
121
- };
122
-
123
- PDFDocument.prototype.switchToPage = function(n) {
124
- var page;
125
- if (!(page = this._pageBuffer[n - this._pageBufferStart])) {
126
- throw new Error("switchToPage(" + n + ") out of bounds, current buffer covers pages " + this._pageBufferStart + " to " + (this._pageBufferStart + this._pageBuffer.length - 1));
127
- }
128
- return this.page = page;
129
- };
130
-
131
- PDFDocument.prototype.flushPages = function() {
132
- var i, len, page, pages;
133
- pages = this._pageBuffer;
134
- this._pageBuffer = [];
135
- this._pageBufferStart += pages.length;
136
- for (i = 0, len = pages.length; i < len; i++) {
137
- page = pages[i];
138
- page.end();
139
- }
140
- };
141
-
142
- PDFDocument.prototype.ref = function(data) {
143
- var ref;
144
- ref = new PDFReference(this, this._offsets.length + 1, data);
145
- this._offsets.push(null);
146
- this._waiting++;
147
- return ref;
148
- };
149
-
150
- PDFDocument.prototype._read = function() {};
151
-
152
- PDFDocument.prototype._write = function(data) {
153
- if (!Buffer.isBuffer(data)) {
154
- data = new Buffer(data + '\n', 'binary');
155
- }
156
- this.push(data);
157
- return this._offset += data.length;
158
- };
159
-
160
- PDFDocument.prototype.addContent = function(data) {
161
- this.page.write(data);
162
- return this;
163
- };
164
-
165
- PDFDocument.prototype._refEnd = function(ref) {
166
- this._offsets[ref.id - 1] = ref.offset;
167
- if (--this._waiting === 0 && this._ended) {
168
- this._finalize();
169
- return this._ended = false;
170
- }
171
- };
172
-
173
- PDFDocument.prototype.write = function(filename, fn) {
174
- var err;
175
- err = new Error('PDFDocument#write is deprecated, and will be removed in a future version of PDFKit. Please pipe the document into a Node stream.');
176
- console.warn(err.stack);
177
- this.pipe(fs.createWriteStream(filename));
178
- this.end();
179
- return this.once('end', fn);
180
- };
181
-
182
- PDFDocument.prototype.output = function(fn) {
183
- throw new Error('PDFDocument#output is deprecated, and has been removed from PDFKit. Please pipe the document into a Node stream.');
184
- };
185
-
186
- PDFDocument.prototype.end = function() {
187
- var font, key, name, ref1, ref2, val;
188
- this.flushPages();
189
- this._info = this.ref();
190
- ref1 = this.info;
191
- for (key in ref1) {
192
- val = ref1[key];
193
- if (typeof val === 'string') {
194
- val = new String(val);
195
- }
196
- this._info.data[key] = val;
197
- }
198
- this._info.end();
199
- ref2 = this._fontFamilies;
200
- for (name in ref2) {
201
- font = ref2[name];
202
- font.finalize();
203
- }
204
- this._root.end();
205
- this._root.data.Pages.end();
206
- if (this._waiting === 0) {
207
- return this._finalize();
208
- } else {
209
- return this._ended = true;
210
- }
211
- };
212
-
213
- PDFDocument.prototype._finalize = function(fn) {
214
- var i, len, offset, ref1, xRefOffset;
215
- xRefOffset = this._offset;
216
- this._write("xref");
217
- this._write("0 " + (this._offsets.length + 1));
218
- this._write("0000000000 65535 f ");
219
- ref1 = this._offsets;
220
- for (i = 0, len = ref1.length; i < len; i++) {
221
- offset = ref1[i];
222
- offset = ('0000000000' + offset).slice(-10);
223
- this._write(offset + ' 00000 n ');
224
- }
225
- this._write('trailer');
226
- this._write(PDFObject.convert({
227
- Size: this._offsets.length + 1,
228
- Root: this._root,
229
- Info: this._info
230
- }));
231
- this._write('startxref');
232
- this._write("" + xRefOffset);
233
- this._write('%%EOF');
234
- return this.push(null);
235
- };
236
-
237
- PDFDocument.prototype.toString = function() {
238
- return "[object PDFDocument]";
239
- };
240
-
241
- return PDFDocument;
242
-
243
- })(stream.Readable);
244
-
245
- module.exports = PDFDocument;
246
-
247
- }).call(this);