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.
@@ -59,7 +59,9 @@ class PDFTree {
59
59
  return out.join('\n');
60
60
  }
61
61
 
62
- _compareKeys() {
62
+ _compareKeys()
63
+ /*a, b*/
64
+ {
63
65
  throw new Error('Must be implemented by subclasses');
64
66
  }
65
67
 
@@ -67,7 +69,9 @@ class PDFTree {
67
69
  throw new Error('Must be implemented by subclasses');
68
70
  }
69
71
 
70
- _dataForKey() {
72
+ _dataForKey()
73
+ /*k*/
74
+ {
71
75
  throw new Error('Must be implemented by subclasses');
72
76
  }
73
77
 
@@ -3237,6 +3241,14 @@ class EmbeddedFont extends PDFFont {
3237
3241
  descriptor.data.FontFile2 = fontFile;
3238
3242
  }
3239
3243
 
3244
+ if (this.document.subset) {
3245
+ var CIDSet = Buffer.from('FFFFFFFFC0', 'hex');
3246
+ var CIDSetRef = this.document.ref();
3247
+ CIDSetRef.write(CIDSet);
3248
+ CIDSetRef.end();
3249
+ descriptor.data.CIDSet = CIDSetRef;
3250
+ }
3251
+
3240
3252
  descriptor.end();
3241
3253
  var descendantFontData = {
3242
3254
  Type: 'Font',
@@ -4991,18 +5003,29 @@ var OutlineMixin = {
4991
5003
 
4992
5004
  };
4993
5005
 
5006
+ function _defineProperty(obj, key, value) {
5007
+ if (key in obj) {
5008
+ Object.defineProperty(obj, key, {
5009
+ value: value,
5010
+ enumerable: true,
5011
+ configurable: true,
5012
+ writable: true
5013
+ });
5014
+ } else {
5015
+ obj[key] = value;
5016
+ }
5017
+
5018
+ return obj;
5019
+ }
5020
+
4994
5021
  function ownKeys(object, enumerableOnly) {
4995
5022
  var keys = Object.keys(object);
4996
5023
 
4997
5024
  if (Object.getOwnPropertySymbols) {
4998
5025
  var symbols = Object.getOwnPropertySymbols(object);
4999
-
5000
- if (enumerableOnly) {
5001
- symbols = symbols.filter(function (sym) {
5002
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
5003
- });
5004
- }
5005
-
5026
+ if (enumerableOnly) symbols = symbols.filter(function (sym) {
5027
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
5028
+ });
5006
5029
  keys.push.apply(keys, symbols);
5007
5030
  }
5008
5031
 
@@ -5029,21 +5052,6 @@ function _objectSpread2(target) {
5029
5052
  return target;
5030
5053
  }
5031
5054
 
5032
- function _defineProperty(obj, key, value) {
5033
- if (key in obj) {
5034
- Object.defineProperty(obj, key, {
5035
- value: value,
5036
- enumerable: true,
5037
- configurable: true,
5038
- writable: true
5039
- });
5040
- } else {
5041
- obj[key] = value;
5042
- }
5043
-
5044
- return obj;
5045
- }
5046
-
5047
5055
  /*
5048
5056
  PDFStructureContent - a reference to a marked structure content
5049
5057
  By Ben Schmidt
@@ -5150,7 +5158,7 @@ class PDFStructureElement {
5150
5158
  }
5151
5159
 
5152
5160
  _addContentToParentTree(content) {
5153
- content.refs.forEach(_ref => {
5161
+ content.refs.forEach((_ref) => {
5154
5162
  var {
5155
5163
  pageRef,
5156
5164
  mcid
@@ -5258,7 +5266,7 @@ class PDFStructureElement {
5258
5266
  }
5259
5267
 
5260
5268
  if (child instanceof PDFStructureContent) {
5261
- child.refs.forEach(_ref2 => {
5269
+ child.refs.forEach((_ref2) => {
5262
5270
  var {
5263
5271
  pageRef,
5264
5272
  mcid
@@ -6044,6 +6052,176 @@ function isEqual(a, b) {
6044
6052
  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;
6045
6053
  }
6046
6054
 
6055
+ var PDFA = {
6056
+ initPDFA(pSubset) {
6057
+ if (pSubset.charAt(pSubset.length - 3) === '-') {
6058
+ this.subset_conformance = pSubset.charAt(pSubset.length - 1).toUpperCase();
6059
+ this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
6060
+ } else {
6061
+ // Default to Basic conformance when user doesn't specify
6062
+ this.subset_conformance = 'B';
6063
+ this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
6064
+ }
6065
+ },
6066
+
6067
+ endSubset() {
6068
+ this._addPdfaMetadata();
6069
+
6070
+ var jsPath = "".concat(__dirname, "/data/sRGB_IEC61966_2_1.icc");
6071
+ var jestPath = "".concat(__dirname, "/../color_profiles/sRGB_IEC61966_2_1.icc");
6072
+
6073
+ this._addColorOutputIntent(fs.existsSync(jsPath) ? jsPath : jestPath);
6074
+ },
6075
+
6076
+ _addColorOutputIntent(pICCPath) {
6077
+ var iccProfile = fs.readFileSync(pICCPath);
6078
+ var colorProfileRef = this.ref({
6079
+ Length: iccProfile.length,
6080
+ N: 3
6081
+ });
6082
+ colorProfileRef.write(iccProfile);
6083
+ colorProfileRef.end();
6084
+ var intentRef = this.ref({
6085
+ Type: 'OutputIntent',
6086
+ S: 'GTS_PDFA1',
6087
+ Info: new String('sRGB IEC61966-2.1'),
6088
+ OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
6089
+ DestOutputProfile: colorProfileRef
6090
+ });
6091
+ intentRef.end();
6092
+ this._root.data.OutputIntents = [intentRef];
6093
+ },
6094
+
6095
+ _getPdfaid() {
6096
+ 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 ");
6097
+ },
6098
+
6099
+ _addPdfaMetadata() {
6100
+ this.appendXML(this._getPdfaid());
6101
+ }
6102
+
6103
+ };
6104
+
6105
+ var SubsetMixin = {
6106
+ _importSubset(subset) {
6107
+ Object.assign(this, subset);
6108
+ },
6109
+
6110
+ initSubset(options) {
6111
+ switch (options.subset) {
6112
+ case 'PDF/A-1':
6113
+ case 'PDF/A-1a':
6114
+ case 'PDF/A-1b':
6115
+ case 'PDF/A-2':
6116
+ case 'PDF/A-2a':
6117
+ case 'PDF/A-2b':
6118
+ case 'PDF/A-3':
6119
+ case 'PDF/A-3a':
6120
+ case 'PDF/A-3b':
6121
+ this._importSubset(PDFA);
6122
+
6123
+ this.initPDFA(options.subset);
6124
+ break;
6125
+ }
6126
+ }
6127
+
6128
+ };
6129
+
6130
+ class PDFMetadata {
6131
+ constructor() {
6132
+ 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 ";
6133
+ }
6134
+
6135
+ _closeTags() {
6136
+ this._metadata = this._metadata.concat("\n </rdf:RDF>\n </x:xmpmeta>\n <?xpacket end=\"w\"?>\n ");
6137
+ }
6138
+
6139
+ append(xml) {
6140
+ var newline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
6141
+ this._metadata = this._metadata.concat(xml);
6142
+ if (newline) this._metadata = this._metadata.concat('\n');
6143
+ }
6144
+
6145
+ getXML() {
6146
+ return this._metadata;
6147
+ }
6148
+
6149
+ getLength() {
6150
+ return this._metadata.length;
6151
+ }
6152
+
6153
+ end() {
6154
+ this._closeTags();
6155
+
6156
+ this._metadata = this._metadata.trim();
6157
+ }
6158
+
6159
+ }
6160
+
6161
+ var MetadataMixin = {
6162
+ initMetadata() {
6163
+ this.metadata = new PDFMetadata();
6164
+ },
6165
+
6166
+ appendXML(xml) {
6167
+ var newline = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
6168
+ this.metadata.append(xml, newline);
6169
+ },
6170
+
6171
+ _addInfo() {
6172
+ 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 "));
6173
+
6174
+ if (this.info.Title || this.info.Author || this.info.Subject) {
6175
+ this.appendXML("\n <rdf:Description rdf:about=\"\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\">\n ");
6176
+
6177
+ if (this.info.Title) {
6178
+ 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 "));
6179
+ }
6180
+
6181
+ if (this.info.Author) {
6182
+ this.appendXML("\n <dc:creator>\n <rdf:Seq>\n <rdf:li>".concat(this.info.Author, "</rdf:li>\n </rdf:Seq>\n </dc:creator>\n "));
6183
+ }
6184
+
6185
+ if (this.info.Subject) {
6186
+ 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 "));
6187
+ }
6188
+
6189
+ this.appendXML("\n </rdf:Description>\n ");
6190
+ }
6191
+
6192
+ 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);
6193
+
6194
+ if (this.info.Keywords) {
6195
+ this.appendXML("\n <pdf:Keywords>".concat(this.info.Keywords, "</pdf:Keywords>"), false);
6196
+ }
6197
+
6198
+ this.appendXML("\n </rdf:Description>\n ");
6199
+ },
6200
+
6201
+ endMetadata() {
6202
+ this._addInfo();
6203
+
6204
+ this.metadata.end();
6205
+ /*
6206
+ Metadata was introduced in PDF 1.4, so adding it to 1.3
6207
+ will likely only take up more space.
6208
+ */
6209
+
6210
+ if (this.version != 1.3) {
6211
+ this.metadataRef = this.ref({
6212
+ length: this.metadata.getLength(),
6213
+ Type: 'Metadata',
6214
+ Subtype: 'XML'
6215
+ });
6216
+ this.metadataRef.compress = false;
6217
+ this.metadataRef.write(Buffer.from(this.metadata.getXML(), 'utf-8'));
6218
+ this.metadataRef.end();
6219
+ this._root.data.Metadata = this.metadataRef;
6220
+ }
6221
+ }
6222
+
6223
+ };
6224
+
6047
6225
  /*
6048
6226
  PDFDocument - represents an entire PDF document
6049
6227
  By Devon Govett
@@ -6108,13 +6286,15 @@ class PDFDocument extends stream.Readable {
6108
6286
 
6109
6287
  this.page = null; // Initialize mixins
6110
6288
 
6289
+ this.initMetadata();
6111
6290
  this.initColor();
6112
6291
  this.initVector();
6113
6292
  this.initFonts(options.font);
6114
6293
  this.initText();
6115
6294
  this.initImages();
6116
6295
  this.initOutline();
6117
- this.initMarkings(options); // Initialize the metadata
6296
+ this.initMarkings(options);
6297
+ this.initSubset(options); // Initialize the metadata
6118
6298
 
6119
6299
  this.info = {
6120
6300
  Producer: 'PDFKit',
@@ -6336,6 +6516,12 @@ class PDFDocument extends stream.Readable {
6336
6516
  this.endOutline();
6337
6517
  this.endMarkings();
6338
6518
 
6519
+ if (this.subset) {
6520
+ this.endSubset();
6521
+ }
6522
+
6523
+ this.endMetadata();
6524
+
6339
6525
  this._root.end();
6340
6526
 
6341
6527
  this._root.data.Pages.end();
@@ -6411,6 +6597,7 @@ var mixin = methods => {
6411
6597
  Object.assign(PDFDocument.prototype, methods);
6412
6598
  };
6413
6599
 
6600
+ mixin(MetadataMixin);
6414
6601
  mixin(ColorMixin);
6415
6602
  mixin(VectorMixin);
6416
6603
  mixin(FontsMixin);
@@ -6421,6 +6608,7 @@ mixin(OutlineMixin);
6421
6608
  mixin(MarkingsMixin);
6422
6609
  mixin(AcroFormMixin);
6423
6610
  mixin(AttachmentsMixin);
6611
+ mixin(SubsetMixin);
6424
6612
  PDFDocument.LineWrapper = LineWrapper;
6425
6613
 
6426
6614
  export default PDFDocument;