pdfkit 0.15.0 → 0.15.2

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,17 @@
1
1
  ## pdfkit changelog
2
2
 
3
- ### Unreleased
3
+ ### [v0.15.2] - 2024-12-15
4
+
5
+ - Fix index not counting when rendering ordered lists (#1517)
6
+ - Fix PDF/A3 compliance of attachments
7
+ - Fix CIDSet generation only for PDF/A1 subset
8
+ - Fix missing acroform font dictionary
9
+ - Fix modify time comparison check equality embedded files
10
+
11
+ ### [v0.15.1] - 2024-10-30
12
+
13
+ - Fix browserify transform sRGB_IEC61966_2_1.icc file
14
+ - Fix time comparison check equality embedded files
4
15
 
5
16
  ### [v0.15.0] - 2024-03-23
6
17
 
package/README.md CHANGED
@@ -129,7 +129,7 @@ complex documents with a very small amount of code. For more, see the `demo` fol
129
129
  There are three ways to use PDFKit in the browser:
130
130
 
131
131
  - Use [Browserify](http://browserify.org/). See demo [source code](demo/browser.js) and [build script](https://github.com/foliojs/pdfkit/blob/master/package.json#L56)
132
- - Use [webpack](https://webpack.js.org/). See [complete example](https://github.com/blikblum/pdfkit-webpack-example).
132
+ - Use [webpack](https://webpack.js.org/). See [complete example](examples/webpack).
133
133
  - Use prebuilt version. Distributed as `pdfkit.standalone.js` file in the [releases](https://github.com/foliojs/pdfkit/releases) or in the package `js` folder.
134
134
 
135
135
  In addition to PDFKit, you'll need somewhere to stream the output to. HTML5 has a
package/js/pdfkit.es.js CHANGED
@@ -2734,7 +2734,7 @@ class EmbeddedFont extends PDFFont {
2734
2734
  } else {
2735
2735
  descriptor.data.FontFile2 = fontFile;
2736
2736
  }
2737
- if (this.document.subset) {
2737
+ if (this.document.subset && this.document.subset === 1) {
2738
2738
  const CIDSet = Buffer.from('FFFFFFFFC0', 'hex');
2739
2739
  const CIDSetRef = this.document.ref();
2740
2740
  CIDSetRef.write(CIDSet);
@@ -3375,11 +3375,10 @@ var TextMixin = {
3375
3375
  return `${text}.`;
3376
3376
  }
3377
3377
  };
3378
- const drawListItem = function (listItem) {
3378
+ const drawListItem = function (listItem, i) {
3379
3379
  wrapper = new LineWrapper(this, options);
3380
3380
  wrapper.on('line', this._line);
3381
3381
  level = 1;
3382
- let i = 0;
3383
3382
  wrapper.once('firstLine', () => {
3384
3383
  let item, itemType, labelType, bodyType;
3385
3384
  if (options.structParent) {
@@ -3436,7 +3435,7 @@ var TextMixin = {
3436
3435
  wrapper.wrap(listItem, options);
3437
3436
  };
3438
3437
  for (let i = 0; i < items.length; i++) {
3439
- drawListItem.call(this, items[i]);
3438
+ drawListItem.call(this, items[i], i);
3440
3439
  }
3441
3440
  return this;
3442
3441
  },
@@ -4958,7 +4957,7 @@ var AcroFormMixin = {
4958
4957
  _fieldDict(name, type) {
4959
4958
  let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
4960
4959
  if (!this._acroform) {
4961
- throw new Error('Call document.initForms() method before adding form elements to document');
4960
+ throw new Error('Call document.initForm() method before adding form elements to document');
4962
4961
  }
4963
4962
  let opts = Object.assign({}, options);
4964
4963
  if (type !== null) {
@@ -5088,7 +5087,7 @@ var AcroFormMixin = {
5088
5087
  },
5089
5088
  _resolveFont(options) {
5090
5089
  // add current font to document-level AcroForm dict if necessary
5091
- if (this._acroform.fonts[this._font.id] === null) {
5090
+ if (this._acroform.fonts[this._font.id] == null) {
5092
5091
  this._acroform.fonts[this._font.id] = this._font.ref();
5093
5092
  }
5094
5093
 
@@ -5160,11 +5159,13 @@ var AttachmentsMixin = {
5160
5159
  * * options.hidden: if true, do not add attachment to EmbeddedFiles dictionary. Useful for file attachment annotations
5161
5160
  * * options.creationDate: override creation date
5162
5161
  * * options.modifiedDate: override modified date
5162
+ * * options.relationship: Relationship between the PDF document and its attached file. Can be 'Alternative', 'Data', 'Source', 'Supplement' or 'Unspecified'.
5163
5163
  * @returns filespec reference
5164
5164
  */
5165
5165
  file(src) {
5166
5166
  let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5167
5167
  options.name = options.name || src;
5168
+ options.relationship = options.relationship || 'Unspecified';
5168
5169
  const refBody = {
5169
5170
  Type: 'EmbeddedFile',
5170
5171
  Params: {}
@@ -5235,6 +5236,7 @@ var AttachmentsMixin = {
5235
5236
  // add filespec for embedded file
5236
5237
  const fileSpecBody = {
5237
5238
  Type: 'Filespec',
5239
+ AFRelationship: options.relationship,
5238
5240
  F: new String(options.name),
5239
5241
  EF: {
5240
5242
  F: ref
@@ -5249,13 +5251,20 @@ var AttachmentsMixin = {
5249
5251
  if (!options.hidden) {
5250
5252
  this.addNamedEmbeddedFile(options.name, filespec);
5251
5253
  }
5254
+
5255
+ // Add file to the catalogue to be PDF/A3 compliant
5256
+ if (this._root.data.AF) {
5257
+ this._root.data.AF.push(filespec);
5258
+ } else {
5259
+ this._root.data.AF = [filespec];
5260
+ }
5252
5261
  return filespec;
5253
5262
  }
5254
5263
  };
5255
5264
 
5256
5265
  /** check two embedded file metadata objects for equality */
5257
5266
  function isEqual(a, b) {
5258
- 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;
5267
+ return a.Subtype === b.Subtype && a.Params.CheckSum.toString() === b.Params.CheckSum.toString() && a.Params.Size === b.Params.Size && a.Params.CreationDate.getTime() === b.Params.CreationDate.getTime() && (a.Params.ModDate === undefined && b.Params.ModDate === undefined || a.Params.ModDate.getTime() === b.Params.ModDate.getTime());
5259
5268
  }
5260
5269
 
5261
5270
  var PDFA = {
@@ -5271,10 +5280,10 @@ var PDFA = {
5271
5280
  },
5272
5281
  endSubset() {
5273
5282
  this._addPdfaMetadata();
5274
- this._addColorOutputIntent(`${__dirname}/data/sRGB_IEC61966_2_1.icc`);
5283
+ this._addColorOutputIntent();
5275
5284
  },
5276
- _addColorOutputIntent(pICCPath) {
5277
- const iccProfile = fs.readFileSync(pICCPath);
5285
+ _addColorOutputIntent() {
5286
+ const iccProfile = fs.readFileSync(`${__dirname}/data/sRGB_IEC61966_2_1.icc`);
5278
5287
  const colorProfileRef = this.ref({
5279
5288
  Length: iccProfile.length,
5280
5289
  N: 3