muhammara 4.0.0 → 5.0.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 (109) hide show
  1. package/CHANGELOG.md +51 -1
  2. package/README.md +10 -4
  3. package/binding.gyp +4 -4
  4. package/lib/PDFRStreamForBuffer.js +4 -5
  5. package/lib/PDFRStreamForFile.js +1 -1
  6. package/lib/PDFStreamForResponse.js +1 -1
  7. package/lib/PDFWStreamForFile.js +1 -1
  8. package/lib/Recipe.js +7 -7
  9. package/lib/muhammara.js +2 -2
  10. package/lib/recipe/annotation.js +49 -15
  11. package/lib/recipe/colors.js +1 -1
  12. package/lib/recipe/coordinate.js +5 -5
  13. package/lib/recipe/encrypt.js +1 -1
  14. package/lib/recipe/font.js +8 -6
  15. package/lib/recipe/htmlToTextObjects.js +1 -1
  16. package/lib/recipe/image.js +1 -1
  17. package/lib/recipe/info.js +5 -5
  18. package/lib/recipe/insertPage.js +2 -2
  19. package/lib/recipe/page.js +10 -7
  20. package/lib/recipe/shapes.js +14 -14
  21. package/lib/recipe/split.js +1 -1
  22. package/lib/recipe/table.js +5 -5
  23. package/lib/recipe/text.helper.js +3 -3
  24. package/lib/recipe/text.js +44 -27
  25. package/lib/recipe/utils.js +3 -3
  26. package/lib/recipe/vector-polygon.js +2 -2
  27. package/lib/recipe/vector.helper.js +6 -6
  28. package/lib/recipe/vector.js +17 -17
  29. package/muhammara.d.ts +94 -50
  30. package/node_modules/@mapbox/node-pre-gyp/.github/workflows/codeql.yml +74 -0
  31. package/node_modules/@mapbox/node-pre-gyp/CHANGELOG.md +3 -0
  32. package/node_modules/@mapbox/node-pre-gyp/package.json +10 -10
  33. package/node_modules/are-we-there-yet/package.json +1 -1
  34. package/node_modules/balanced-match/package.json +2 -1
  35. package/node_modules/brace-expansion/package.json +1 -2
  36. package/node_modules/debug/README.md +1 -1
  37. package/node_modules/debug/package.json +11 -9
  38. package/node_modules/debug/src/browser.js +3 -1
  39. package/node_modules/debug/src/node.js +2 -2
  40. package/node_modules/detect-libc/README.md +4 -1
  41. package/node_modules/detect-libc/index.d.ts +3 -0
  42. package/node_modules/detect-libc/lib/detect-libc.js +93 -4
  43. package/node_modules/detect-libc/lib/filesystem.js +41 -0
  44. package/node_modules/detect-libc/lib/process.js +11 -3
  45. package/node_modules/detect-libc/package.json +13 -6
  46. package/node_modules/gauge/package.json +1 -1
  47. package/node_modules/glob/package.json +1 -1
  48. package/node_modules/inflight/package.json +1 -1
  49. package/node_modules/ms/index.js +1 -1
  50. package/node_modules/ms/license.md +1 -1
  51. package/node_modules/ms/package.json +19 -17
  52. package/node_modules/ms/readme.md +1 -2
  53. package/node_modules/node-fetch/README.md +2 -1
  54. package/node_modules/node-fetch/lib/index.es.js +1 -5
  55. package/node_modules/node-fetch/lib/index.js +1 -4
  56. package/node_modules/node-fetch/lib/index.mjs +1 -5
  57. package/node_modules/node-fetch/package.json +5 -5
  58. package/node_modules/npmlog/package.json +1 -1
  59. package/node_modules/path-is-absolute/package.json +1 -2
  60. package/node_modules/rimraf/package.json +1 -1
  61. package/node_modules/semver/README.md +49 -32
  62. package/node_modules/semver/bin/semver.js +5 -14
  63. package/node_modules/semver/classes/range.js +28 -13
  64. package/node_modules/semver/classes/semver.js +1 -1
  65. package/node_modules/semver/functions/coerce.js +13 -5
  66. package/node_modules/semver/internal/lrucache.js +40 -0
  67. package/node_modules/semver/internal/re.js +7 -2
  68. package/node_modules/semver/package.json +11 -21
  69. package/node_modules/tar/README.md +10 -0
  70. package/node_modules/tar/lib/pack.js +18 -6
  71. package/node_modules/tar/lib/parse.js +46 -3
  72. package/node_modules/tar/lib/replace.js +1 -1
  73. package/node_modules/tar/lib/unpack.js +22 -5
  74. package/node_modules/tar/lib/update.js +1 -1
  75. package/node_modules/tar/package.json +5 -10
  76. package/node_modules/yallist/package.json +1 -2
  77. package/package.json +10 -10
  78. package/src/FormXObjectDriver.cpp +1 -1
  79. package/src/FormXObjectDriver.h +1 -1
  80. package/src/ImageXObjectDriver.cpp +1 -1
  81. package/src/ImageXObjectDriver.h +1 -1
  82. package/src/InfoDictionaryDriver.cpp +14 -14
  83. package/src/InfoDictionaryDriver.h +14 -14
  84. package/src/PDFBooleanDriver.cpp +1 -1
  85. package/src/PDFBooleanDriver.h +1 -1
  86. package/src/PDFHexStringDriver.cpp +1 -1
  87. package/src/PDFHexStringDriver.h +1 -1
  88. package/src/PDFIntegerDriver.cpp +1 -1
  89. package/src/PDFIntegerDriver.h +1 -1
  90. package/src/PDFLiteralStringDriver.cpp +1 -1
  91. package/src/PDFLiteralStringDriver.h +1 -1
  92. package/src/PDFNameDriver.cpp +1 -1
  93. package/src/PDFNameDriver.h +1 -1
  94. package/src/PDFNullDriver.cpp +1 -1
  95. package/src/PDFNullDriver.h +1 -1
  96. package/src/PDFPageDriver.cpp +12 -12
  97. package/src/PDFPageDriver.h +12 -12
  98. package/src/PDFRealDriver.cpp +1 -1
  99. package/src/PDFRealDriver.h +1 -1
  100. package/src/PDFSymbolDriver.cpp +1 -1
  101. package/src/PDFSymbolDriver.h +1 -1
  102. package/src/deps/LibTiff/tif_config.h +2 -0
  103. package/src/deps/ZLib/binding.gyp +3 -3
  104. package/src/deps/ZLib/zconf.h +6 -0
  105. package/src/nodes.h +10 -2
  106. package/node_modules/lru-cache/LICENSE +0 -15
  107. package/node_modules/lru-cache/README.md +0 -166
  108. package/node_modules/lru-cache/index.js +0 -334
  109. package/node_modules/lru-cache/package.json +0 -69
package/CHANGELOG.md CHANGED
@@ -7,6 +7,47 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [5.0.0] - 2024-09-08
11
+
12
+ ### Added
13
+
14
+ - Add electron 24.7 and 24.8
15
+ - Add electron 25.4, 25.5, 25.6, 25.7, 25.8 and 25.9
16
+ - Add electron 26.0, 26.1, 26.2, 26.3, 26.4, 26.5, 26.6
17
+ - Add electron 27.0, 27.1, 27.2 and 27.3
18
+ - Add electron 28.0, 28.1, 28.2 and 28.3
19
+ - Add electron 29.0, 29.1, 29.2, 29.3 and 29.4
20
+ - Add electron 30.0, 30.1, 30.2, 30.3 and 30.4
21
+ - Add electron 31.0, 31.1, 31.2, 31.3 and 31.4
22
+ - Add electron 32.0
23
+ - Add node v22.0.0
24
+
25
+ ### Remove
26
+
27
+ - Outdated electron 23.x versions
28
+ - Node version <= 16
29
+
30
+ ### Update
31
+
32
+ - Update dependencies
33
+ - Including tar which removes a security vulnerability
34
+ - new Buffer to Buffer.from
35
+
36
+ ## [4.1.0] - 2023-12-13
37
+
38
+ ### Fixed
39
+
40
+ - definitions: appendPage optionnal parameter
41
+ - Build musl/musl-arm with node 20
42
+ - Support negative rotation in recipe page changes
43
+ - registerFont now returns recipe as stated in typescript definition
44
+
45
+ ### Added
46
+
47
+ - Add nodejs v21.0.0
48
+
49
+ ## [4.0.0] - 2023-07-14
50
+
10
51
  ### Fixed
11
52
 
12
53
  - Underline in text object
@@ -21,14 +62,20 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
21
62
  - Electron v24.1, 24.2, 24.3, 24.4, 24.5, 24.6
22
63
  - Add node 20.x
23
64
  - Add electron v25.0, 25.1, 25.2, 25.3
65
+ - Option to add annotation replies to annotations
66
+ - Textboxes now show title and date as annotations in pdfs
24
67
 
25
68
  ### Removed
26
69
 
27
70
  - Dependency to static-eval and static-module as they are not used directly
71
+ - Node versions: 11.x - 14.x
72
+ - Electron versions: 11.x - 14.2
28
73
 
29
74
  ### Changed
30
75
 
76
+ - Updated node-gyp version to 1.0.10
31
77
  - Older node ubuntu 18.04 builds are now building on docker, as github actions removed 18.04
78
+ - CI linux builds use ubuntu 20.04 instead of 18.04 -> glibc Update, see readme for breaking changes in v4
32
79
 
33
80
  ## [3.8.0] - 2023-03-01
34
81
 
@@ -391,7 +438,10 @@ with the following changes.
391
438
 
392
439
  - Initial release
393
440
 
394
- [unreleased]: https://github.com/julianhille/MuhammaraJS/compare/3.8.0...HEAD
441
+ [unreleased]: https://github.com/julianhille/MuhammaraJS/compare/5.0.0...HEAD
442
+ [5.0.0]: https://github.com/julianhille/MuhammaraJS/compare/4.1.0...5.0.0
443
+ [4.1.0]: https://github.com/julianhille/MuhammaraJS/compare/4.0.0...4.1.0
444
+ [4.0.0]: https://github.com/julianhille/MuhammaraJS/compare/3.8.0...4.0.0
395
445
  [3.8.0]: https://github.com/julianhille/MuhammaraJS/compare/3.7.0...3.8.0
396
446
  [3.7.0]: https://github.com/julianhille/MuhammaraJS/compare/3.6.0...3.7.0
397
447
  [3.6.0]: https://github.com/julianhille/MuhammaraJS/compare/3.5.0...3.6.0
package/README.md CHANGED
@@ -4,12 +4,12 @@
4
4
  [![Build status](https://github.com/julianhille/MuhammaraJS/actions/workflows/build.yml/badge.svg?branch=develop)](https://github.com/julianhille/MuhammaraJS/actions/workflows/build.yml)
5
5
 
6
6
  Welcome to MuhammaraJS.
7
- A Fast NodeJS Module for Creating, Parsing an Manipulating PDF Files and Streams.
7
+ A Fast NodeJS Module for creating, parsing and manipulating PDF files and streams.
8
8
 
9
9
  Original Project (CPP base version)
10
10
  Project site is [here](http://www.pdfhummus.com).
11
11
 
12
- If you are looking for a C++ Library go [here](https://github.com/galkahana/PDF-Writer).
12
+ If you are looking for a C++ library go [here](https://github.com/galkahana/PDF-Writer).
13
13
 
14
14
  ## Hummus JS is the base
15
15
 
@@ -19,7 +19,7 @@ He did an awesome job, but discontinued hummusjs.
19
19
  The documentation for MuhammaraJS / HummusJS is still located at the
20
20
  hummusJS github wiki: available [here](https://github.com/galkahana/HummusJS/wiki)
21
21
 
22
- ## muhammara-recipe '(formerly known as hummus-recipe) as been added
22
+ ## muhammara-recipe (formerly known as hummus-recipe) as been added
23
23
 
24
24
  Muhammara-recipe and hummus-recipe has been integrated, dependencies updated
25
25
  and is now shipped along with muhammara itself.
@@ -49,6 +49,12 @@ This won't affect a lot of you but still.
49
49
  This means the glibc has been raised to 2.31 which might break pre-builts for you.
50
50
  It is still possible to build for older glibc version.
51
51
 
52
+ ### Version 5.x
53
+
54
+ - Node <= 16 pre-builts have been removed
55
+ - Electron <= 23 pre-builts have been removed
56
+ - GCC 13 needed / std ++ 20 (only needed if you compile yourself)
57
+
52
58
  # Installation
53
59
 
54
60
  ```
@@ -167,7 +173,7 @@ pdfDoc
167
173
  stroke: [0, 0, 140],
168
174
  fill: [153, 143, 32],
169
175
  lineWidth: 5,
170
- }
176
+ },
171
177
  )
172
178
  .rectangle(240, 400, 50, 50, {
173
179
  stroke: "#3b7721",
package/binding.gyp CHANGED
@@ -7,8 +7,8 @@
7
7
  'dependencies': [
8
8
  './src/deps/PDFWriter/binding.gyp:pdfwriter'
9
9
  ],
10
- "cflags_cc": [ "-std=c++17" ],
11
- "cflags": [ "-std=c++17" ],
10
+ "cflags_cc": [ "-std=c++20" ],
11
+ "cflags": [ "-std=c++20" ],
12
12
  'include_dirs': [
13
13
  './src',
14
14
  './src/deps/PDFWriter',
@@ -20,7 +20,7 @@
20
20
  {
21
21
  'AdditionalOptions':
22
22
  [
23
- '/std:c++17',
23
+ '/std:c++20',
24
24
  ]
25
25
  }
26
26
  },
@@ -28,7 +28,7 @@
28
28
  ['OS=="mac"', {
29
29
  'xcode_settings': {
30
30
  'CLANG_CXX_LIBRARY': 'libc++',
31
- "OTHER_CFLAGS": [ "-std=c++17"]
31
+ "OTHER_CFLAGS": [ "-std=c++20"]
32
32
  }
33
33
  }],
34
34
  ['OS=="win"', {
@@ -5,17 +5,16 @@
5
5
  */
6
6
 
7
7
  function PDFRStreamForBuffer(buffer) {
8
- this.innerArray = Array.prototype.slice.call(buffer, 0);
8
+ this.buffer = buffer;
9
9
  this.rposition = 0;
10
- this.fileSize = this.innerArray.length;
10
+ this.fileSize = this.buffer.length;
11
11
  this.mStartPosition = 0;
12
12
  }
13
13
 
14
14
  PDFRStreamForBuffer.prototype.read = function (inAmount) {
15
15
  var amountToRead = inAmount;
16
- var arr = this.innerArray.slice(
17
- this.rposition,
18
- this.rposition + amountToRead
16
+ var arr = Array.from(
17
+ this.buffer.subarray(this.rposition, this.rposition + amountToRead),
19
18
  );
20
19
  this.rposition += amountToRead;
21
20
  return arr;
@@ -12,7 +12,7 @@ function PDFRStreamForFile(inPath) {
12
12
  }
13
13
 
14
14
  PDFRStreamForFile.prototype.read = function (inAmount) {
15
- var buffer = new Buffer(inAmount * 2);
15
+ var buffer = Buffer.alloc(inAmount * 2);
16
16
  var bytesRead = fs.readSync(this.rs, buffer, 0, inAmount, this.rposition);
17
17
  var arr = [];
18
18
 
@@ -9,7 +9,7 @@ function PDFStreamForResponse(inResponse) {
9
9
 
10
10
  PDFStreamForResponse.prototype.write = function (inBytesArray) {
11
11
  if (inBytesArray.length > 0) {
12
- this.response.write(new Buffer(inBytesArray));
12
+ this.response.write(Buffer.from(inBytesArray));
13
13
  this.position += inBytesArray.length;
14
14
  return inBytesArray.length;
15
15
  } else return 0;
@@ -12,7 +12,7 @@ function PDFWStreamForFile(inPath) {
12
12
 
13
13
  PDFWStreamForFile.prototype.write = function (inBytesArray) {
14
14
  if (inBytesArray.length > 0) {
15
- this.ws.write(new Buffer(inBytesArray));
15
+ this.ws.write(Buffer.from(inBytesArray));
16
16
  this.position += inBytesArray.length;
17
17
  return inBytesArray.length;
18
18
  } else return 0;
package/lib/Recipe.js CHANGED
@@ -79,7 +79,7 @@ class Recipe {
79
79
  this.output,
80
80
  Object.assign({}, this.encryptOptions, {
81
81
  version: this._getVersion(this.options.version),
82
- })
82
+ }),
83
83
  );
84
84
  } else {
85
85
  this.read();
@@ -90,7 +90,7 @@ class Recipe {
90
90
  new muhammara.PDFStreamForResponse(this.outStream),
91
91
  Object.assign({}, this.encryptOptions, {
92
92
  log: this.logFile,
93
- })
93
+ }),
94
94
  );
95
95
  } else {
96
96
  this.writer = muhammara.createWriterToModify(
@@ -98,7 +98,7 @@ class Recipe {
98
98
  Object.assign({}, this.encryptOptions, {
99
99
  modifiedFilePath: this.output,
100
100
  log: this.logFile,
101
- })
101
+ }),
102
102
  );
103
103
  }
104
104
  } catch (err) {
@@ -122,7 +122,7 @@ class Recipe {
122
122
  get position() {
123
123
  const { ox, oy } = this._reverseCoordinate(
124
124
  this._position.x,
125
- this._position.y
125
+ this._position.y,
126
126
  );
127
127
  return {
128
128
  x: ox,
@@ -222,7 +222,7 @@ class Recipe {
222
222
  new muhammara.PDFStreamForResponse(this.outStream),
223
223
  Object.assign({}, this.encryptOptions, {
224
224
  log: this.logFile,
225
- })
225
+ }),
226
226
  );
227
227
  } else {
228
228
  this.writer = muhammara.createWriterToModify(
@@ -230,7 +230,7 @@ class Recipe {
230
230
  Object.assign({}, this.encryptOptions, {
231
231
  modifiedFilePath: this.output,
232
232
  log: this.logFile,
233
- })
233
+ }),
234
234
  );
235
235
  }
236
236
 
@@ -242,7 +242,7 @@ class Recipe {
242
242
  if (this.isBufferSrc) {
243
243
  // eslint-disable-next-line no-console
244
244
  console.log(
245
- "Feature: Inserting Pages is not supported in Buffer Mode yet."
245
+ "Feature: Inserting Pages is not supported in Buffer Mode yet.",
246
246
  );
247
247
  } else {
248
248
  this._insertPages();
package/lib/muhammara.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var path = require("path");
2
2
  var pregyp = require("@mapbox/node-pre-gyp");
3
3
  var binding_path = pregyp.find(
4
- path.resolve(path.join(__dirname, "../package.json"))
4
+ path.resolve(path.join(__dirname, "../package.json")),
5
5
  );
6
6
  var muhammara = (module.exports = require(binding_path));
7
7
  var EventEmitter = require("events").EventEmitter;
@@ -17,7 +17,7 @@ muhammara.PDFWriter.prototype.getEvents = function () {
17
17
 
18
18
  muhammara.PDFWriter.prototype.triggerDocumentExtensionEvent = function (
19
19
  eventName,
20
- eventParams
20
+ eventParams,
21
21
  ) {
22
22
  eventParams.writer = this;
23
23
  this.getEvents().emit(eventName, eventParams);
@@ -27,30 +27,35 @@ exports.comment = function comment(text = "", x, y, options = {}) {
27
27
  * @name annot
28
28
  * @function
29
29
  * @memberof Recipe
30
- * @todo support for rich texst RC
30
+ * @todo support for rich text RC
31
31
  * @todo support for opacity CA
32
32
  * @param {number} x - The coordinate x
33
33
  * @param {number} y - The coordinate y
34
- * @param {string} subtype - The markup annotation type 'Text'|'FreeText'|'Line'|'Square'|'Circle'|'Polygon'|'PolyLine'|'Highlight'|'Underline'|'Squiggly'|'StrikeOut'|'Stamp'|'Caret'|'Ink'|'FileAttachment'|'Sound'
34
+ * @param {string} subtype - The markup annotation type 'Text'|'Link'|'FreeText'|'Line'|'Square'|'Circle'|'Polygon'|'PolyLine'|'Highlight'|'Underline'|'Squiggly'|'StrikeOut'|'Caret'|'Stamp'|'Ink'|'Popup'|'FileAttachment'|'Sound'|'Movie'|'Screen'|'Widget'|'PrinterMark'|'TrapNet'|'Watermark'|'3D'|'Redact'|'Projection'|'RichMedia'
35
35
  * @param {Object} [options] - The options
36
36
  * @param {string} [options.title] - The title.
37
- * @param {boolean} [options.open=false] - Open the annotation by default?
37
+ * @param {boolean} [options.open=false] - Open the annotation. Annotation will be closed by default. Specific to text annotations; subtype='Text'
38
+ * @param {boolean} [options.richText] - Rich text
38
39
  * @param {'invisible'|'hidden'|'print'|'nozoom'|'norotate'|'noview'|'readonly'|'locked'|'togglenoview'} [options.flag] - The flag property
39
- * @param {'Comment'|'Key'|'Note'|'Help'|'NewParagraph'|'Paragraph'|'Insert'} [options.icon] - The icon of annotation.
40
+ * @param {'Comment'|'Key'|'Note'|'Help'|'NewParagraph'|'Paragraph'|'Insert'} [options.icon='Note'] - The icon of annotation. Specific to text annotations. Default value: 'Note'
40
41
  * @param {number} [options.width] - Width
41
42
  * @param {number} [options.height] - Height
43
+ * @param {string} [options.date] - Date of annotation
44
+ * @param {string} [options.subject] - The subject.
45
+ * @param {Array} [options.replies] - Array of annotation replies
42
46
  */
43
47
  exports.annot = function annot(
44
48
  x,
45
49
  y,
46
50
  subtype,
47
- options = { text: "", width: 0, height: 0 }
51
+ options = { text: "", width: 0, height: 0 },
48
52
  ) {
49
- const { text, width, height } = options;
53
+ const { text, width, height, replies } = options;
50
54
  this.annotationsToWrite.push({
51
55
  subtype,
52
56
  args: { text, x, y, width, height, options },
53
57
  pageNumber: this.pageNumber,
58
+ replies,
54
59
  });
55
60
  return this;
56
61
  };
@@ -59,8 +64,9 @@ exports.annot = function annot(
59
64
  // Link, Popup, Movie, Widget, Screen, PrinterMark, TrapNet, Watermark, 3D
60
65
  exports._attachNonMarkupAnnot = function _attachNonMarkupAnnot() {};
61
66
 
62
- exports._annot = function _annot(subtype, args = {}, pageNumber) {
63
- const { x, y, width, height, text, options } = args;
67
+ exports._annot = function _annot(subtype, args = {}, pageNumber, ref) {
68
+ const { x, y, width, height, options, reply } = args;
69
+ let { text } = args;
64
70
  this._startDictionary(pageNumber);
65
71
  const { rotate } = this.metadata[pageNumber];
66
72
  let { nx, ny } = this._calibrateCoordinateForAnnots(x, y, 0, 0, pageNumber);
@@ -92,17 +98,26 @@ exports._annot = function _annot(subtype, args = {}, pageNumber) {
92
98
  {
93
99
  title: "",
94
100
  subject: "",
95
- date: new Date(),
101
+ date: "",
96
102
  open: false,
97
103
  flag: "", // 'readonly'
98
104
  },
99
- options
105
+ options,
100
106
  );
101
107
 
102
108
  const ex = nWidth ? nWidth : 0;
103
109
  const ey = nHeight ? nHeight : 0;
104
110
  const position = [nx, ny, nx + ex, ny + ey];
105
111
 
112
+ if (reply && ref) {
113
+ text = reply.text;
114
+ params.title = reply.title || params.title;
115
+ params.date = reply.date || params.date;
116
+ params.subject = reply.subject || params.subject;
117
+ params.richText = Boolean(reply.richText);
118
+ params.flag = reply.flag || params.flag;
119
+ }
120
+
106
121
  this.dictionaryContext
107
122
  .writeKey("Type")
108
123
  .writeNameValue("Annot")
@@ -117,7 +132,9 @@ exports._annot = function _annot(subtype, args = {}, pageNumber) {
117
132
  .writeKey("T")
118
133
  .writeLiteralStringValue(params.title || "")
119
134
  .writeKey("M")
120
- .writeLiteralStringValue(this.writer.createPDFDate(params.date).toString())
135
+ .writeLiteralStringValue(
136
+ this.writer.createPDFDate(new Date(params.date)).toString(),
137
+ )
121
138
  .writeKey("Open")
122
139
  .writeBooleanValue(params.open)
123
140
  .writeKey("F")
@@ -127,9 +144,9 @@ exports._annot = function _annot(subtype, args = {}, pageNumber) {
127
144
  * Rich Text Strings
128
145
  * 12.7.3.4
129
146
  */
130
- if (text && options.richText) {
147
+ if (text && params.richText) {
131
148
  const richText =
132
- text.substring(0, 5) !== "<?xml" ? contentToRC(text) : options.richText;
149
+ text.substring(0, 5) !== "<?xml" ? contentToRC(text) : params.richText;
133
150
  const richTextContent = richText;
134
151
  this.dictionaryContext
135
152
  .writeKey("RC")
@@ -141,6 +158,14 @@ exports._annot = function _annot(subtype, args = {}, pageNumber) {
141
158
  .writeLiteralStringValue(textContent);
142
159
  }
143
160
 
161
+ if (reply && ref) {
162
+ this.dictionaryContext
163
+ .writeKey("IRT")
164
+ .writeObjectReferenceValue(ref)
165
+ .writeKey("RT")
166
+ .writeNameValue("R");
167
+ }
168
+
144
169
  let { border, color } = options;
145
170
 
146
171
  if (this._getTextMarkupAnnotationSubtype(subtype)) {
@@ -212,12 +237,19 @@ exports._annot = function _annot(subtype, args = {}, pageNumber) {
212
237
  if (params.icon) {
213
238
  this.dictionaryContext.writeKey("Name").writeNameValue(params.icon);
214
239
  }
215
- this._endDictionary(pageNumber);
240
+ return this._endDictionary(pageNumber);
216
241
  };
217
242
 
218
243
  exports._writeAnnotations = function _writeAnnotations() {
219
244
  this.annotationsToWrite.forEach((annot) => {
220
- this._annot(annot.subtype, annot.args, annot.pageNumber);
245
+ const ref = this._annot(annot.subtype, annot.args, annot.pageNumber);
246
+
247
+ if (annot.replies) {
248
+ annot.replies.forEach((reply) => {
249
+ annot.args.reply = reply;
250
+ this._annot(annot.subtype, annot.args, annot.pageNumber, ref);
251
+ });
252
+ }
221
253
  });
222
254
  this.annotations.forEach((pageAnnots, index) => {
223
255
  this._writeAnnotation(index);
@@ -276,6 +308,8 @@ exports._endDictionary = function _endDictionary(pageNumber) {
276
308
  const pageIndex = pageNumber - 1;
277
309
  this.annotations[pageIndex] = this.annotations[pageIndex] || [];
278
310
  this.annotations[pageIndex].push(this.dictionaryObject);
311
+
312
+ return this.dictionaryObject;
279
313
  };
280
314
 
281
315
  exports._getTextMarkupAnnotationSubtype =
@@ -81,7 +81,7 @@ exports.chroma = function chroma(name, value, colorspace = "") {
81
81
  // device colorspaces gray, rgb, and cmyk.
82
82
  if (![2, 6, 8].includes(value.toString().length)) {
83
83
  throw new Error(
84
- "Color value has incorrect size for gray, rgb, or cmyk colorspaces"
84
+ "Color value has incorrect size for gray, rgb, or cmyk colorspaces",
85
85
  );
86
86
  }
87
87
 
@@ -20,7 +20,7 @@ exports._calibrateCoordinate = function _calibrateCoordinate(
20
20
  y,
21
21
  offsetX = 0,
22
22
  offsetY = 0,
23
- pageNumber
23
+ pageNumber,
24
24
  ) {
25
25
  pageNumber = pageNumber || this.pageNumber;
26
26
  const { height, mediaBox } = this.metadata[pageNumber];
@@ -41,14 +41,14 @@ exports._calibrateCoordinateForAnnots = function _calibrateCoordinateForAnnots(
41
41
  y,
42
42
  offsetX = 0,
43
43
  offsetY = 0,
44
- pageNumber
44
+ pageNumber,
45
45
  ) {
46
46
  const { nx: tx, ny: ty } = this._calibrateCoordinate(
47
47
  x,
48
48
  y,
49
49
  offsetX,
50
50
  offsetY,
51
- pageNumber
51
+ pageNumber,
52
52
  );
53
53
  const { width, height, rotate, mediaBox } = this.metadata[pageNumber];
54
54
  const startX = mediaBox[0];
@@ -78,7 +78,7 @@ exports._calibrateCoordinateForAnnots = function _calibrateCoordinateForAnnots(
78
78
  ty,
79
79
  360 - rotate,
80
80
  rotateOffsetX,
81
- rotateOffsetY
81
+ rotateOffsetY,
82
82
  );
83
83
  return {
84
84
  nx,
@@ -91,7 +91,7 @@ exports._reverseCoordinate = function _reverseCoordinate(
91
91
  y,
92
92
  offsetX = 0,
93
93
  offsetY = 0,
94
- pageNumber
94
+ pageNumber,
95
95
  ) {
96
96
  pageNumber = pageNumber || this.pageNumber;
97
97
  const { height } = this.metadata[pageNumber];
@@ -44,7 +44,7 @@ exports.permission = function permission(flags = "print") {
44
44
 
45
45
  exports._getEncryptOptions = function _getEncryptOptions(
46
46
  options,
47
- addPermissions = true
47
+ addPermissions = true,
48
48
  ) {
49
49
  const encryptOptions = {};
50
50
 
@@ -12,7 +12,7 @@ const path = require("path");
12
12
  exports.registerFont = function registerFont(
13
13
  fontName = "",
14
14
  fontSrcPath = "",
15
- type = "regular"
15
+ type = "regular",
16
16
  ) {
17
17
  return this._registerFont(fontName, fontSrcPath, type);
18
18
  };
@@ -55,7 +55,7 @@ exports._loadFonts = function _loadFonts(fontSrcPath) {
55
55
  exports._registerFont = function _registerFont(
56
56
  fontName,
57
57
  fontSrcPath,
58
- type = "regular"
58
+ type = "regular",
59
59
  ) {
60
60
  this.fonts = this.fonts || {};
61
61
  let family = fontName.toLowerCase();
@@ -79,6 +79,8 @@ exports._registerFont = function _registerFont(
79
79
  break;
80
80
  }
81
81
  this.fonts[family] = font;
82
+
83
+ return this;
82
84
  };
83
85
 
84
86
  function _getFontFile(self, options = {}) {
@@ -89,10 +91,10 @@ function _getFontFile(self, options = {}) {
89
91
  (options.bold || options.isBold) && (options.italic || options.isItalic)
90
92
  ? "bi"
91
93
  : options.italic || options.isItalic
92
- ? "i"
93
- : options.bold || options.isBold
94
- ? "b"
95
- : "r";
94
+ ? "i"
95
+ : options.bold || options.isBold
96
+ ? "b"
97
+ : "r";
96
98
 
97
99
  if (options.font) {
98
100
  const fontFamily = self.fonts[options.font.toLowerCase()];
@@ -4,7 +4,7 @@ exports.htmlToTextObjects = function (htmlCodes) {
4
4
  htmlCodes = htmlCodes.replace(/<br\/?>/g, "<p>[@@DONOT_RENDER_THIS@@]</p>");
5
5
  const nodes = new DOMParser().parseFromString(
6
6
  `<html>${htmlCodes}</html>`,
7
- "text/html"
7
+ "text/html",
8
8
  );
9
9
  const textObjects = parseNode(nodes).childs[0].childs;
10
10
  return textObjects;
@@ -17,7 +17,7 @@
17
17
  exports.image = function image(imgSrc, x, y, options = {}) {
18
18
  const { width, height, offsetX, offsetY } = this._getImgOffset(
19
19
  imgSrc,
20
- options
20
+ options,
21
21
  );
22
22
  const imgOptions = {
23
23
  transformation: {
@@ -36,7 +36,7 @@ exports._readInfo = function _readInfo() {
36
36
  .getSourceDocumentParser()
37
37
  .queryDictionaryObject(
38
38
  copyCtx.getSourceDocumentParser().getTrailer(),
39
- "Info"
39
+ "Info",
40
40
  );
41
41
 
42
42
  const oldInfo =
@@ -138,19 +138,19 @@ exports._writeInfo = function _writeInfo() {
138
138
  case "modDate":
139
139
  infoDictionary.addAdditionalInfoEntry(
140
140
  "source-ModDate",
141
- oldInfo.modDate
141
+ oldInfo.modDate,
142
142
  );
143
143
  break;
144
144
  case "creator":
145
145
  infoDictionary.addAdditionalInfoEntry(
146
146
  "source-Creator",
147
- oldInfo.creator
147
+ oldInfo.creator,
148
148
  );
149
149
  break;
150
150
  case "producer":
151
151
  infoDictionary.addAdditionalInfoEntry(
152
152
  "source-Producer",
153
- oldInfo.producer
153
+ oldInfo.producer,
154
154
  );
155
155
  break;
156
156
  default:
@@ -301,7 +301,7 @@ exports.structure = function structure(output) {
301
301
 
302
302
  const itemTrailer = pdfReader.queryDictionaryObject(
303
303
  pdfReader.getTrailer(),
304
- item
304
+ item,
305
305
  );
306
306
  logToFile(item);
307
307
  iterateObjectTypes(itemTrailer);
@@ -13,7 +13,7 @@ const hummusUtils = require("./utils");
13
13
  exports.insertPage = function insertPage(
14
14
  afterPageNumber,
15
15
  pdfSrc,
16
- srcPageNumber
16
+ srcPageNumber,
17
17
  ) {
18
18
  if (isNaN(afterPageNumber)) {
19
19
  throw new Error("The afterPageNumber is inValid.");
@@ -68,7 +68,7 @@ exports._insertPages = function _insertPages() {
68
68
  hummusUtils.appendPDFPagesFromPDFWithAnnotations(
69
69
  pdfWriter,
70
70
  info.pdfSrc,
71
- { specificRanges }
71
+ { specificRanges },
72
72
  );
73
73
  });
74
74
  }