pdfkit 0.13.0 → 0.14.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 CHANGED
@@ -1,6 +1,9 @@
1
1
  ## pdfkit changelog
2
2
 
3
- ### Unreleased
3
+ ### [v0.14.0] - 2023-11-09
4
+
5
+ - Add support for PDF/A-1b, PDF/A-1a, PDF/A-2b, PDF/A-2a, PDF/A-3b, PDF/A-3a
6
+ - Update crypto-js to v4.2.0 (properly fix security issue)
4
7
 
5
8
  ### [v0.13.0] - 2021-10-24
6
9
 
Binary file
package/js/pdfkit.es5.js CHANGED
@@ -7,44 +7,6 @@ import { EventEmitter } from 'events';
7
7
  import LineBreaker from 'linebreak';
8
8
  import PNG from 'png-js';
9
9
 
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
10
  function _classCallCheck(instance, Constructor) {
49
11
  if (!(instance instanceof Constructor)) {
50
12
  throw new TypeError("Cannot call a class as a function");
@@ -82,6 +44,40 @@ function _defineProperty(obj, key, value) {
82
44
  return obj;
83
45
  }
84
46
 
47
+ function ownKeys(object, enumerableOnly) {
48
+ var keys = Object.keys(object);
49
+
50
+ if (Object.getOwnPropertySymbols) {
51
+ var symbols = Object.getOwnPropertySymbols(object);
52
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
53
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
54
+ });
55
+ keys.push.apply(keys, symbols);
56
+ }
57
+
58
+ return keys;
59
+ }
60
+
61
+ function _objectSpread2(target) {
62
+ for (var i = 1; i < arguments.length; i++) {
63
+ var source = arguments[i] != null ? arguments[i] : {};
64
+
65
+ if (i % 2) {
66
+ ownKeys(Object(source), true).forEach(function (key) {
67
+ _defineProperty(target, key, source[key]);
68
+ });
69
+ } else if (Object.getOwnPropertyDescriptors) {
70
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
71
+ } else {
72
+ ownKeys(Object(source)).forEach(function (key) {
73
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
74
+ });
75
+ }
76
+ }
77
+
78
+ return target;
79
+ }
80
+
85
81
  function _inherits(subClass, superClass) {
86
82
  if (typeof superClass !== "function" && superClass !== null) {
87
83
  throw new TypeError("Super expression must either be null or a function");
@@ -119,7 +115,7 @@ function _isNativeReflectConstruct() {
119
115
  if (typeof Proxy === "function") return true;
120
116
 
121
117
  try {
122
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
118
+ Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
123
119
  return true;
124
120
  } catch (e) {
125
121
  return false;
@@ -178,21 +174,18 @@ function _arrayWithHoles(arr) {
178
174
  }
179
175
 
180
176
  function _iterableToArray(iter) {
181
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
177
+ if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
182
178
  }
183
179
 
184
180
  function _iterableToArrayLimit(arr, i) {
185
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
186
-
187
- if (_i == null) return;
181
+ if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
188
182
  var _arr = [];
189
183
  var _n = true;
190
184
  var _d = false;
191
-
192
- var _s, _e;
185
+ var _e = undefined;
193
186
 
194
187
  try {
195
- for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
188
+ for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
196
189
  _arr.push(_s.value);
197
190
 
198
191
  if (i && _arr.length === i) break;
@@ -237,9 +230,9 @@ function _nonIterableRest() {
237
230
  }
238
231
 
239
232
  function _createForOfIteratorHelper(o, allowArrayLike) {
240
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
233
+ var it;
241
234
 
242
- if (!it) {
235
+ if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) {
243
236
  if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
244
237
  if (it) o = it;
245
238
  var i = 0;
@@ -272,7 +265,7 @@ function _createForOfIteratorHelper(o, allowArrayLike) {
272
265
  err;
273
266
  return {
274
267
  s: function () {
275
- it = it.call(o);
268
+ it = o[Symbol.iterator]();
276
269
  },
277
270
  n: function () {
278
271
  var step = it.next();
@@ -371,7 +364,9 @@ var PDFTree = /*#__PURE__*/function () {
371
364
  }
372
365
  }, {
373
366
  key: "_compareKeys",
374
- value: function _compareKeys() {
367
+ value: function _compareKeys()
368
+ /*a, b*/
369
+ {
375
370
  throw new Error('Must be implemented by subclasses');
376
371
  }
377
372
  }, {
@@ -381,7 +376,9 @@ var PDFTree = /*#__PURE__*/function () {
381
376
  }
382
377
  }, {
383
378
  key: "_dataForKey",
384
- value: function _dataForKey() {
379
+ value: function _dataForKey()
380
+ /*k*/
381
+ {
385
382
  throw new Error('Must be implemented by subclasses');
386
383
  }
387
384
  }]);
@@ -725,6 +722,23 @@ var PDFPage = /*#__PURE__*/function () {
725
722
 
726
723
 
727
724
  _createClass(PDFPage, [{
725
+ key: "maxY",
726
+ value: function maxY() {
727
+ return this.height - this.margins.bottom;
728
+ }
729
+ }, {
730
+ key: "write",
731
+ value: function write(chunk) {
732
+ return this.content.write(chunk);
733
+ }
734
+ }, {
735
+ key: "end",
736
+ value: function end() {
737
+ this.dictionary.end();
738
+ this.resources.end();
739
+ return this.content.end();
740
+ }
741
+ }, {
728
742
  key: "fonts",
729
743
  get: function get() {
730
744
  var data = this.resources.data;
@@ -766,23 +780,6 @@ var PDFPage = /*#__PURE__*/function () {
766
780
  var data = this.dictionary.data;
767
781
  return data.StructParents != null ? data.StructParents : data.StructParents = this.document.createStructParentTreeNextKey();
768
782
  }
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
783
  }]);
787
784
 
788
785
  return PDFPage;
@@ -1257,6 +1254,41 @@ function saslprep(input) {
1257
1254
  }
1258
1255
 
1259
1256
  var PDFSecurity = /*#__PURE__*/function () {
1257
+ _createClass(PDFSecurity, null, [{
1258
+ key: "generateFileID",
1259
+ value: function generateFileID() {
1260
+ var info = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
1261
+ var infoStr = "".concat(info.CreationDate.getTime(), "\n");
1262
+
1263
+ for (var key in info) {
1264
+ // eslint-disable-next-line no-prototype-builtins
1265
+ if (!info.hasOwnProperty(key)) {
1266
+ continue;
1267
+ }
1268
+
1269
+ infoStr += "".concat(key, ": ").concat(info[key].valueOf(), "\n");
1270
+ }
1271
+
1272
+ return wordArrayToBuffer(CryptoJS.MD5(infoStr));
1273
+ }
1274
+ }, {
1275
+ key: "generateRandomWordArray",
1276
+ value: function generateRandomWordArray(bytes) {
1277
+ return CryptoJS.lib.WordArray.random(bytes);
1278
+ }
1279
+ }, {
1280
+ key: "create",
1281
+ value: function create(document) {
1282
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1283
+
1284
+ if (!options.ownerPassword && !options.userPassword) {
1285
+ return null;
1286
+ }
1287
+
1288
+ return new PDFSecurity(document, options);
1289
+ }
1290
+ }]);
1291
+
1260
1292
  function PDFSecurity(document) {
1261
1293
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1262
1294
 
@@ -1449,39 +1481,6 @@ var PDFSecurity = /*#__PURE__*/function () {
1449
1481
  value: function end() {
1450
1482
  this.dictionary.end();
1451
1483
  }
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
1484
  }]);
1486
1485
 
1487
1486
  return PDFSecurity;
@@ -3244,6 +3243,13 @@ var WIN_ANSI_MAP = {
3244
3243
  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
3244
 
3246
3245
  var AFMFont = /*#__PURE__*/function () {
3246
+ _createClass(AFMFont, null, [{
3247
+ key: "open",
3248
+ value: function open(filename) {
3249
+ return new AFMFont(fs.readFileSync(filename, 'utf8'));
3250
+ }
3251
+ }]);
3252
+
3247
3253
  function AFMFont(contents) {
3248
3254
  _classCallCheck(this, AFMFont);
3249
3255
 
@@ -3388,11 +3394,6 @@ var AFMFont = /*#__PURE__*/function () {
3388
3394
 
3389
3395
  return advances;
3390
3396
  }
3391
- }], [{
3392
- key: "open",
3393
- value: function open(filename) {
3394
- return new AFMFont(fs.readFileSync(filename, 'utf8'));
3395
- }
3396
3397
  }]);
3397
3398
 
3398
3399
  return AFMFont;
@@ -3790,6 +3791,14 @@ var EmbeddedFont = /*#__PURE__*/function (_PDFFont) {
3790
3791
  descriptor.data.FontFile2 = fontFile;
3791
3792
  }
3792
3793
 
3794
+ if (this.document.subset) {
3795
+ var CIDSet = Buffer.from('FFFFFFFFC0', 'hex');
3796
+ var CIDSetRef = this.document.ref();
3797
+ CIDSetRef.write(CIDSet);
3798
+ CIDSetRef.end();
3799
+ descriptor.data.CIDSet = CIDSetRef;
3800
+ }
3801
+
3793
3802
  descriptor.end();
3794
3803
  var descendantFontData = {
3795
3804
  Type: 'Font',
@@ -6693,6 +6702,175 @@ function isEqual(a, b) {
6693
6702
  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
6703
  }
6695
6704
 
6705
+ var PDFA = {
6706
+ initPDFA: function initPDFA(pSubset) {
6707
+ if (pSubset.charAt(pSubset.length - 3) === '-') {
6708
+ this.subset_conformance = pSubset.charAt(pSubset.length - 1).toUpperCase();
6709
+ this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
6710
+ } else {
6711
+ // Default to Basic conformance when user doesn't specify
6712
+ this.subset_conformance = 'B';
6713
+ this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
6714
+ }
6715
+ },
6716
+ endSubset: function endSubset() {
6717
+ this._addPdfaMetadata();
6718
+
6719
+ var jsPath = "".concat(__dirname, "/data/sRGB_IEC61966_2_1.icc");
6720
+ var jestPath = "".concat(__dirname, "/../color_profiles/sRGB_IEC61966_2_1.icc");
6721
+
6722
+ this._addColorOutputIntent(fs.existsSync(jsPath) ? jsPath : jestPath);
6723
+ },
6724
+ _addColorOutputIntent: function _addColorOutputIntent(pICCPath) {
6725
+ var iccProfile = fs.readFileSync(pICCPath);
6726
+ var colorProfileRef = this.ref({
6727
+ Length: iccProfile.length,
6728
+ N: 3
6729
+ });
6730
+ colorProfileRef.write(iccProfile);
6731
+ colorProfileRef.end();
6732
+ var intentRef = this.ref({
6733
+ Type: 'OutputIntent',
6734
+ S: 'GTS_PDFA1',
6735
+ Info: new String('sRGB IEC61966-2.1'),
6736
+ OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
6737
+ DestOutputProfile: colorProfileRef
6738
+ });
6739
+ intentRef.end();
6740
+ this._root.data.OutputIntents = [intentRef];
6741
+ },
6742
+ _getPdfaid: function _getPdfaid() {
6743
+ 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 ");
6744
+ },
6745
+ _addPdfaMetadata: function _addPdfaMetadata() {
6746
+ this.appendXML(this._getPdfaid());
6747
+ }
6748
+ };
6749
+
6750
+ var SubsetMixin = {
6751
+ _importSubset: function _importSubset(subset) {
6752
+ Object.assign(this, subset);
6753
+ },
6754
+ initSubset: function initSubset(options) {
6755
+ switch (options.subset) {
6756
+ case 'PDF/A-1':
6757
+ case 'PDF/A-1a':
6758
+ case 'PDF/A-1b':
6759
+ case 'PDF/A-2':
6760
+ case 'PDF/A-2a':
6761
+ case 'PDF/A-2b':
6762
+ case 'PDF/A-3':
6763
+ case 'PDF/A-3a':
6764
+ case 'PDF/A-3b':
6765
+ this._importSubset(PDFA);
6766
+
6767
+ this.initPDFA(options.subset);
6768
+ break;
6769
+ }
6770
+ }
6771
+ };
6772
+
6773
+ var PDFMetadata = /*#__PURE__*/function () {
6774
+ function PDFMetadata() {
6775
+ _classCallCheck(this, PDFMetadata);
6776
+
6777
+ 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 ";
6778
+ }
6779
+
6780
+ _createClass(PDFMetadata, [{
6781
+ key: "_closeTags",
6782
+ value: function _closeTags() {
6783
+ this._metadata = this._metadata.concat("\n </rdf:RDF>\n </x:xmpmeta>\n <?xpacket end=\"w\"?>\n ");
6784
+ }
6785
+ }, {
6786
+ key: "append",
6787
+ value: function append(xml) {
6788
+ var newline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
6789
+ this._metadata = this._metadata.concat(xml);
6790
+ if (newline) this._metadata = this._metadata.concat('\n');
6791
+ }
6792
+ }, {
6793
+ key: "getXML",
6794
+ value: function getXML() {
6795
+ return this._metadata;
6796
+ }
6797
+ }, {
6798
+ key: "getLength",
6799
+ value: function getLength() {
6800
+ return this._metadata.length;
6801
+ }
6802
+ }, {
6803
+ key: "end",
6804
+ value: function end() {
6805
+ this._closeTags();
6806
+
6807
+ this._metadata = this._metadata.trim();
6808
+ }
6809
+ }]);
6810
+
6811
+ return PDFMetadata;
6812
+ }();
6813
+
6814
+ var MetadataMixin = {
6815
+ initMetadata: function initMetadata() {
6816
+ this.metadata = new PDFMetadata();
6817
+ },
6818
+ appendXML: function appendXML(xml) {
6819
+ var newline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
6820
+ this.metadata.append(xml, newline);
6821
+ },
6822
+ _addInfo: function _addInfo() {
6823
+ 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 "));
6824
+
6825
+ if (this.info.Title || this.info.Author || this.info.Subject) {
6826
+ this.appendXML("\n <rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n ");
6827
+
6828
+ if (this.info.Title) {
6829
+ 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 "));
6830
+ }
6831
+
6832
+ if (this.info.Author) {
6833
+ this.appendXML("\n <dc:creator>\n <rdf:Seq>\n <rdf:li>".concat(this.info.Author, "</rdf:li>\n </rdf:Seq>\n </dc:creator>\n "));
6834
+ }
6835
+
6836
+ if (this.info.Subject) {
6837
+ 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 "));
6838
+ }
6839
+
6840
+ this.appendXML("\n </rdf:Description>\n ");
6841
+ }
6842
+
6843
+ 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);
6844
+
6845
+ if (this.info.Keywords) {
6846
+ this.appendXML("\n <pdf:Keywords>".concat(this.info.Keywords, "</pdf:Keywords>"), false);
6847
+ }
6848
+
6849
+ this.appendXML("\n </rdf:Description>\n ");
6850
+ },
6851
+ endMetadata: function endMetadata() {
6852
+ this._addInfo();
6853
+
6854
+ this.metadata.end();
6855
+ /*
6856
+ Metadata was introduced in PDF 1.4, so adding it to 1.3
6857
+ will likely only take up more space.
6858
+ */
6859
+
6860
+ if (this.version != 1.3) {
6861
+ this.metadataRef = this.ref({
6862
+ length: this.metadata.getLength(),
6863
+ Type: 'Metadata',
6864
+ Subtype: 'XML'
6865
+ });
6866
+ this.metadataRef.compress = false;
6867
+ this.metadataRef.write(Buffer.from(this.metadata.getXML(), 'utf-8'));
6868
+ this.metadataRef.end();
6869
+ this._root.data.Metadata = this.metadataRef;
6870
+ }
6871
+ }
6872
+ };
6873
+
6696
6874
  var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
6697
6875
  _inherits(PDFDocument, _stream$Readable);
6698
6876
 
@@ -6764,6 +6942,8 @@ var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
6764
6942
 
6765
6943
  _this.page = null; // Initialize mixins
6766
6944
 
6945
+ _this.initMetadata();
6946
+
6767
6947
  _this.initColor();
6768
6948
 
6769
6949
  _this.initVector();
@@ -6776,7 +6956,9 @@ var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
6776
6956
 
6777
6957
  _this.initOutline();
6778
6958
 
6779
- _this.initMarkings(options); // Initialize the metadata
6959
+ _this.initMarkings(options);
6960
+
6961
+ _this.initSubset(options); // Initialize the metadata
6780
6962
 
6781
6963
 
6782
6964
  _this.info = {
@@ -7025,6 +7207,12 @@ var PDFDocument = /*#__PURE__*/function (_stream$Readable) {
7025
7207
  this.endOutline();
7026
7208
  this.endMarkings();
7027
7209
 
7210
+ if (this.subset) {
7211
+ this.endSubset();
7212
+ }
7213
+
7214
+ this.endMetadata();
7215
+
7028
7216
  this._root.end();
7029
7217
 
7030
7218
  this._root.data.Pages.end();
@@ -7114,6 +7302,7 @@ var mixin = function mixin(methods) {
7114
7302
  Object.assign(PDFDocument.prototype, methods);
7115
7303
  };
7116
7304
 
7305
+ mixin(MetadataMixin);
7117
7306
  mixin(ColorMixin);
7118
7307
  mixin(VectorMixin);
7119
7308
  mixin(FontsMixin);
@@ -7124,6 +7313,7 @@ mixin(OutlineMixin);
7124
7313
  mixin(MarkingsMixin);
7125
7314
  mixin(AcroFormMixin);
7126
7315
  mixin(AttachmentsMixin);
7316
+ mixin(SubsetMixin);
7127
7317
  PDFDocument.LineWrapper = LineWrapper;
7128
7318
 
7129
7319
  export default PDFDocument;