pdfkit 0.13.0 → 0.15.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.
- package/CHANGELOG.md +18 -0
- package/README.md +1 -1
- package/js/data/sRGB_IEC61966_2_1.icc +0 -0
- package/js/pdfkit.es.js +5788 -0
- package/js/pdfkit.es.js.map +1 -0
- package/js/pdfkit.es5.js +558 -195
- package/js/pdfkit.es5.js.map +1 -1
- package/js/pdfkit.esnext.js +463 -108
- package/js/pdfkit.esnext.js.map +1 -1
- package/js/pdfkit.js +815 -1532
- package/js/pdfkit.js.map +1 -1
- package/js/pdfkit.standalone.js +29455 -43266
- package/js/virtual-fs.js +13 -30
- package/package.json +12 -14
package/js/pdfkit.es5.js
CHANGED
|
@@ -5,46 +5,9 @@ import CryptoJS from 'crypto-js';
|
|
|
5
5
|
import fontkit from 'fontkit';
|
|
6
6
|
import { EventEmitter } from 'events';
|
|
7
7
|
import LineBreaker from 'linebreak';
|
|
8
|
+
import exif from 'jpeg-exif';
|
|
8
9
|
import PNG from 'png-js';
|
|
9
10
|
|
|
10
|
-
function ownKeys(object, enumerableOnly) {
|
|
11
|
-
var keys = Object.keys(object);
|
|
12
|
-
|
|
13
|
-
if (Object.getOwnPropertySymbols) {
|
|
14
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
15
|
-
|
|
16
|
-
if (enumerableOnly) {
|
|
17
|
-
symbols = symbols.filter(function (sym) {
|
|
18
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
keys.push.apply(keys, symbols);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return keys;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function _objectSpread2(target) {
|
|
29
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
30
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
31
|
-
|
|
32
|
-
if (i % 2) {
|
|
33
|
-
ownKeys(Object(source), true).forEach(function (key) {
|
|
34
|
-
_defineProperty(target, key, source[key]);
|
|
35
|
-
});
|
|
36
|
-
} else if (Object.getOwnPropertyDescriptors) {
|
|
37
|
-
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
38
|
-
} else {
|
|
39
|
-
ownKeys(Object(source)).forEach(function (key) {
|
|
40
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return target;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
11
|
function _classCallCheck(instance, Constructor) {
|
|
49
12
|
if (!(instance instanceof Constructor)) {
|
|
50
13
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -82,6 +45,40 @@ function _defineProperty(obj, key, value) {
|
|
|
82
45
|
return obj;
|
|
83
46
|
}
|
|
84
47
|
|
|
48
|
+
function ownKeys(object, enumerableOnly) {
|
|
49
|
+
var keys = Object.keys(object);
|
|
50
|
+
|
|
51
|
+
if (Object.getOwnPropertySymbols) {
|
|
52
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
53
|
+
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
54
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
55
|
+
});
|
|
56
|
+
keys.push.apply(keys, symbols);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return keys;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _objectSpread2(target) {
|
|
63
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
64
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
65
|
+
|
|
66
|
+
if (i % 2) {
|
|
67
|
+
ownKeys(Object(source), true).forEach(function (key) {
|
|
68
|
+
_defineProperty(target, key, source[key]);
|
|
69
|
+
});
|
|
70
|
+
} else if (Object.getOwnPropertyDescriptors) {
|
|
71
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
72
|
+
} else {
|
|
73
|
+
ownKeys(Object(source)).forEach(function (key) {
|
|
74
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return target;
|
|
80
|
+
}
|
|
81
|
+
|
|
85
82
|
function _inherits(subClass, superClass) {
|
|
86
83
|
if (typeof superClass !== "function" && superClass !== null) {
|
|
87
84
|
throw new TypeError("Super expression must either be null or a function");
|
|
@@ -119,7 +116,7 @@ function _isNativeReflectConstruct() {
|
|
|
119
116
|
if (typeof Proxy === "function") return true;
|
|
120
117
|
|
|
121
118
|
try {
|
|
122
|
-
|
|
119
|
+
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
|
123
120
|
return true;
|
|
124
121
|
} catch (e) {
|
|
125
122
|
return false;
|
|
@@ -178,21 +175,18 @@ function _arrayWithHoles(arr) {
|
|
|
178
175
|
}
|
|
179
176
|
|
|
180
177
|
function _iterableToArray(iter) {
|
|
181
|
-
if (typeof Symbol !== "undefined" &&
|
|
178
|
+
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
|
|
182
179
|
}
|
|
183
180
|
|
|
184
181
|
function _iterableToArrayLimit(arr, i) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
if (_i == null) return;
|
|
182
|
+
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
|
|
188
183
|
var _arr = [];
|
|
189
184
|
var _n = true;
|
|
190
185
|
var _d = false;
|
|
191
|
-
|
|
192
|
-
var _s, _e;
|
|
186
|
+
var _e = undefined;
|
|
193
187
|
|
|
194
188
|
try {
|
|
195
|
-
for (_i =
|
|
189
|
+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
|
|
196
190
|
_arr.push(_s.value);
|
|
197
191
|
|
|
198
192
|
if (i && _arr.length === i) break;
|
|
@@ -237,9 +231,9 @@ function _nonIterableRest() {
|
|
|
237
231
|
}
|
|
238
232
|
|
|
239
233
|
function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
240
|
-
var it
|
|
234
|
+
var it;
|
|
241
235
|
|
|
242
|
-
if (
|
|
236
|
+
if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
|
|
243
237
|
if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
|
|
244
238
|
if (it) o = it;
|
|
245
239
|
var i = 0;
|
|
@@ -272,7 +266,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
|
|
|
272
266
|
err;
|
|
273
267
|
return {
|
|
274
268
|
s: function () {
|
|
275
|
-
it =
|
|
269
|
+
it = o[Symbol.iterator]();
|
|
276
270
|
},
|
|
277
271
|
n: function () {
|
|
278
272
|
var step = it.next();
|
|
@@ -371,7 +365,9 @@ var PDFTree = /*#__PURE__*/function () {
|
|
|
371
365
|
}
|
|
372
366
|
}, {
|
|
373
367
|
key: "_compareKeys",
|
|
374
|
-
value: function _compareKeys()
|
|
368
|
+
value: function _compareKeys()
|
|
369
|
+
/*a, b*/
|
|
370
|
+
{
|
|
375
371
|
throw new Error('Must be implemented by subclasses');
|
|
376
372
|
}
|
|
377
373
|
}, {
|
|
@@ -381,7 +377,9 @@ var PDFTree = /*#__PURE__*/function () {
|
|
|
381
377
|
}
|
|
382
378
|
}, {
|
|
383
379
|
key: "_dataForKey",
|
|
384
|
-
value: function _dataForKey()
|
|
380
|
+
value: function _dataForKey()
|
|
381
|
+
/*k*/
|
|
382
|
+
{
|
|
385
383
|
throw new Error('Must be implemented by subclasses');
|
|
386
384
|
}
|
|
387
385
|
}]);
|
|
@@ -725,6 +723,23 @@ var PDFPage = /*#__PURE__*/function () {
|
|
|
725
723
|
|
|
726
724
|
|
|
727
725
|
_createClass(PDFPage, [{
|
|
726
|
+
key: "maxY",
|
|
727
|
+
value: function maxY() {
|
|
728
|
+
return this.height - this.margins.bottom;
|
|
729
|
+
}
|
|
730
|
+
}, {
|
|
731
|
+
key: "write",
|
|
732
|
+
value: function write(chunk) {
|
|
733
|
+
return this.content.write(chunk);
|
|
734
|
+
}
|
|
735
|
+
}, {
|
|
736
|
+
key: "end",
|
|
737
|
+
value: function end() {
|
|
738
|
+
this.dictionary.end();
|
|
739
|
+
this.resources.end();
|
|
740
|
+
return this.content.end();
|
|
741
|
+
}
|
|
742
|
+
}, {
|
|
728
743
|
key: "fonts",
|
|
729
744
|
get: function get() {
|
|
730
745
|
var data = this.resources.data;
|
|
@@ -766,23 +781,6 @@ var PDFPage = /*#__PURE__*/function () {
|
|
|
766
781
|
var data = this.dictionary.data;
|
|
767
782
|
return data.StructParents != null ? data.StructParents : data.StructParents = this.document.createStructParentTreeNextKey();
|
|
768
783
|
}
|
|
769
|
-
}, {
|
|
770
|
-
key: "maxY",
|
|
771
|
-
value: function maxY() {
|
|
772
|
-
return this.height - this.margins.bottom;
|
|
773
|
-
}
|
|
774
|
-
}, {
|
|
775
|
-
key: "write",
|
|
776
|
-
value: function write(chunk) {
|
|
777
|
-
return this.content.write(chunk);
|
|
778
|
-
}
|
|
779
|
-
}, {
|
|
780
|
-
key: "end",
|
|
781
|
-
value: function end() {
|
|
782
|
-
this.dictionary.end();
|
|
783
|
-
this.resources.end();
|
|
784
|
-
return this.content.end();
|
|
785
|
-
}
|
|
786
784
|
}]);
|
|
787
785
|
|
|
788
786
|
return PDFPage;
|
|
@@ -1257,6 +1255,41 @@ function saslprep(input) {
|
|
|
1257
1255
|
}
|
|
1258
1256
|
|
|
1259
1257
|
var PDFSecurity = /*#__PURE__*/function () {
|
|
1258
|
+
_createClass(PDFSecurity, null, [{
|
|
1259
|
+
key: "generateFileID",
|
|
1260
|
+
value: function generateFileID() {
|
|
1261
|
+
var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1262
|
+
var infoStr = "".concat(info.CreationDate.getTime(), "\n");
|
|
1263
|
+
|
|
1264
|
+
for (var key in info) {
|
|
1265
|
+
// eslint-disable-next-line no-prototype-builtins
|
|
1266
|
+
if (!info.hasOwnProperty(key)) {
|
|
1267
|
+
continue;
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
infoStr += "".concat(key, ": ").concat(info[key].valueOf(), "\n");
|
|
1271
|
+
}
|
|
1272
|
+
|
|
1273
|
+
return wordArrayToBuffer(CryptoJS.MD5(infoStr));
|
|
1274
|
+
}
|
|
1275
|
+
}, {
|
|
1276
|
+
key: "generateRandomWordArray",
|
|
1277
|
+
value: function generateRandomWordArray(bytes) {
|
|
1278
|
+
return CryptoJS.lib.WordArray.random(bytes);
|
|
1279
|
+
}
|
|
1280
|
+
}, {
|
|
1281
|
+
key: "create",
|
|
1282
|
+
value: function create(document) {
|
|
1283
|
+
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1284
|
+
|
|
1285
|
+
if (!options.ownerPassword && !options.userPassword) {
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
|
|
1289
|
+
return new PDFSecurity(document, options);
|
|
1290
|
+
}
|
|
1291
|
+
}]);
|
|
1292
|
+
|
|
1260
1293
|
function PDFSecurity(document) {
|
|
1261
1294
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1262
1295
|
|
|
@@ -1449,39 +1482,6 @@ var PDFSecurity = /*#__PURE__*/function () {
|
|
|
1449
1482
|
value: function end() {
|
|
1450
1483
|
this.dictionary.end();
|
|
1451
1484
|
}
|
|
1452
|
-
}], [{
|
|
1453
|
-
key: "generateFileID",
|
|
1454
|
-
value: function generateFileID() {
|
|
1455
|
-
var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1456
|
-
var infoStr = "".concat(info.CreationDate.getTime(), "\n");
|
|
1457
|
-
|
|
1458
|
-
for (var key in info) {
|
|
1459
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
1460
|
-
if (!info.hasOwnProperty(key)) {
|
|
1461
|
-
continue;
|
|
1462
|
-
}
|
|
1463
|
-
|
|
1464
|
-
infoStr += "".concat(key, ": ").concat(info[key].valueOf(), "\n");
|
|
1465
|
-
}
|
|
1466
|
-
|
|
1467
|
-
return wordArrayToBuffer(CryptoJS.MD5(infoStr));
|
|
1468
|
-
}
|
|
1469
|
-
}, {
|
|
1470
|
-
key: "generateRandomWordArray",
|
|
1471
|
-
value: function generateRandomWordArray(bytes) {
|
|
1472
|
-
return CryptoJS.lib.WordArray.random(bytes);
|
|
1473
|
-
}
|
|
1474
|
-
}, {
|
|
1475
|
-
key: "create",
|
|
1476
|
-
value: function create(document) {
|
|
1477
|
-
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
1478
|
-
|
|
1479
|
-
if (!options.ownerPassword && !options.userPassword) {
|
|
1480
|
-
return null;
|
|
1481
|
-
}
|
|
1482
|
-
|
|
1483
|
-
return new PDFSecurity(document, options);
|
|
1484
|
-
}
|
|
1485
1485
|
}]);
|
|
1486
1486
|
|
|
1487
1487
|
return PDFSecurity;
|
|
@@ -3139,6 +3139,11 @@ var VectorMixin = {
|
|
|
3139
3139
|
},
|
|
3140
3140
|
transform: function transform(m11, m12, m21, m22, dx, dy) {
|
|
3141
3141
|
// keep track of the current transformation matrix
|
|
3142
|
+
if (m11 === 1 && m12 === 0 && m21 === 0 && m22 === 1 && dx === 0 && dy === 0) {
|
|
3143
|
+
// Ignore identity transforms
|
|
3144
|
+
return this;
|
|
3145
|
+
}
|
|
3146
|
+
|
|
3142
3147
|
var m = this._ctm;
|
|
3143
3148
|
|
|
3144
3149
|
var _m = _slicedToArray(m, 6),
|
|
@@ -3244,6 +3249,13 @@ var WIN_ANSI_MAP = {
|
|
|
3244
3249
|
var characters = ".notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n.notdef .notdef .notdef .notdef\n \nspace exclam quotedbl numbersign\ndollar percent ampersand quotesingle\nparenleft parenright asterisk plus\ncomma hyphen period slash\nzero one two three\nfour five six seven\neight nine colon semicolon\nless equal greater question\n \nat A B C\nD E F G\nH I J K\nL M N O\nP Q R S\nT U V W\nX Y Z bracketleft\nbackslash bracketright asciicircum underscore\n \ngrave a b c\nd e f g\nh i j k\nl m n o\np q r s\nt u v w\nx y z braceleft\nbar braceright asciitilde .notdef\n \nEuro .notdef quotesinglbase florin\nquotedblbase ellipsis dagger daggerdbl\ncircumflex perthousand Scaron guilsinglleft\nOE .notdef Zcaron .notdef\n.notdef quoteleft quoteright quotedblleft\nquotedblright bullet endash emdash\ntilde trademark scaron guilsinglright\noe .notdef zcaron ydieresis\n \nspace exclamdown cent sterling\ncurrency yen brokenbar section\ndieresis copyright ordfeminine guillemotleft\nlogicalnot hyphen registered macron\ndegree plusminus twosuperior threesuperior\nacute mu paragraph periodcentered\ncedilla onesuperior ordmasculine guillemotright\nonequarter onehalf threequarters questiondown\n \nAgrave Aacute Acircumflex Atilde\nAdieresis Aring AE Ccedilla\nEgrave Eacute Ecircumflex Edieresis\nIgrave Iacute Icircumflex Idieresis\nEth Ntilde Ograve Oacute\nOcircumflex Otilde Odieresis multiply\nOslash Ugrave Uacute Ucircumflex\nUdieresis Yacute Thorn germandbls\n \nagrave aacute acircumflex atilde\nadieresis aring ae ccedilla\negrave eacute ecircumflex edieresis\nigrave iacute icircumflex idieresis\neth ntilde ograve oacute\nocircumflex otilde odieresis divide\noslash ugrave uacute ucircumflex\nudieresis yacute thorn ydieresis".split(/\s+/);
|
|
3245
3250
|
|
|
3246
3251
|
var AFMFont = /*#__PURE__*/function () {
|
|
3252
|
+
_createClass(AFMFont, null, [{
|
|
3253
|
+
key: "open",
|
|
3254
|
+
value: function open(filename) {
|
|
3255
|
+
return new AFMFont(fs.readFileSync(filename, 'utf8'));
|
|
3256
|
+
}
|
|
3257
|
+
}]);
|
|
3258
|
+
|
|
3247
3259
|
function AFMFont(contents) {
|
|
3248
3260
|
_classCallCheck(this, AFMFont);
|
|
3249
3261
|
|
|
@@ -3388,11 +3400,6 @@ var AFMFont = /*#__PURE__*/function () {
|
|
|
3388
3400
|
|
|
3389
3401
|
return advances;
|
|
3390
3402
|
}
|
|
3391
|
-
}], [{
|
|
3392
|
-
key: "open",
|
|
3393
|
-
value: function open(filename) {
|
|
3394
|
-
return new AFMFont(fs.readFileSync(filename, 'utf8'));
|
|
3395
|
-
}
|
|
3396
3403
|
}]);
|
|
3397
3404
|
|
|
3398
3405
|
return AFMFont;
|
|
@@ -3790,6 +3797,14 @@ var EmbeddedFont = /*#__PURE__*/function (_PDFFont) {
|
|
|
3790
3797
|
descriptor.data.FontFile2 = fontFile;
|
|
3791
3798
|
}
|
|
3792
3799
|
|
|
3800
|
+
if (this.document.subset) {
|
|
3801
|
+
var CIDSet = Buffer.from('FFFFFFFFC0', 'hex');
|
|
3802
|
+
var CIDSetRef = this.document.ref();
|
|
3803
|
+
CIDSetRef.write(CIDSet);
|
|
3804
|
+
CIDSetRef.end();
|
|
3805
|
+
descriptor.data.CIDSet = CIDSetRef;
|
|
3806
|
+
}
|
|
3807
|
+
|
|
3793
3808
|
descriptor.end();
|
|
3794
3809
|
var descendantFontData = {
|
|
3795
3810
|
Type: 'Font',
|
|
@@ -3867,7 +3882,17 @@ var EmbeddedFont = /*#__PURE__*/function (_PDFFont) {
|
|
|
3867
3882
|
_iterator.f();
|
|
3868
3883
|
}
|
|
3869
3884
|
|
|
3870
|
-
|
|
3885
|
+
var chunkSize = 256;
|
|
3886
|
+
var chunks = Math.ceil(entries.length / chunkSize);
|
|
3887
|
+
var ranges = [];
|
|
3888
|
+
|
|
3889
|
+
for (var i = 0; i < chunks; i++) {
|
|
3890
|
+
var start = i * chunkSize;
|
|
3891
|
+
var end = Math.min((i + 1) * chunkSize, entries.length);
|
|
3892
|
+
ranges.push("<".concat(toHex(start), "> <").concat(toHex(end - 1), "> [").concat(entries.slice(start, end).join(' '), "]"));
|
|
3893
|
+
}
|
|
3894
|
+
|
|
3895
|
+
cmap.end("/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo <<\n /Registry (Adobe)\n /Ordering (UCS)\n /Supplement 0\n>> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000><ffff>\nendcodespacerange\n1 beginbfrange\n".concat(ranges.join('\n'), "\nendbfrange\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend"));
|
|
3871
3896
|
return cmap;
|
|
3872
3897
|
}
|
|
3873
3898
|
}]);
|
|
@@ -4000,6 +4025,9 @@ var FontsMixin = {
|
|
|
4000
4025
|
}
|
|
4001
4026
|
};
|
|
4002
4027
|
|
|
4028
|
+
var SOFT_HYPHEN = "\xAD";
|
|
4029
|
+
var HYPHEN = '-';
|
|
4030
|
+
|
|
4003
4031
|
var LineWrapper = /*#__PURE__*/function (_EventEmitter) {
|
|
4004
4032
|
_inherits(LineWrapper, _EventEmitter);
|
|
4005
4033
|
|
|
@@ -4080,6 +4108,15 @@ var LineWrapper = /*#__PURE__*/function (_EventEmitter) {
|
|
|
4080
4108
|
value: function wordWidth(word) {
|
|
4081
4109
|
return this.document.widthOfString(word, this) + this.characterSpacing + this.wordSpacing;
|
|
4082
4110
|
}
|
|
4111
|
+
}, {
|
|
4112
|
+
key: "canFit",
|
|
4113
|
+
value: function canFit(word, w) {
|
|
4114
|
+
if (word[word.length - 1] != SOFT_HYPHEN) {
|
|
4115
|
+
return w <= this.spaceLeft;
|
|
4116
|
+
}
|
|
4117
|
+
|
|
4118
|
+
return w + this.wordWidth(HYPHEN) <= this.spaceLeft;
|
|
4119
|
+
}
|
|
4083
4120
|
}, {
|
|
4084
4121
|
key: "eachWord",
|
|
4085
4122
|
value: function eachWord(text, fn) {
|
|
@@ -4214,13 +4251,13 @@ var LineWrapper = /*#__PURE__*/function (_EventEmitter) {
|
|
|
4214
4251
|
_this2.spaceLeft = _this2.lineWidth;
|
|
4215
4252
|
}
|
|
4216
4253
|
|
|
4217
|
-
if (
|
|
4254
|
+
if (_this2.canFit(word, w)) {
|
|
4218
4255
|
buffer += word;
|
|
4219
4256
|
textWidth += w;
|
|
4220
4257
|
wc++;
|
|
4221
4258
|
}
|
|
4222
4259
|
|
|
4223
|
-
if (bk.required ||
|
|
4260
|
+
if (bk.required || !_this2.canFit(word, w)) {
|
|
4224
4261
|
// if the user specified a max height and an ellipsis, and is about to pass the
|
|
4225
4262
|
// max height and max columns after the next line, append the ellipsis
|
|
4226
4263
|
var lh = _this2.document.currentLineHeight(true);
|
|
@@ -4257,6 +4294,12 @@ var LineWrapper = /*#__PURE__*/function (_EventEmitter) {
|
|
|
4257
4294
|
}
|
|
4258
4295
|
|
|
4259
4296
|
_this2.emit('lastLine', options, _this2);
|
|
4297
|
+
} // Previous entry is a soft hyphen - add visible hyphen.
|
|
4298
|
+
|
|
4299
|
+
|
|
4300
|
+
if (buffer[buffer.length - 1] == SOFT_HYPHEN) {
|
|
4301
|
+
buffer = buffer.slice(0, -1) + HYPHEN;
|
|
4302
|
+
_this2.spaceLeft -= _this2.wordWidth(HYPHEN);
|
|
4260
4303
|
}
|
|
4261
4304
|
|
|
4262
4305
|
emitLine(); // if we've reached the edge of the page,
|
|
@@ -4455,8 +4498,6 @@ var TextMixin = {
|
|
|
4455
4498
|
return height;
|
|
4456
4499
|
},
|
|
4457
4500
|
list: function list(_list, x, y, options, wrapper) {
|
|
4458
|
-
var _this3 = this;
|
|
4459
|
-
|
|
4460
4501
|
options = this._initOptions(x, y, options);
|
|
4461
4502
|
var listType = options.listType || 'bullet';
|
|
4462
4503
|
var unit = Math.round(this._font.ascender / 1000 * this._fontSize);
|
|
@@ -4472,8 +4513,8 @@ var TextMixin = {
|
|
|
4472
4513
|
var flatten = function flatten(list) {
|
|
4473
4514
|
var n = 1;
|
|
4474
4515
|
|
|
4475
|
-
for (var
|
|
4476
|
-
var item = list[
|
|
4516
|
+
for (var i = 0; i < list.length; i++) {
|
|
4517
|
+
var item = list[i];
|
|
4477
4518
|
|
|
4478
4519
|
if (Array.isArray(item)) {
|
|
4479
4520
|
level++;
|
|
@@ -4505,83 +4546,92 @@ var TextMixin = {
|
|
|
4505
4546
|
}
|
|
4506
4547
|
};
|
|
4507
4548
|
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
level = 1;
|
|
4511
|
-
var i = 0;
|
|
4512
|
-
wrapper.on('firstLine', function () {
|
|
4513
|
-
var item, itemType, labelType, bodyType;
|
|
4549
|
+
var drawListItem = function drawListItem(listItem) {
|
|
4550
|
+
var _this3 = this;
|
|
4514
4551
|
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
|
|
4552
|
+
wrapper = new LineWrapper(this, options);
|
|
4553
|
+
wrapper.on('line', this._line);
|
|
4554
|
+
level = 1;
|
|
4555
|
+
var i = 0;
|
|
4556
|
+
wrapper.once('firstLine', function () {
|
|
4557
|
+
var item, itemType, labelType, bodyType;
|
|
4518
4558
|
|
|
4519
|
-
|
|
4520
|
-
|
|
4521
|
-
|
|
4522
|
-
|
|
4523
|
-
|
|
4524
|
-
|
|
4525
|
-
|
|
4559
|
+
if (options.structParent) {
|
|
4560
|
+
if (options.structTypes) {
|
|
4561
|
+
var _options$structTypes = _slicedToArray(options.structTypes, 3);
|
|
4562
|
+
|
|
4563
|
+
itemType = _options$structTypes[0];
|
|
4564
|
+
labelType = _options$structTypes[1];
|
|
4565
|
+
bodyType = _options$structTypes[2];
|
|
4566
|
+
} else {
|
|
4567
|
+
itemType = 'LI';
|
|
4568
|
+
labelType = 'Lbl';
|
|
4569
|
+
bodyType = 'LBody';
|
|
4570
|
+
}
|
|
4526
4571
|
}
|
|
4527
|
-
}
|
|
4528
4572
|
|
|
4529
|
-
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4573
|
+
if (itemType) {
|
|
4574
|
+
item = _this3.struct(itemType);
|
|
4575
|
+
options.structParent.add(item);
|
|
4576
|
+
} else if (options.structParent) {
|
|
4577
|
+
item = options.structParent;
|
|
4578
|
+
}
|
|
4535
4579
|
|
|
4536
|
-
|
|
4580
|
+
var l;
|
|
4537
4581
|
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4582
|
+
if ((l = levels[i++]) !== level) {
|
|
4583
|
+
var diff = itemIndent * (l - level);
|
|
4584
|
+
_this3.x += diff;
|
|
4585
|
+
wrapper.lineWidth -= diff;
|
|
4586
|
+
level = l;
|
|
4587
|
+
}
|
|
4544
4588
|
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4589
|
+
if (item && (labelType || bodyType)) {
|
|
4590
|
+
item.add(_this3.struct(labelType || bodyType, [_this3.markStructureContent(labelType || bodyType)]));
|
|
4591
|
+
}
|
|
4548
4592
|
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4593
|
+
switch (listType) {
|
|
4594
|
+
case 'bullet':
|
|
4595
|
+
_this3.circle(_this3.x - indent + r, _this3.y + midLine, r);
|
|
4552
4596
|
|
|
4553
|
-
|
|
4597
|
+
_this3.fill();
|
|
4554
4598
|
|
|
4555
|
-
|
|
4599
|
+
break;
|
|
4556
4600
|
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4601
|
+
case 'numbered':
|
|
4602
|
+
case 'lettered':
|
|
4603
|
+
var text = label(numbers[i - 1]);
|
|
4560
4604
|
|
|
4561
|
-
|
|
4605
|
+
_this3._fragment(text, _this3.x - indent, _this3.y, options);
|
|
4562
4606
|
|
|
4563
|
-
|
|
4564
|
-
|
|
4607
|
+
break;
|
|
4608
|
+
}
|
|
4565
4609
|
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4610
|
+
if (item && labelType && bodyType) {
|
|
4611
|
+
item.add(_this3.struct(bodyType, [_this3.markStructureContent(bodyType)]));
|
|
4612
|
+
}
|
|
4613
|
+
|
|
4614
|
+
if (item && item !== options.structParent) {
|
|
4615
|
+
item.end();
|
|
4616
|
+
}
|
|
4617
|
+
});
|
|
4618
|
+
wrapper.on('sectionStart', function () {
|
|
4619
|
+
var pos = indent + itemIndent * (level - 1);
|
|
4620
|
+
_this3.x += pos;
|
|
4621
|
+
return wrapper.lineWidth -= pos;
|
|
4622
|
+
});
|
|
4623
|
+
wrapper.on('sectionEnd', function () {
|
|
4624
|
+
var pos = indent + itemIndent * (level - 1);
|
|
4625
|
+
_this3.x -= pos;
|
|
4626
|
+
return wrapper.lineWidth += pos;
|
|
4627
|
+
});
|
|
4628
|
+
wrapper.wrap(listItem, options);
|
|
4629
|
+
};
|
|
4630
|
+
|
|
4631
|
+
for (var i = 0; i < items.length; i++) {
|
|
4632
|
+
drawListItem.call(this, items[i]);
|
|
4633
|
+
}
|
|
4569
4634
|
|
|
4570
|
-
if (item && item !== options.structParent) {
|
|
4571
|
-
item.end();
|
|
4572
|
-
}
|
|
4573
|
-
});
|
|
4574
|
-
wrapper.on('sectionStart', function () {
|
|
4575
|
-
var pos = indent + itemIndent * (level - 1);
|
|
4576
|
-
_this3.x += pos;
|
|
4577
|
-
return wrapper.lineWidth -= pos;
|
|
4578
|
-
});
|
|
4579
|
-
wrapper.on('sectionEnd', function () {
|
|
4580
|
-
var pos = indent + itemIndent * (level - 1);
|
|
4581
|
-
_this3.x -= pos;
|
|
4582
|
-
return wrapper.lineWidth += pos;
|
|
4583
|
-
});
|
|
4584
|
-
wrapper.wrap(items.join('\n'), options);
|
|
4585
4635
|
return this;
|
|
4586
4636
|
},
|
|
4587
4637
|
_initOptions: function _initOptions() {
|
|
@@ -4956,8 +5006,10 @@ var JPEG = /*#__PURE__*/function () {
|
|
|
4956
5006
|
|
|
4957
5007
|
if (this.data.readUInt16BE(0) !== 0xffd8) {
|
|
4958
5008
|
throw 'SOI not found in JPEG';
|
|
4959
|
-
}
|
|
5009
|
+
} // Parse the EXIF orientation
|
|
4960
5010
|
|
|
5011
|
+
|
|
5012
|
+
this.orientation = exif.fromBuffer(this.data).Orientation || 1;
|
|
4961
5013
|
var pos = 2;
|
|
4962
5014
|
|
|
4963
5015
|
while (pos < this.data.length) {
|
|
@@ -5225,7 +5277,7 @@ var PDFImage = /*#__PURE__*/function () {
|
|
|
5225
5277
|
} else {
|
|
5226
5278
|
var match;
|
|
5227
5279
|
|
|
5228
|
-
if (match = /^data
|
|
5280
|
+
if (match = /^data:.+?;base64,(.*)$/.exec(src)) {
|
|
5229
5281
|
data = Buffer.from(match[1], 'base64');
|
|
5230
5282
|
} else {
|
|
5231
5283
|
data = fs.readFileSync(src);
|
|
@@ -5256,13 +5308,15 @@ var ImagesMixin = {
|
|
|
5256
5308
|
},
|
|
5257
5309
|
image: function image(src, x, y) {
|
|
5258
5310
|
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
5259
|
-
var bh, bp, bw, image, ip, left, left1;
|
|
5311
|
+
var bh, bp, bw, image, ip, left, left1, rotateAngle, originX, originY;
|
|
5260
5312
|
|
|
5261
5313
|
if (typeof x === 'object') {
|
|
5262
5314
|
options = x;
|
|
5263
5315
|
x = null;
|
|
5264
|
-
}
|
|
5316
|
+
} // Ignore orientation based on document options or image options
|
|
5317
|
+
|
|
5265
5318
|
|
|
5319
|
+
var ignoreOrientation = options.ignoreOrientation || options.ignoreOrientation !== false && this.options.ignoreOrientation;
|
|
5266
5320
|
x = (left = x != null ? x : options.x) != null ? left : this.x;
|
|
5267
5321
|
y = (left1 = y != null ? y : options.y) != null ? left1 : this.y;
|
|
5268
5322
|
|
|
@@ -5286,27 +5340,37 @@ var ImagesMixin = {
|
|
|
5286
5340
|
this.page.xobjects[image.label] = image.obj;
|
|
5287
5341
|
}
|
|
5288
5342
|
|
|
5289
|
-
var
|
|
5290
|
-
|
|
5343
|
+
var _image = image,
|
|
5344
|
+
width = _image.width,
|
|
5345
|
+
height = _image.height; // If EXIF orientation calls for it, swap width and height
|
|
5346
|
+
|
|
5347
|
+
if (!ignoreOrientation && image.orientation > 4) {
|
|
5348
|
+
var _ref = [height, width];
|
|
5349
|
+
width = _ref[0];
|
|
5350
|
+
height = _ref[1];
|
|
5351
|
+
}
|
|
5352
|
+
|
|
5353
|
+
var w = options.width || width;
|
|
5354
|
+
var h = options.height || height;
|
|
5291
5355
|
|
|
5292
5356
|
if (options.width && !options.height) {
|
|
5293
|
-
var wp = w /
|
|
5294
|
-
w =
|
|
5295
|
-
h =
|
|
5357
|
+
var wp = w / width;
|
|
5358
|
+
w = width * wp;
|
|
5359
|
+
h = height * wp;
|
|
5296
5360
|
} else if (options.height && !options.width) {
|
|
5297
|
-
var hp = h /
|
|
5298
|
-
w =
|
|
5299
|
-
h =
|
|
5361
|
+
var hp = h / height;
|
|
5362
|
+
w = width * hp;
|
|
5363
|
+
h = height * hp;
|
|
5300
5364
|
} else if (options.scale) {
|
|
5301
|
-
w =
|
|
5302
|
-
h =
|
|
5365
|
+
w = width * options.scale;
|
|
5366
|
+
h = height * options.scale;
|
|
5303
5367
|
} else if (options.fit) {
|
|
5304
5368
|
var _options$fit = _slicedToArray(options.fit, 2);
|
|
5305
5369
|
|
|
5306
5370
|
bw = _options$fit[0];
|
|
5307
5371
|
bh = _options$fit[1];
|
|
5308
5372
|
bp = bw / bh;
|
|
5309
|
-
ip =
|
|
5373
|
+
ip = width / height;
|
|
5310
5374
|
|
|
5311
5375
|
if (ip > bp) {
|
|
5312
5376
|
w = bw;
|
|
@@ -5321,7 +5385,7 @@ var ImagesMixin = {
|
|
|
5321
5385
|
bw = _options$cover[0];
|
|
5322
5386
|
bh = _options$cover[1];
|
|
5323
5387
|
bp = bw / bh;
|
|
5324
|
-
ip =
|
|
5388
|
+
ip = width / height;
|
|
5325
5389
|
|
|
5326
5390
|
if (ip > bp) {
|
|
5327
5391
|
h = bh;
|
|
@@ -5344,6 +5408,93 @@ var ImagesMixin = {
|
|
|
5344
5408
|
} else if (options.valign === 'bottom') {
|
|
5345
5409
|
y = y + bh - h;
|
|
5346
5410
|
}
|
|
5411
|
+
}
|
|
5412
|
+
|
|
5413
|
+
if (!ignoreOrientation) {
|
|
5414
|
+
switch (image.orientation) {
|
|
5415
|
+
// No orientation (need to flip image, though, because of the default transform matrix on the document)
|
|
5416
|
+
default:
|
|
5417
|
+
case 1:
|
|
5418
|
+
h = -h;
|
|
5419
|
+
y -= h;
|
|
5420
|
+
rotateAngle = 0;
|
|
5421
|
+
break;
|
|
5422
|
+
// Flip Horizontal
|
|
5423
|
+
|
|
5424
|
+
case 2:
|
|
5425
|
+
w = -w;
|
|
5426
|
+
h = -h;
|
|
5427
|
+
x -= w;
|
|
5428
|
+
y -= h;
|
|
5429
|
+
rotateAngle = 0;
|
|
5430
|
+
break;
|
|
5431
|
+
// Rotate 180 degrees
|
|
5432
|
+
|
|
5433
|
+
case 3:
|
|
5434
|
+
originX = x;
|
|
5435
|
+
originY = y;
|
|
5436
|
+
h = -h;
|
|
5437
|
+
x -= w;
|
|
5438
|
+
rotateAngle = 180;
|
|
5439
|
+
break;
|
|
5440
|
+
// Flip vertical
|
|
5441
|
+
|
|
5442
|
+
case 4:
|
|
5443
|
+
// Do nothing, image will be flipped
|
|
5444
|
+
break;
|
|
5445
|
+
// Flip horizontally and rotate 270 degrees CW
|
|
5446
|
+
|
|
5447
|
+
case 5:
|
|
5448
|
+
originX = x;
|
|
5449
|
+
originY = y;
|
|
5450
|
+
var _ref2 = [h, w];
|
|
5451
|
+
w = _ref2[0];
|
|
5452
|
+
h = _ref2[1];
|
|
5453
|
+
y -= h;
|
|
5454
|
+
rotateAngle = 90;
|
|
5455
|
+
break;
|
|
5456
|
+
// Rotate 90 degrees CW
|
|
5457
|
+
|
|
5458
|
+
case 6:
|
|
5459
|
+
originX = x;
|
|
5460
|
+
originY = y;
|
|
5461
|
+
var _ref3 = [h, w];
|
|
5462
|
+
w = _ref3[0];
|
|
5463
|
+
h = _ref3[1];
|
|
5464
|
+
h = -h;
|
|
5465
|
+
rotateAngle = 90;
|
|
5466
|
+
break;
|
|
5467
|
+
// Flip horizontally and rotate 90 degrees CW
|
|
5468
|
+
|
|
5469
|
+
case 7:
|
|
5470
|
+
originX = x;
|
|
5471
|
+
originY = y;
|
|
5472
|
+
var _ref4 = [h, w];
|
|
5473
|
+
w = _ref4[0];
|
|
5474
|
+
h = _ref4[1];
|
|
5475
|
+
h = -h;
|
|
5476
|
+
w = -w;
|
|
5477
|
+
x -= w;
|
|
5478
|
+
rotateAngle = 90;
|
|
5479
|
+
break;
|
|
5480
|
+
// Rotate 270 degrees CW
|
|
5481
|
+
|
|
5482
|
+
case 8:
|
|
5483
|
+
originX = x;
|
|
5484
|
+
originY = y;
|
|
5485
|
+
var _ref5 = [h, w];
|
|
5486
|
+
w = _ref5[0];
|
|
5487
|
+
h = _ref5[1];
|
|
5488
|
+
h = -h;
|
|
5489
|
+
x -= w;
|
|
5490
|
+
y -= h;
|
|
5491
|
+
rotateAngle = -90;
|
|
5492
|
+
break;
|
|
5493
|
+
}
|
|
5494
|
+
} else {
|
|
5495
|
+
h = -h;
|
|
5496
|
+
y -= h;
|
|
5497
|
+
rotateAngle = 0;
|
|
5347
5498
|
} // create link annotations if the link option is given
|
|
5348
5499
|
|
|
5349
5500
|
|
|
@@ -5365,7 +5516,14 @@ var ImagesMixin = {
|
|
|
5365
5516
|
}
|
|
5366
5517
|
|
|
5367
5518
|
this.save();
|
|
5368
|
-
|
|
5519
|
+
|
|
5520
|
+
if (rotateAngle) {
|
|
5521
|
+
this.rotate(rotateAngle, {
|
|
5522
|
+
origin: [originX, originY]
|
|
5523
|
+
});
|
|
5524
|
+
}
|
|
5525
|
+
|
|
5526
|
+
this.transform(w, 0, 0, h, x, y);
|
|
5369
5527
|
this.addContent("/".concat(image.label, " Do"));
|
|
5370
5528
|
this.restore();
|
|
5371
5529
|
return this;
|
|
@@ -6473,7 +6631,10 @@ var AcroFormMixin = {
|
|
|
6473
6631
|
var result = 0;
|
|
6474
6632
|
Object.keys(options).forEach(function (key) {
|
|
6475
6633
|
if (FIELD_FLAGS[key]) {
|
|
6476
|
-
|
|
6634
|
+
if (options[key]) {
|
|
6635
|
+
result |= FIELD_FLAGS[key];
|
|
6636
|
+
}
|
|
6637
|
+
|
|
6477
6638
|
delete options[key];
|
|
6478
6639
|
}
|
|
6479
6640
|
});
|
|
@@ -6606,7 +6767,7 @@ var AttachmentsMixin = {
|
|
|
6606
6767
|
} else {
|
|
6607
6768
|
var match;
|
|
6608
6769
|
|
|
6609
|
-
if (match = /^data:(
|
|
6770
|
+
if (match = /^data:(.*?);base64,(.*)$/.exec(src)) {
|
|
6610
6771
|
if (match[1]) {
|
|
6611
6772
|
refBody.Subtype = match[1].replace('/', '#2F');
|
|
6612
6773
|
}
|
|
@@ -6693,6 +6854,196 @@ function isEqual(a, b) {
|
|
|
6693
6854
|
return a.Subtype === b.Subtype && a.Params.CheckSum.toString() === b.Params.CheckSum.toString() && a.Params.Size === b.Params.Size && a.Params.CreationDate === b.Params.CreationDate && a.Params.ModDate === b.Params.ModDate;
|
|
6694
6855
|
}
|
|
6695
6856
|
|
|
6857
|
+
var PDFA = {
|
|
6858
|
+
initPDFA: function initPDFA(pSubset) {
|
|
6859
|
+
if (pSubset.charAt(pSubset.length - 3) === '-') {
|
|
6860
|
+
this.subset_conformance = pSubset.charAt(pSubset.length - 1).toUpperCase();
|
|
6861
|
+
this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
|
|
6862
|
+
} else {
|
|
6863
|
+
// Default to Basic conformance when user doesn't specify
|
|
6864
|
+
this.subset_conformance = 'B';
|
|
6865
|
+
this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
|
|
6866
|
+
}
|
|
6867
|
+
},
|
|
6868
|
+
endSubset: function endSubset() {
|
|
6869
|
+
this._addPdfaMetadata();
|
|
6870
|
+
|
|
6871
|
+
var jsPath = "".concat(__dirname, "/data/sRGB_IEC61966_2_1.icc");
|
|
6872
|
+
var jestPath = "".concat(__dirname, "/../color_profiles/sRGB_IEC61966_2_1.icc");
|
|
6873
|
+
|
|
6874
|
+
this._addColorOutputIntent(fs.existsSync(jsPath) ? jsPath : jestPath);
|
|
6875
|
+
},
|
|
6876
|
+
_addColorOutputIntent: function _addColorOutputIntent(pICCPath) {
|
|
6877
|
+
var iccProfile = fs.readFileSync(pICCPath);
|
|
6878
|
+
var colorProfileRef = this.ref({
|
|
6879
|
+
Length: iccProfile.length,
|
|
6880
|
+
N: 3
|
|
6881
|
+
});
|
|
6882
|
+
colorProfileRef.write(iccProfile);
|
|
6883
|
+
colorProfileRef.end();
|
|
6884
|
+
var intentRef = this.ref({
|
|
6885
|
+
Type: 'OutputIntent',
|
|
6886
|
+
S: 'GTS_PDFA1',
|
|
6887
|
+
Info: new String('sRGB IEC61966-2.1'),
|
|
6888
|
+
OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
|
|
6889
|
+
DestOutputProfile: colorProfileRef
|
|
6890
|
+
});
|
|
6891
|
+
intentRef.end();
|
|
6892
|
+
this._root.data.OutputIntents = [intentRef];
|
|
6893
|
+
},
|
|
6894
|
+
_getPdfaid: function _getPdfaid() {
|
|
6895
|
+
return "\n <rdf:Description xmlns:pdfaid=\"http://www.aiim.org/pdfa/ns/id/\" rdf:about=\"\">\n <pdfaid:part>".concat(this.subset, "</pdfaid:part>\n <pdfaid:conformance>").concat(this.subset_conformance, "</pdfaid:conformance>\n </rdf:Description>\n ");
|
|
6896
|
+
},
|
|
6897
|
+
_addPdfaMetadata: function _addPdfaMetadata() {
|
|
6898
|
+
this.appendXML(this._getPdfaid());
|
|
6899
|
+
}
|
|
6900
|
+
};
|
|
6901
|
+
|
|
6902
|
+
var PDFUA = {
|
|
6903
|
+
initPDFUA: function initPDFUA() {
|
|
6904
|
+
this.subset = 1;
|
|
6905
|
+
},
|
|
6906
|
+
endSubset: function endSubset() {
|
|
6907
|
+
this._addPdfuaMetadata();
|
|
6908
|
+
},
|
|
6909
|
+
_addPdfuaMetadata: function _addPdfuaMetadata() {
|
|
6910
|
+
this.appendXML(this._getPdfuaid());
|
|
6911
|
+
},
|
|
6912
|
+
_getPdfuaid: function _getPdfuaid() {
|
|
6913
|
+
return "\n <rdf:Description xmlns:pdfuaid=\"http://www.aiim.org/pdfua/ns/id/\" rdf:about=\"\">\n <pdfuaid:part>".concat(this.subset, "</pdfuaid:part>\n </rdf:Description>\n ");
|
|
6914
|
+
}
|
|
6915
|
+
};
|
|
6916
|
+
|
|
6917
|
+
var SubsetMixin = {
|
|
6918
|
+
_importSubset: function _importSubset(subset) {
|
|
6919
|
+
Object.assign(this, subset);
|
|
6920
|
+
},
|
|
6921
|
+
initSubset: function initSubset(options) {
|
|
6922
|
+
switch (options.subset) {
|
|
6923
|
+
case 'PDF/A-1':
|
|
6924
|
+
case 'PDF/A-1a':
|
|
6925
|
+
case 'PDF/A-1b':
|
|
6926
|
+
case 'PDF/A-2':
|
|
6927
|
+
case 'PDF/A-2a':
|
|
6928
|
+
case 'PDF/A-2b':
|
|
6929
|
+
case 'PDF/A-3':
|
|
6930
|
+
case 'PDF/A-3a':
|
|
6931
|
+
case 'PDF/A-3b':
|
|
6932
|
+
this._importSubset(PDFA);
|
|
6933
|
+
|
|
6934
|
+
this.initPDFA(options.subset);
|
|
6935
|
+
break;
|
|
6936
|
+
|
|
6937
|
+
case 'PDF/UA':
|
|
6938
|
+
this._importSubset(PDFUA);
|
|
6939
|
+
|
|
6940
|
+
this.initPDFUA();
|
|
6941
|
+
break;
|
|
6942
|
+
}
|
|
6943
|
+
}
|
|
6944
|
+
};
|
|
6945
|
+
|
|
6946
|
+
var PDFMetadata = /*#__PURE__*/function () {
|
|
6947
|
+
function PDFMetadata() {
|
|
6948
|
+
_classCallCheck(this, PDFMetadata);
|
|
6949
|
+
|
|
6950
|
+
this._metadata = "\n <?xpacket begin=\"\uFEFF\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n <x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n ";
|
|
6951
|
+
}
|
|
6952
|
+
|
|
6953
|
+
_createClass(PDFMetadata, [{
|
|
6954
|
+
key: "_closeTags",
|
|
6955
|
+
value: function _closeTags() {
|
|
6956
|
+
this._metadata = this._metadata.concat("\n </rdf:RDF>\n </x:xmpmeta>\n <?xpacket end=\"w\"?>\n ");
|
|
6957
|
+
}
|
|
6958
|
+
}, {
|
|
6959
|
+
key: "append",
|
|
6960
|
+
value: function append(xml) {
|
|
6961
|
+
var newline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
6962
|
+
this._metadata = this._metadata.concat(xml);
|
|
6963
|
+
if (newline) this._metadata = this._metadata.concat('\n');
|
|
6964
|
+
}
|
|
6965
|
+
}, {
|
|
6966
|
+
key: "getXML",
|
|
6967
|
+
value: function getXML() {
|
|
6968
|
+
return this._metadata;
|
|
6969
|
+
}
|
|
6970
|
+
}, {
|
|
6971
|
+
key: "getLength",
|
|
6972
|
+
value: function getLength() {
|
|
6973
|
+
return this._metadata.length;
|
|
6974
|
+
}
|
|
6975
|
+
}, {
|
|
6976
|
+
key: "end",
|
|
6977
|
+
value: function end() {
|
|
6978
|
+
this._closeTags();
|
|
6979
|
+
|
|
6980
|
+
this._metadata = this._metadata.trim();
|
|
6981
|
+
}
|
|
6982
|
+
}]);
|
|
6983
|
+
|
|
6984
|
+
return PDFMetadata;
|
|
6985
|
+
}();
|
|
6986
|
+
|
|
6987
|
+
var MetadataMixin = {
|
|
6988
|
+
initMetadata: function initMetadata() {
|
|
6989
|
+
this.metadata = new PDFMetadata();
|
|
6990
|
+
},
|
|
6991
|
+
appendXML: function appendXML(xml) {
|
|
6992
|
+
var newline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
|
6993
|
+
this.metadata.append(xml, newline);
|
|
6994
|
+
},
|
|
6995
|
+
_addInfo: function _addInfo() {
|
|
6996
|
+
this.appendXML("\n <rdf:Description rdf:about=\"\" xmlns:xmp=\"http://ns.adobe.com/xap/1.0/\">\n <xmp:CreateDate>".concat(this.info.CreationDate.toISOString().split('.')[0] + "Z", "</xmp:CreateDate>\n <xmp:CreatorTool>").concat(this.info.Creator, "</xmp:CreatorTool>\n </rdf:Description>\n "));
|
|
6997
|
+
|
|
6998
|
+
if (this.info.Title || this.info.Author || this.info.Subject) {
|
|
6999
|
+
this.appendXML("\n <rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n ");
|
|
7000
|
+
|
|
7001
|
+
if (this.info.Title) {
|
|
7002
|
+
this.appendXML("\n <dc:title>\n <rdf:Alt>\n <rdf:li xml:lang=\"x-default\">".concat(this.info.Title, "</rdf:li>\n </rdf:Alt>\n </dc:title>\n "));
|
|
7003
|
+
}
|
|
7004
|
+
|
|
7005
|
+
if (this.info.Author) {
|
|
7006
|
+
this.appendXML("\n <dc:creator>\n <rdf:Seq>\n <rdf:li>".concat(this.info.Author, "</rdf:li>\n </rdf:Seq>\n </dc:creator>\n "));
|
|
7007
|
+
}
|
|
7008
|
+
|
|
7009
|
+
if (this.info.Subject) {
|
|
7010
|
+
this.appendXML("\n <dc:description>\n <rdf:Alt>\n <rdf:li xml:lang=\"x-default\">".concat(this.info.Subject, "</rdf:li>\n </rdf:Alt>\n </dc:description>\n "));
|
|
7011
|
+
}
|
|
7012
|
+
|
|
7013
|
+
this.appendXML("\n </rdf:Description>\n ");
|
|
7014
|
+
}
|
|
7015
|
+
|
|
7016
|
+
this.appendXML("\n <rdf:Description rdf:about=\"\" xmlns:pdf=\"http://ns.adobe.com/pdf/1.3/\">\n <pdf:Producer>".concat(this.info.Creator, "</pdf:Producer>"), false);
|
|
7017
|
+
|
|
7018
|
+
if (this.info.Keywords) {
|
|
7019
|
+
this.appendXML("\n <pdf:Keywords>".concat(this.info.Keywords, "</pdf:Keywords>"), false);
|
|
7020
|
+
}
|
|
7021
|
+
|
|
7022
|
+
this.appendXML("\n </rdf:Description>\n ");
|
|
7023
|
+
},
|
|
7024
|
+
endMetadata: function endMetadata() {
|
|
7025
|
+
this._addInfo();
|
|
7026
|
+
|
|
7027
|
+
this.metadata.end();
|
|
7028
|
+
/*
|
|
7029
|
+
Metadata was introduced in PDF 1.4, so adding it to 1.3
|
|
7030
|
+
will likely only take up more space.
|
|
7031
|
+
*/
|
|
7032
|
+
|
|
7033
|
+
if (this.version != 1.3) {
|
|
7034
|
+
this.metadataRef = this.ref({
|
|
7035
|
+
length: this.metadata.getLength(),
|
|
7036
|
+
Type: 'Metadata',
|
|
7037
|
+
Subtype: 'XML'
|
|
7038
|
+
});
|
|
7039
|
+
this.metadataRef.compress = false;
|
|
7040
|
+
this.metadataRef.write(Buffer.from(this.metadata.getXML(), 'utf-8'));
|
|
7041
|
+
this.metadataRef.end();
|
|
7042
|
+
this._root.data.Metadata = this.metadataRef;
|
|
7043
|
+
}
|
|
7044
|
+
}
|
|
7045
|
+
};
|
|
7046
|
+
|
|
6696
7047
|
var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
|
|
6697
7048
|
_inherits(PDFDocument, _stream$Readable);
|
|
6698
7049
|
|
|
@@ -6764,6 +7115,8 @@ var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
|
|
|
6764
7115
|
|
|
6765
7116
|
_this.page = null; // Initialize mixins
|
|
6766
7117
|
|
|
7118
|
+
_this.initMetadata();
|
|
7119
|
+
|
|
6767
7120
|
_this.initColor();
|
|
6768
7121
|
|
|
6769
7122
|
_this.initVector();
|
|
@@ -6776,7 +7129,9 @@ var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
|
|
|
6776
7129
|
|
|
6777
7130
|
_this.initOutline();
|
|
6778
7131
|
|
|
6779
|
-
_this.initMarkings(options);
|
|
7132
|
+
_this.initMarkings(options);
|
|
7133
|
+
|
|
7134
|
+
_this.initSubset(options); // Initialize the metadata
|
|
6780
7135
|
|
|
6781
7136
|
|
|
6782
7137
|
_this.info = {
|
|
@@ -7025,6 +7380,12 @@ var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
|
|
|
7025
7380
|
this.endOutline();
|
|
7026
7381
|
this.endMarkings();
|
|
7027
7382
|
|
|
7383
|
+
if (this.subset) {
|
|
7384
|
+
this.endSubset();
|
|
7385
|
+
}
|
|
7386
|
+
|
|
7387
|
+
this.endMetadata();
|
|
7388
|
+
|
|
7028
7389
|
this._root.end();
|
|
7029
7390
|
|
|
7030
7391
|
this._root.data.Pages.end();
|
|
@@ -7114,6 +7475,7 @@ var mixin = function mixin(methods) {
|
|
|
7114
7475
|
Object.assign(PDFDocument.prototype, methods);
|
|
7115
7476
|
};
|
|
7116
7477
|
|
|
7478
|
+
mixin(MetadataMixin);
|
|
7117
7479
|
mixin(ColorMixin);
|
|
7118
7480
|
mixin(VectorMixin);
|
|
7119
7481
|
mixin(FontsMixin);
|
|
@@ -7124,6 +7486,7 @@ mixin(OutlineMixin);
|
|
|
7124
7486
|
mixin(MarkingsMixin);
|
|
7125
7487
|
mixin(AcroFormMixin);
|
|
7126
7488
|
mixin(AttachmentsMixin);
|
|
7489
|
+
mixin(SubsetMixin);
|
|
7127
7490
|
PDFDocument.LineWrapper = LineWrapper;
|
|
7128
7491
|
|
|
7129
7492
|
export default PDFDocument;
|