@muhammara/native-core 7.0.0-beta.3 → 7.0.0-rc.1

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 (43) hide show
  1. package/README.md +57 -7
  2. package/THIRD_PARTY_NOTICES.md +39 -0
  3. package/index.js +120 -1
  4. package/lib/PDFRStreamForBuffer.js +52 -7
  5. package/lib/PDFRStreamForFile.js +56 -7
  6. package/lib/PDFStreamForResponse.js +22 -5
  7. package/lib/PDFWStreamForBuffer.js +49 -10
  8. package/lib/PDFWStreamForFile.js +26 -5
  9. package/lib/Recipe.js +86 -30
  10. package/lib/content-stream.js +503 -0
  11. package/lib/css-colors.js +149 -0
  12. package/lib/font-text.js +1461 -0
  13. package/lib/glyph-list.js +1127 -0
  14. package/lib/recipe/annotation.js +482 -105
  15. package/lib/recipe/appendPage.js +8 -1
  16. package/lib/recipe/colors.js +132 -35
  17. package/lib/recipe/coordinate.js +82 -16
  18. package/lib/recipe/encrypt.js +32 -13
  19. package/lib/recipe/font.js +70 -25
  20. package/lib/recipe/graphics-state.js +3 -2
  21. package/lib/recipe/htmlToTextObjects.js +154 -21
  22. package/lib/recipe/image.js +34 -9
  23. package/lib/recipe/info.js +93 -22
  24. package/lib/recipe/insertPage.js +12 -3
  25. package/lib/recipe/overlay.js +4 -2
  26. package/lib/recipe/page-references.js +436 -0
  27. package/lib/recipe/page.js +379 -275
  28. package/lib/recipe/parameters.js +11 -2
  29. package/lib/recipe/replaceText.js +464 -30
  30. package/lib/recipe/shapes.js +418 -45
  31. package/lib/recipe/split.js +6 -2
  32. package/lib/recipe/table.js +260 -173
  33. package/lib/recipe/text.helper.js +176 -10
  34. package/lib/recipe/text.js +420 -115
  35. package/lib/recipe/utils.js +66 -3
  36. package/lib/recipe/vector-line.js +101 -39
  37. package/lib/recipe/vector-polygon.js +18 -6
  38. package/lib/recipe/vector.helper.js +150 -13
  39. package/lib/recipe/vector.js +150 -53
  40. package/lib/recipe/xObjectForm.js +73 -10
  41. package/lib/recipe-constants.js +373 -0
  42. package/muhammara.d.ts +3487 -152
  43. package/package.json +1 -1
package/muhammara.d.ts CHANGED
@@ -13,63 +13,225 @@ declare namespace muhammara {
13
13
  export let PDFRStreamForBuffer: PDFRStreamForBuffer;
14
14
  export let PDFWStreamForBuffer: PDFWStreamForBuffer;
15
15
  export let PDFStreamForResponse: PDFStreamForResponse;
16
+ export let PDFDate: {
17
+ new (value?: string | Date): PDFDate;
18
+ };
19
+ export let PDFTextString: {
20
+ new (value?: string | number[]): PDFTextString;
21
+ };
16
22
 
23
+ /**
24
+ * Starts writing a new PDF.
25
+ * @param input - The output path, or a stream that receives the bytes.
26
+ * @param options - The PDF version, compression, log and encryption.
27
+ * @returns The writer; call end() to finish the PDF.
28
+ * @throws {TypeError} If the arguments are wrong, the version is not a valid
29
+ * PDF version, or the output cannot be opened.
30
+ */
17
31
  export function createWriter(
18
32
  input: FilePath | WriteStream,
19
33
  options?: PDFWriterOptions,
20
34
  ): PDFWriter;
35
+ /**
36
+ * Starts an incremental update of a PDF file, in place or into
37
+ * options.modifiedFilePath.
38
+ * @param inFile - The PDF path.
39
+ * @param options - The output path, version, compression, log and encryption.
40
+ * @returns The writer; call end() to append the update.
41
+ * @throws {TypeError} If the arguments are wrong or the PDF cannot be read.
42
+ */
21
43
  export function createWriterToModify(
22
44
  inFile: FilePath,
23
45
  options?: PDFWriterToModifyOptions,
24
46
  ): PDFWriter;
47
+ /**
48
+ * Starts an incremental update of a PDF stream. The output receives the
49
+ * original bytes followed by the update.
50
+ * @param inStream - The source PDF.
51
+ * @param outStream - The output stream.
52
+ * @param options - The version, compression, log and encryption.
53
+ * @returns The writer; call end() to append the update.
54
+ * @throws {TypeError} If the arguments are wrong or the PDF cannot be read.
55
+ */
25
56
  export function createWriterToModify(
26
57
  inStream: ReadStream,
27
58
  outStream: WriteStream,
28
59
  options?: PDFWriterToModifyOptions,
29
60
  ): PDFWriter;
30
61
 
62
+ /**
63
+ * Continues a PDF whose writer was retired with shutdown().
64
+ * @param restartFile - The output path, or the output stream, of the
65
+ * interrupted PDF.
66
+ * @param restartStateFile - The state file written by shutdown().
67
+ * @param options - The modified PDF path or stream, and the log.
68
+ * @returns The writer.
69
+ * @throws {TypeError} If the arguments are wrong or the state cannot be read.
70
+ */
31
71
  export function createWriterToContinue(
32
72
  restartFile: string,
33
73
  restartStateFile: string,
34
74
  options?: PDFWriterToContinueOptions,
35
75
  ): PDFWriter;
76
+ /**
77
+ * Opens a PDF for reading.
78
+ * @param input - The PDF path or a read stream.
79
+ * @param options - The password of an encrypted PDF.
80
+ * @returns The reader; call end() to release the file.
81
+ * @throws {TypeError} If the arguments are wrong or the PDF cannot be parsed.
82
+ */
36
83
  export function createReader(
37
84
  input: FilePath | ReadStream,
38
85
  options?: PDFReaderOptions,
39
86
  ): PDFReader;
87
+ /**
88
+ * Writes a copy of a PDF with new encryption settings, or decrypted when
89
+ * no passwords are given.
90
+ * @param originalPdfPath - The source PDF path.
91
+ * @param newPdfPath - The output path.
92
+ * @param options - The source password and the new encryption settings.
93
+ * @throws {TypeError} If the arguments are wrong, one side is a path and the
94
+ * other a stream, or the PDF cannot be recrypted.
95
+ */
40
96
  export function recrypt(
41
97
  originalPdfPath: FilePath,
42
98
  newPdfPath: FilePath,
43
99
  options?: PDFRecryptOptions,
44
100
  ): void;
101
+ /**
102
+ * Writes a copy of a PDF stream with new encryption settings, or decrypted
103
+ * when no passwords are given.
104
+ * @param originalPdfStream - The source PDF.
105
+ * @param newPdfStream - The output stream.
106
+ * @param options - The source password and the new encryption settings.
107
+ * @throws {TypeError} If the arguments are wrong or the PDF cannot be
108
+ * recrypted.
109
+ */
45
110
  export function recrypt(
46
111
  originalPdfStream: PDFRStreamForFile | PDFRStreamForBuffer,
47
112
  newPdfStream: PDFWStreamForFile | PDFWStreamForBuffer,
48
113
  options?: PDFRecryptOptions,
49
114
  ): void;
50
115
 
116
+ /**
117
+ * A JavaScript output stream. `write` receives each chunk as a `Buffer` the
118
+ * stream owns and may keep, and returns the number of bytes it accepted.
119
+ */
51
120
  export interface WriteStream {
52
- write(inBytesArray: any[]): number;
121
+ /**
122
+ * Writes bytes. Implement it on a custom output stream.
123
+ * @param inBytes - The bytes to write.
124
+ * @returns The number of bytes written.
125
+ */
126
+ write(inBytes: Buffer): number;
127
+ /**
128
+ * Returns the number of bytes written so far.
129
+ * @returns The current byte offset.
130
+ */
53
131
  getCurrentPosition(): number;
54
132
  }
55
133
 
134
+ /**
135
+ * A JavaScript log sink. `write` receives each chunk as a `Buffer` the sink
136
+ * owns and may keep, and returns the number of bytes it accepted.
137
+ */
138
+ export interface LogStream {
139
+ /**
140
+ * Writes log bytes synchronously.
141
+ * @param inBytes - The bytes to write.
142
+ * @returns The number of bytes written.
143
+ */
144
+ write(inBytes: Buffer): number;
145
+ }
146
+
147
+ /**
148
+ * A JavaScript input stream. `read` returns at most `inAmount` bytes as a
149
+ * `Uint8Array` (a `Buffer` qualifies) or an array of byte values.
150
+ */
56
151
  export interface ReadStream {
57
- read(inAmount: number): number[];
152
+ /**
153
+ * Reads the next bytes and advances the position by the amount read.
154
+ * Implement it on a custom input stream.
155
+ * @param inAmount - The maximum number of bytes to read.
156
+ * @returns The bytes read; shorter than requested at the end.
157
+ */
158
+ read(inAmount: number): Uint8Array | number[];
159
+ /**
160
+ * Tells whether bytes remain after the current position.
161
+ * @returns True while the end has not been reached.
162
+ */
58
163
  notEnded(): boolean;
164
+ /**
165
+ * Moves to a position relative to the start position.
166
+ * @param inPosition - The byte offset from the start position.
167
+ */
59
168
  setPosition(inPosition: number): void;
169
+ /**
170
+ * Moves to a position counted back from the end.
171
+ * @param inPosition - The number of bytes before the end.
172
+ */
60
173
  setPositionFromEnd(inPosition: number): void;
174
+ /**
175
+ * Advances the position without reading.
176
+ * @param inAmount - The number of bytes to skip.
177
+ */
61
178
  skip(inAmount: number): void;
179
+ /**
180
+ * Returns the position relative to the start position.
181
+ * @returns The current byte offset.
182
+ */
62
183
  getCurrentPosition(): number;
63
- moveStartPosition(inPosition: number): void;
184
+ /**
185
+ * Sets the offset that later positions are counted from, for PDF data
186
+ * that does not begin at byte zero. Optional: the reader never calls it, so
187
+ * a 6.x stream without it works unchanged.
188
+ * @param inPosition - The absolute byte offset of the start.
189
+ */
190
+ moveStartPosition?(inPosition: number): void;
64
191
  }
65
192
 
66
193
  export interface PDFPageInput {
194
+ /**
195
+ * Returns the page dictionary.
196
+ * @returns The dictionary.
197
+ * @throws {TypeError} If the page input was not created by a reader.
198
+ */
67
199
  getDictionary(): PDFDictionary;
200
+ /**
201
+ * Returns the media box, inherited from parent pages when not set.
202
+ * @returns The box [left, bottom, right, top].
203
+ * @throws {TypeError} If the page input was not created by a reader.
204
+ */
68
205
  getMediaBox(): PDFBox;
206
+ /**
207
+ * Returns the crop box, inherited from parent pages when not set.
208
+ * @returns The box [left, bottom, right, top]; the media box when not set.
209
+ * @throws {TypeError} If the page input was not created by a reader.
210
+ */
69
211
  getCropBox(): PDFBox;
212
+ /**
213
+ * Returns the trim box, inherited from parent pages when not set.
214
+ * @returns The box [left, bottom, right, top]; the crop box when not set.
215
+ * @throws {TypeError} If the page input was not created by a reader.
216
+ */
70
217
  getTrimBox(): PDFBox;
218
+ /**
219
+ * Returns the bleed box, inherited from parent pages when not set.
220
+ * @returns The box [left, bottom, right, top]; the crop box when not set.
221
+ * @throws {TypeError} If the page input was not created by a reader.
222
+ */
71
223
  getBleedBox(): PDFBox;
224
+ /**
225
+ * Returns the art box, inherited from parent pages when not set.
226
+ * @returns The box [left, bottom, right, top]; the crop box when not set.
227
+ * @throws {TypeError} If the page input was not created by a reader.
228
+ */
72
229
  getArtBox(): PDFBox;
230
+ /**
231
+ * Returns the page rotation, inherited from parent pages when not set.
232
+ * @returns The rotation in degrees, a multiple of 90.
233
+ * @throws {TypeError} If the page input was not created by a reader.
234
+ */
73
235
  getRotate(): number;
74
236
  }
75
237
 
@@ -79,9 +241,38 @@ declare namespace muhammara {
79
241
  pageIndex?: number,
80
242
  ensureContentEncapsulation?: boolean,
81
243
  ): PDFPageModifier;
244
+ /**
245
+ * Starts a content stream drawn over the existing page content.
246
+ * @returns This modifier.
247
+ * @throws {TypeError} If the page does not exist.
248
+ * @throws {TypeError} If the modifier was not created with a writer.
249
+ */
82
250
  startContext(): this;
251
+ /**
252
+ * Returns the started content context.
253
+ * @returns The content context.
254
+ * @throws {TypeError} If startContext() was not called.
255
+ * @throws {TypeError} If the modifier was not created with a writer.
256
+ */
83
257
  getContext(): XObjectContentContext;
258
+ /**
259
+ * Ends the content stream started by startContext().
260
+ * @returns This modifier.
261
+ * @throws {TypeError} If the modifier was not created with a writer.
262
+ */
84
263
  endContext(): this;
264
+ /**
265
+ * Adds a link annotation to the modified page.
266
+ * @param inUrl - The ASCII link target.
267
+ * @param left - The clickable area left edge.
268
+ * @param bottom - The clickable area bottom edge.
269
+ * @param right - The clickable area right edge.
270
+ * @param top - The clickable area top edge.
271
+ * @returns This modifier.
272
+ * @throws {TypeError} If the arguments are not a string and four numbers, or
273
+ * the URL cannot be encoded as ASCII.
274
+ * @throws {TypeError} If the modifier was not created with a writer.
275
+ */
85
276
  attachURLLinktoCurrentPage(
86
277
  inUrl: string,
87
278
  left: number,
@@ -89,27 +280,103 @@ declare namespace muhammara {
89
280
  right: number,
90
281
  top: number,
91
282
  ): this;
283
+ /**
284
+ * Writes the modified page.
285
+ * @returns This modifier.
286
+ * @throws {TypeError} If the page cannot be written.
287
+ * @throws {TypeError} If the modifier was not created with a writer.
288
+ */
92
289
  writePage(): this;
93
290
  }
94
291
 
95
- export type PDFImageType = "JPG" | "PDF" | "PNG" | "TIFF";
292
+ /** Image or document format reported by `getImageType()`. */
293
+ export const PDFImageType: {
294
+ readonly PDF: "PDF";
295
+ readonly JPG: "JPG";
296
+ readonly TIFF: "TIFF";
297
+ readonly PNG: "PNG";
298
+ };
299
+ export type PDFImageType = (typeof PDFImageType)[keyof typeof PDFImageType];
96
300
 
97
301
  export interface PDFRStreamForFile extends ReadStream {
302
+ /**
303
+ * Opens a file for reading.
304
+ * @param inPath - The file path.
305
+ * @throws {Error} If the file cannot be opened or read.
306
+ */
98
307
  new (inPath: FilePath): PDFRStreamForFile;
308
+ /**
309
+ * Reads the next bytes from the file.
310
+ * @param inAmount - The maximum number of bytes to read.
311
+ * @returns The bytes read; shorter than requested at the end.
312
+ */
313
+ read(inAmount: number): Buffer;
314
+ /**
315
+ * Closes the file.
316
+ * @param inCallback - Called once the file is closed.
317
+ */
99
318
  close(inCallback?: () => void): void;
319
+ /**
320
+ * Sets the offset that later positions are counted from.
321
+ * @param inPosition - The absolute byte offset of the start.
322
+ */
323
+ moveStartPosition(inPosition: number): void;
100
324
  }
101
325
 
102
326
  export interface PDFRStreamForBuffer extends ReadStream {
327
+ /**
328
+ * Creates a read stream over a buffer.
329
+ * @param buffer - The bytes to read.
330
+ */
103
331
  new (buffer: Buffer): PDFRStreamForBuffer;
332
+ /**
333
+ * Reads a copy of the next bytes.
334
+ * @param inAmount - The maximum number of bytes to read.
335
+ * @returns The bytes read; shorter than requested at the end.
336
+ */
337
+ read(inAmount: number): Buffer;
338
+ /**
339
+ * Sets the offset that later positions are counted from.
340
+ * @param inPosition - The absolute byte offset of the start.
341
+ */
342
+ moveStartPosition(inPosition: number): void;
104
343
  }
105
344
 
345
+ /** Device color space of a drawing color option. */
346
+ export const DeviceColorSpace: {
347
+ readonly RGB: "rgb";
348
+ readonly GRAY: "gray";
349
+ readonly CMYK: "cmyk";
350
+ };
351
+ export type DeviceColorSpace =
352
+ (typeof DeviceColorSpace)[keyof typeof DeviceColorSpace];
353
+
106
354
  export interface ColorOptions {
107
- colorspace?: string;
355
+ /**
356
+ * A DeviceColorSpace value. A `gray` or `cmyk` color must be a number; a
357
+ * color name or `#rrggbb` string is RGB and throws a `TypeError` with them.
358
+ */
359
+ colorspace?: DeviceColorSpace;
108
360
  color?: string | number;
109
361
  }
110
362
 
363
+ /**
364
+ * Paint operation a drawing helper finishes its path with. `"stroke"` is the
365
+ * default when `type` is omitted, `"fill"` fills the path, and `"clip"`
366
+ * intersects the clipping region without painting; scope it with q()/Q().
367
+ * `null` selects no paint operation and ends the path unpainted.
368
+ */
369
+ /** Paint operations for the `type` option of the drawing helpers. */
370
+ export const DrawingPathType: {
371
+ readonly STROKE: "stroke";
372
+ readonly FILL: "fill";
373
+ readonly CLIP: "clip";
374
+ };
375
+ export type DrawingPathType =
376
+ (typeof DrawingPathType)[keyof typeof DrawingPathType] | null;
377
+
111
378
  export interface GraphicOptions extends ColorOptions {
112
- type?: "stroke" | "fill" | "clip";
379
+ type?: DrawingPathType;
113
380
  width?: number;
114
381
  close?: boolean;
115
382
  }
@@ -124,7 +391,13 @@ declare namespace muhammara {
124
391
 
125
392
  export type LineJoinStyle = 0 | 1 | 2;
126
393
 
127
- export type EEncoding = "text" | "code" | "hex";
394
+ /** How text-showing operators encode string text. */
395
+ export const EEncoding: {
396
+ readonly TEXT: "text";
397
+ readonly CODE: "code";
398
+ readonly HEX: "hex";
399
+ };
400
+ export type EEncoding = (typeof EEncoding)[keyof typeof EEncoding];
128
401
 
129
402
  export const LineCapStyle: {
130
403
  readonly LINECAP_BUTT: 0;
@@ -140,86 +413,605 @@ declare namespace muhammara {
140
413
  export type Glyph = Array<[number, number]>;
141
414
 
142
415
  export interface AbstractContentContext {
416
+ /**
417
+ * Closes, fills (nonzero winding) and strokes the path; operator b.
418
+ * @returns This context.
419
+ * @throws {TypeError} If there is no content context.
420
+ */
143
421
  b(): this;
422
+ /**
423
+ * Fills (nonzero winding) and strokes the path; operator B.
424
+ * @returns This context.
425
+ * @throws {TypeError} If there is no content context.
426
+ */
144
427
  B(): this;
428
+ /**
429
+ * Closes, fills (even-odd) and strokes the path; operator b*.
430
+ * @returns This context.
431
+ * @throws {TypeError} If there is no content context.
432
+ */
145
433
  bStar(): this;
434
+ /**
435
+ * Fills (even-odd) and strokes the path; operator B*.
436
+ * @returns This context.
437
+ * @throws {TypeError} If there is no content context.
438
+ */
146
439
  BStar(): this;
440
+ /**
441
+ * Closes and strokes the path; operator s.
442
+ * @returns This context.
443
+ * @throws {TypeError} If there is no content context.
444
+ */
147
445
  s(): this;
446
+ /**
447
+ * Strokes the path; operator S.
448
+ * @returns This context.
449
+ * @throws {TypeError} If there is no content context.
450
+ */
148
451
  S(): this;
452
+ /**
453
+ * Fills the path (nonzero winding); operator f.
454
+ * @returns This context.
455
+ * @throws {TypeError} If there is no content context.
456
+ */
149
457
  f(): this;
458
+ /**
459
+ * Fills the path (nonzero winding); operator F, the obsolete form of f.
460
+ * @returns This context.
461
+ * @throws {TypeError} If there is no content context.
462
+ */
150
463
  F(): this;
464
+ /**
465
+ * Fills the path (even-odd); operator f*.
466
+ * @returns This context.
467
+ * @throws {TypeError} If there is no content context.
468
+ */
151
469
  fStar(): this;
470
+ /**
471
+ * Ends the path without painting it, for clipping; operator n.
472
+ * @returns This context.
473
+ * @throws {TypeError} If there is no content context.
474
+ */
152
475
  n(): this;
476
+ /**
477
+ * Starts a subpath; operator m.
478
+ * @param x - The x coordinate.
479
+ * @param y - The y coordinate.
480
+ * @returns This context.
481
+ * @throws {TypeError} If the arguments are not 2 numbers.
482
+ * @throws {TypeError} If there is no content context.
483
+ */
153
484
  m(x: PosX, y: PosY): this;
485
+ /**
486
+ * Adds a line to the path; operator l.
487
+ * @param x - The x coordinate.
488
+ * @param y - The y coordinate.
489
+ * @returns This context.
490
+ * @throws {TypeError} If the arguments are not 2 numbers.
491
+ * @throws {TypeError} If there is no content context.
492
+ */
154
493
  l(x: PosX, y: PosY): this;
494
+ /**
495
+ * Adds a cubic Bezier curve; operator c.
496
+ * @param x1 - The first control point x.
497
+ * @param y1 - The first control point y.
498
+ * @param x2 - The second control point x.
499
+ * @param y2 - The second control point y.
500
+ * @param x3 - The end point x.
501
+ * @param y3 - The end point y.
502
+ * @returns This context.
503
+ * @throws {TypeError} If the arguments are not 6 numbers.
504
+ * @throws {TypeError} If there is no content context.
505
+ */
155
506
  c(x1: PosX, y1: PosY, x2: PosX, y2: PosY, x3: PosX, y3: PosY): this;
507
+ /**
508
+ * Adds a Bezier curve whose first control point is the current point;
509
+ * operator v.
510
+ * @param x2 - The second control point x.
511
+ * @param y2 - The second control point y.
512
+ * @param x3 - The end point x.
513
+ * @param y3 - The end point y.
514
+ * @returns This context.
515
+ * @throws {TypeError} If the arguments are not 4 numbers.
516
+ * @throws {TypeError} If there is no content context.
517
+ */
156
518
  v(x2: PosX, y2: PosY, x3: PosX, y3: PosY): this;
519
+ /**
520
+ * Adds a Bezier curve whose second control point is the end point;
521
+ * operator y.
522
+ * @param x1 - The first control point x.
523
+ * @param y1 - The first control point y.
524
+ * @param x3 - The end point x.
525
+ * @param y3 - The end point y.
526
+ * @returns This context.
527
+ * @throws {TypeError} If the arguments are not 4 numbers.
528
+ * @throws {TypeError} If there is no content context.
529
+ */
157
530
  y(x1: PosX, y1: PosY, x3: PosX, y3: PosY): this;
531
+ /**
532
+ * Closes the current subpath; operator h.
533
+ * @returns This context.
534
+ * @throws {TypeError} If there is no content context.
535
+ */
158
536
  h(): this;
537
+ /**
538
+ * Adds a rectangle to the path; operator re.
539
+ * @param left - The left edge.
540
+ * @param bottom - The bottom edge.
541
+ * @param width - The width.
542
+ * @param height - The height.
543
+ * @returns This context.
544
+ * @throws {TypeError} If the arguments are not 4 numbers.
545
+ * @throws {TypeError} If there is no content context.
546
+ */
159
547
  re(left: number, bottom: number, width: Width, height: Height): this;
548
+ /**
549
+ * Saves the graphics state; operator q.
550
+ * @returns This context.
551
+ * @throws {TypeError} If there is no content context.
552
+ */
160
553
  q(): this;
554
+ /**
555
+ * Restores the graphics state; operator Q.
556
+ * @returns This context.
557
+ * @throws {TypeError} If there is no content context.
558
+ */
161
559
  Q(): this;
162
560
  /**
163
- * a b 0
164
- * c d 0
165
- * e f 1
561
+ * Concatenates a matrix to the current transformation; operator cm. The
562
+ * matrix is [a b 0, c d 0, e f 1].
563
+ * @param args - The matrix values a, b, c, d, e and f.
564
+ * @returns This context.
565
+ * @throws {TypeError} If the arguments are not 6 numbers.
566
+ * @throws {TypeError} If there is no content context.
166
567
  */
167
568
  cm(...args: TransformationMatrix): this;
569
+ /**
570
+ * Sets the line width; operator w.
571
+ * @param lineWidth - The width in user units.
572
+ * @returns This context.
573
+ * @throws {TypeError} If lineWidth is not a single number.
574
+ * @throws {TypeError} If there is no content context.
575
+ */
168
576
  w(lineWidth: Width): this;
577
+ /**
578
+ * Sets the line cap style; operator J.
579
+ * @param lineCapStyle - A LineCapStyle value.
580
+ * @returns This context.
581
+ * @throws {TypeError} If lineCapStyle is not a single number.
582
+ * @throws {TypeError} If there is no content context.
583
+ */
169
584
  J(lineCapStyle: LineCapStyle): this;
585
+ /**
586
+ * Sets the line join style; operator j.
587
+ * @param lineJoinStyle - 0 miter, 1 round or 2 bevel.
588
+ * @returns This context.
589
+ * @throws {TypeError} If lineJoinStyle is not a single number.
590
+ * @throws {TypeError} If there is no content context.
591
+ */
170
592
  j(lineJoinStyle: LineJoinStyle): this;
593
+ /**
594
+ * Sets the miter limit; operator M.
595
+ * @param miterLimit - The miter limit.
596
+ * @returns This context.
597
+ * @throws {TypeError} If miterLimit is not a single number.
598
+ * @throws {TypeError} If there is no content context.
599
+ */
171
600
  M(miterLimit: number): this;
172
- d(miterLimit: number[], dashPhase: number): this;
601
+ /**
602
+ * Sets the dash pattern; operator d. Values are truncated to integers.
603
+ * @param dashArray - Alternating dash and gap lengths; empty for a solid line.
604
+ * @param dashPhase - The offset into the pattern; 0 when omitted.
605
+ * @returns This context.
606
+ * @throws {TypeError} If dashArray is not an array or dashPhase is not a
607
+ * number.
608
+ * @throws {TypeError} If there is no content context.
609
+ */
610
+ d(dashArray: number[], dashPhase?: number): this;
611
+ /**
612
+ * Sets the rendering intent; operator ri.
613
+ * @param renderingIntentName - The intent, for example Perceptual.
614
+ * @returns This context.
615
+ * @throws {TypeError} If renderingIntentName is not a single string.
616
+ * @throws {TypeError} If there is no content context.
617
+ */
173
618
  ri(renderingIntentName: string): this;
619
+ /**
620
+ * Sets the flatness tolerance; operator i. The value is truncated to an
621
+ * integer.
622
+ * @param flatness - The tolerance, 0 to 100.
623
+ * @returns This context.
624
+ * @throws {TypeError} If flatness is not a single number.
625
+ * @throws {TypeError} If there is no content context.
626
+ */
174
627
  i(flatness: number): this;
628
+ /**
629
+ * Applies a graphics state resource; operator gs.
630
+ * @param graphicStateName - The ExtGState resource name.
631
+ * @returns This context.
632
+ * @throws {TypeError} If graphicStateName is not a single string.
633
+ * @throws {TypeError} If there is no content context.
634
+ */
175
635
  gs(graphicStateName: string): this;
636
+ /**
637
+ * Sets the fill and stroke opacity through a graphics state resource.
638
+ * @param opacity - The opacity, 0 to 1.
639
+ * @returns This context.
640
+ * @throws {TypeError} If opacity is not a single number from 0 to 1.
641
+ * @throws {TypeError} If there is no content context.
642
+ */
176
643
  setOpacity(opacity: number): this;
644
+ /**
645
+ * Sets the stroke color space; operator CS.
646
+ * @param colorSpaceName - A color space name or resource name.
647
+ * @returns This context.
648
+ * @throws {TypeError} If colorSpaceName is not a single string.
649
+ * @throws {TypeError} If there is no content context.
650
+ */
177
651
  CS(colorSpaceName: string): this;
652
+ /**
653
+ * Sets the fill color space; operator cs.
654
+ * @param colorSpaceName - A color space name or resource name.
655
+ * @returns This context.
656
+ * @throws {TypeError} If colorSpaceName is not a single string.
657
+ * @throws {TypeError} If there is no content context.
658
+ */
178
659
  cs(colorSpaceName: string): this;
660
+ /**
661
+ * Sets the stroke color in the current color space; operator SC.
662
+ * @param colorComponents - The components, each 0 to 1.
663
+ * @returns This context.
664
+ * @throws {TypeError} If no component is given.
665
+ * @throws {TypeError} If there is no content context.
666
+ */
179
667
  SC(...colorComponents: number[]): this;
668
+ /**
669
+ * Sets the stroke color, optionally with a pattern; operator SCN. Pass
670
+ * the components as arguments or as one array, then an optional pattern name. A pattern
671
+ * name alone selects a colored (PaintType 1) pattern.
672
+ * @param parameters - The components and an optional pattern name.
673
+ * @returns This context.
674
+ * @throws {TypeError} If the arguments are neither components nor components and a pattern name.
675
+ * @throws {TypeError} If there is no content context.
676
+ */
180
677
  SCN(...parameters: any[]): this; // This can't be materialized in TypeScript
181
678
  ////SCN(...colorComponents: number[], patternName?: string): this;
182
679
  SCN(colorComponents: number[], patternName?: string): this;
680
+ SCN(patternName: string): this;
681
+ /**
682
+ * Sets the fill color in the current color space; operator sc.
683
+ * @param colorComponents - The components, each 0 to 1.
684
+ * @returns This context.
685
+ * @throws {TypeError} If no component is given.
686
+ * @throws {TypeError} If there is no content context.
687
+ */
183
688
  sc(...colorComponents: number[]): this;
689
+ /**
690
+ * Sets the fill color, optionally with a pattern; operator scn. Pass the
691
+ * components as arguments or as one array, then an optional pattern name. A pattern
692
+ * name alone selects a colored (PaintType 1) pattern.
693
+ * @param parameters - The components and an optional pattern name.
694
+ * @returns This context.
695
+ * @throws {TypeError} If the arguments are neither components nor components and a pattern name.
696
+ * @throws {TypeError} If there is no content context.
697
+ */
184
698
  scn(...parameters: any[]): this; // This can't be materialized in TypeScript
185
699
  ////scn(...colorComponents: number[], patternName?: string): this;
186
700
  scn(colorComponents: number[], patternName?: string): this;
701
+ scn(patternName: string): this;
702
+ /**
703
+ * Sets a gray stroke color; operator G.
704
+ * @param gray - The gray level, 0 (black) to 1 (white).
705
+ * @returns This context.
706
+ * @throws {TypeError} If gray is not a single number.
707
+ * @throws {TypeError} If there is no content context.
708
+ */
187
709
  G(gray: number): this;
710
+ /**
711
+ * Sets a gray fill color; operator g.
712
+ * @param gray - The gray level, 0 (black) to 1 (white).
713
+ * @returns This context.
714
+ * @throws {TypeError} If gray is not a single number.
715
+ * @throws {TypeError} If there is no content context.
716
+ */
188
717
  g(gray: number): this;
718
+ /**
719
+ * Sets an RGB stroke color; operator RG.
720
+ * @param r - Red, 0 to 1.
721
+ * @param g - Green, 0 to 1.
722
+ * @param b - Blue, 0 to 1.
723
+ * @returns This context.
724
+ * @throws {TypeError} If the arguments are not 3 numbers.
725
+ * @throws {TypeError} If there is no content context.
726
+ */
189
727
  RG(r: number, g: number, b: number): this;
728
+ /**
729
+ * Sets an RGB fill color; operator rg.
730
+ * @param r - Red, 0 to 1.
731
+ * @param g - Green, 0 to 1.
732
+ * @param b - Blue, 0 to 1.
733
+ * @returns This context.
734
+ * @throws {TypeError} If the arguments are not 3 numbers.
735
+ * @throws {TypeError} If there is no content context.
736
+ */
190
737
  rg(r: number, g: number, b: number): this;
738
+ /**
739
+ * Sets a CMYK stroke color; operator K.
740
+ * @param c - Cyan, 0 to 1.
741
+ * @param m - Magenta, 0 to 1.
742
+ * @param y - Yellow, 0 to 1.
743
+ * @param k - Black, 0 to 1.
744
+ * @returns This context.
745
+ * @throws {TypeError} If the arguments are not 4 numbers.
746
+ * @throws {TypeError} If there is no content context.
747
+ */
191
748
  K(c: number, m: number, y: number, k: number): this;
749
+ /**
750
+ * Sets a CMYK fill color; operator k.
751
+ * @param c - Cyan, 0 to 1.
752
+ * @param m - Magenta, 0 to 1.
753
+ * @param y - Yellow, 0 to 1.
754
+ * @param k - Black, 0 to 1.
755
+ * @returns This context.
756
+ * @throws {TypeError} If the arguments are not 4 numbers.
757
+ * @throws {TypeError} If there is no content context.
758
+ */
192
759
  k(c: number, m: number, y: number, k: number): this;
760
+ /**
761
+ * Clips to the path (nonzero winding); operator W. Follow it with n.
762
+ * @returns This context.
763
+ * @throws {TypeError} If there is no content context.
764
+ */
193
765
  W(): this;
766
+ /**
767
+ * Clips to the path (even-odd); operator W*. Follow it with n.
768
+ * @returns This context.
769
+ * @throws {TypeError} If there is no content context.
770
+ */
194
771
  WStar(): this;
195
- doXObject(xObject: string | FormXObject | ImageXObject): this;
772
+ /**
773
+ * Draws an XObject; operator Do. A form or image is added to the
774
+ * resources.
775
+ * @param xObject - A resource name, a form or image, or a form object ID.
776
+ * @returns This context.
777
+ * @throws {TypeError} If xObject is not a single XObject, name or ID.
778
+ * @throws {TypeError} If there is no content context.
779
+ */
780
+ doXObject(
781
+ xObject: string | FormXObjectId | FormXObject | ImageXObject,
782
+ ): this;
783
+ /**
784
+ * Sets the character spacing; operator Tc.
785
+ * @param characterSpace - The extra space per character in text space units.
786
+ * @returns This context.
787
+ * @throws {TypeError} If characterSpace is not a single number.
788
+ * @throws {TypeError} If there is no content context.
789
+ */
196
790
  Tc(characterSpace: number): this;
791
+ /**
792
+ * Sets the word spacing; operator Tw.
793
+ * @param wordSpace - The extra space per space character in text space units.
794
+ * @returns This context.
795
+ * @throws {TypeError} If wordSpace is not a single number.
796
+ * @throws {TypeError} If there is no content context.
797
+ */
197
798
  Tw(wordSpace: number): this;
799
+ /**
800
+ * Sets the horizontal scaling; operator Tz. The value is truncated to an
801
+ * integer.
802
+ * @param horizontalScaling - The scaling in percent; 100 is normal.
803
+ * @returns This context.
804
+ * @throws {TypeError} If horizontalScaling is not a single number.
805
+ * @throws {TypeError} If there is no content context.
806
+ */
198
807
  Tz(horizontalScaling: number): this;
808
+ /**
809
+ * Sets the text leading used by T*, ' and "; operator TL.
810
+ * @param textLeading - The leading in text space units.
811
+ * @returns This context.
812
+ * @throws {TypeError} If textLeading is not a single number.
813
+ * @throws {TypeError} If there is no content context.
814
+ */
199
815
  TL(textLeading: number): this;
816
+ /**
817
+ * Sets the text rendering mode; operator Tr.
818
+ * @param renderingMode - 0 fill to 7 clip, as in ISO 32000-1 table 106.
819
+ * @returns This context.
820
+ * @throws {TypeError} If renderingMode is not a single number.
821
+ * @throws {TypeError} If there is no content context.
822
+ */
200
823
  Tr(renderingMode: number): this;
824
+ /**
825
+ * Sets the text rise; operator Ts.
826
+ * @param fontRise - The baseline shift in text space units.
827
+ * @returns This context.
828
+ * @throws {TypeError} If fontRise is not a single number.
829
+ * @throws {TypeError} If there is no content context.
830
+ */
201
831
  Ts(fontRise: number): this;
832
+ /**
833
+ * Begins a text object; operator BT.
834
+ * @returns This context.
835
+ * @throws {TypeError} If there is no content context.
836
+ */
202
837
  BT(): this;
838
+ /**
839
+ * Ends a text object; operator ET.
840
+ * @returns This context.
841
+ * @throws {TypeError} If there is no content context.
842
+ */
203
843
  ET(): this;
844
+ /**
845
+ * Moves to the start of the next line by an offset; operator Td.
846
+ * @param tX - The horizontal offset.
847
+ * @param tY - The vertical offset.
848
+ * @returns This context.
849
+ * @throws {TypeError} If the arguments are not 2 numbers.
850
+ * @throws {TypeError} If there is no content context.
851
+ */
204
852
  Td(tX: number, tY: number): this;
853
+ /**
854
+ * Moves to the next line by an offset and sets the leading to -tY;
855
+ * operator TD.
856
+ * @param tX - The horizontal offset.
857
+ * @param tY - The vertical offset.
858
+ * @returns This context.
859
+ * @throws {TypeError} If the arguments are not 2 numbers.
860
+ * @throws {TypeError} If there is no content context.
861
+ */
205
862
  TD(tX: number, tY: number): this;
863
+ /**
864
+ * Sets the text matrix; operator Tm.
865
+ * @param a - The matrix value a.
866
+ * @param b - The matrix value b.
867
+ * @param c - The matrix value c.
868
+ * @param d - The matrix value d.
869
+ * @param e - The matrix value e.
870
+ * @param f - The matrix value f.
871
+ * @returns This context.
872
+ * @throws {TypeError} If the arguments are not 6 numbers.
873
+ * @throws {TypeError} If there is no content context.
874
+ */
206
875
  Tm(a: number, b: number, c: number, d: number, e: number, f: number): this;
876
+ /**
877
+ * Moves to the start of the next line; operator T*.
878
+ * @returns This context.
879
+ * @throws {TypeError} If there is no content context.
880
+ */
207
881
  TStar(): this;
882
+ /**
883
+ * Sets the font and size; operator Tf.
884
+ * @param fontReferenced - A font from getFontForFile(), or a font resource name.
885
+ * @param fontSize - The font size.
886
+ * @returns This context.
887
+ * @throws {TypeError} If the arguments are not a font or string and a number.
888
+ * @throws {TypeError} If there is no content context.
889
+ */
208
890
  Tf(fontReferenced: UsedFont | string, fontSize: number): this;
891
+ /**
892
+ * Shows text; operator Tj. Set a font with Tf() first.
893
+ * @param text - The text, or glyphs of the current font.
894
+ * @param options - Text encoding options.
895
+ * @returns This context.
896
+ * @throws {TypeError} If the arguments are wrong.
897
+ * @throws {TypeError} If there is no content context.
898
+ */
899
+ Tj(text: string, options?: TextRenderOptions): this;
900
+ Tj(glyphs: Glyph): this;
209
901
  Tj(text: string | Glyph): this;
902
+ /**
903
+ * Moves to the next line and shows text; operator '.
904
+ * @param text - The text, or glyphs of the current font.
905
+ * @param options - Text encoding options.
906
+ * @returns This context.
907
+ * @throws {TypeError} If the arguments are wrong.
908
+ * @throws {TypeError} If there is no content context.
909
+ */
910
+ Quote(text: string, options?: TextRenderOptions): this;
911
+ Quote(glyphs: Glyph): this;
210
912
  Quote(text: string | Glyph): this;
913
+ /**
914
+ * Sets word and character spacing, moves to the next line and shows text;
915
+ * operator ".
916
+ * @param wordSpacing - The word spacing.
917
+ * @param characterSpacing - The character spacing.
918
+ * @param text - The text, or glyphs of the current font.
919
+ * @param options - Text encoding options.
920
+ * @returns This context.
921
+ * @throws {TypeError} If the arguments are wrong.
922
+ * @throws {TypeError} If there is no content context.
923
+ */
924
+ DoubleQuote(
925
+ wordSpacing: number,
926
+ characterSpacing: number,
927
+ text: string,
928
+ options?: TextRenderOptions,
929
+ ): this;
930
+ DoubleQuote(
931
+ wordSpacing: number,
932
+ characterSpacing: number,
933
+ glyphs: Glyph,
934
+ ): this;
211
935
  DoubleQuote(
212
936
  wordSpacing: number,
213
- characterString: number,
937
+ characterSpacing: number,
214
938
  text: string | Glyph,
215
939
  ): this;
216
- TJ(value: string | Glyph, options?: TextRenderOptions): this;
940
+ /**
941
+ * Shows text with kerning adjustments; operator TJ. Pass the array items
942
+ * as separate arguments: strings with numeric adjustments in thousandths of
943
+ * text space, optionally followed by options.
944
+ * @param items - The strings or glyphs and adjustments.
945
+ * @returns This context.
946
+ * @throws {TypeError} If an item is not a string, glyph list or number.
947
+ * @throws {TypeError} If there is no content context.
948
+ */
949
+ TJ(...items: (string | number)[]): this;
950
+ TJ(
951
+ ...items: [string | number, ...(string | number)[], TextRenderOptions]
952
+ ): this;
953
+ /** Glyph variant: glyph lists with numeric kerning adjustments. */
954
+ TJ(...items: (Glyph | number)[]): this;
955
+ /**
956
+ * Writes content-stream code as given, unchecked.
957
+ * @param freeCode - The code.
958
+ * @returns This context.
959
+ * @throws {TypeError} If freeCode is not a single string.
960
+ * @throws {TypeError} If there is no content context.
961
+ */
217
962
  writeFreeCode(freeCode: string): this;
963
+ /**
964
+ * Draws a path through points. Pass x, y numbers as arguments or one array
965
+ * of [x, y] pairs, then optional options. Invalid input emits no operators.
966
+ * @param parameters - The coordinates and optional options.
967
+ * @returns This context.
968
+ * @throws {TypeError} If fewer than two complete finite coordinate pairs are
969
+ * given.
970
+ * @throws {TypeError} If there is no content context.
971
+ * @throws {TypeError} If `options.type` is not "stroke", "fill", "clip" or null.
972
+ */
218
973
  drawPath(...parameters: any[]): this; // This can't be materialized in TypeScript
219
974
  ////drawPath(...xyPairs: number[], options: GraphicOptions): this;
220
975
  drawPath(xyPairs: Array<[number, number]>, options: GraphicOptions): this;
976
+ /**
977
+ * Draws a circle.
978
+ * @param x - The center x.
979
+ * @param y - The center y.
980
+ * @param r - The radius.
981
+ * @param options - The paint type, color and line width.
982
+ * @returns This context.
983
+ * @throws {TypeError} If fewer than 3 arguments are given, or the coordinates,
984
+ * radius or calculated geometry are not finite.
985
+ * @throws {TypeError} If there is no content context.
986
+ * @throws {TypeError} If `options.type` is not "stroke", "fill", "clip" or null.
987
+ */
221
988
  drawCircle(x: PosX, y: PosY, r: number, options?: GraphicOptions): this;
989
+ /**
990
+ * Draws a square.
991
+ * @param x - The left edge.
992
+ * @param y - The bottom edge.
993
+ * @param l - The edge length.
994
+ * @param options - The paint type, color and line width.
995
+ * @returns This context.
996
+ * @throws {TypeError} If fewer than 3 arguments are given or a value is not
997
+ * finite.
998
+ * @throws {TypeError} If there is no content context.
999
+ * @throws {TypeError} If `options.type` is not "stroke", "fill", "clip" or null.
1000
+ */
222
1001
  drawSquare(x: PosX, y: PosY, l: number, options?: GraphicOptions): this;
1002
+ /**
1003
+ * Draws a rectangle.
1004
+ * @param x - The left edge.
1005
+ * @param y - The bottom edge.
1006
+ * @param w - The width.
1007
+ * @param h - The height.
1008
+ * @param options - The paint type, color and line width.
1009
+ * @returns This context.
1010
+ * @throws {TypeError} If fewer than 4 arguments are given or a value is not
1011
+ * finite.
1012
+ * @throws {TypeError} If there is no content context.
1013
+ * @throws {TypeError} If `options.type` is not "stroke", "fill", "clip" or null.
1014
+ */
223
1015
  drawRectangle(
224
1016
  x: PosX,
225
1017
  y: PosY,
@@ -227,7 +1019,29 @@ declare namespace muhammara {
227
1019
  h: number,
228
1020
  options?: GraphicOptions,
229
1021
  ): this;
1022
+ /**
1023
+ * Writes a line of text with its own text object.
1024
+ * @param text - The text.
1025
+ * @param x - The baseline start x.
1026
+ * @param y - The baseline y.
1027
+ * @param options - The font, size, color, underline and strike-out.
1028
+ * @returns This context.
1029
+ * @throws {TypeError} If fewer than 3 arguments are given, or the coordinates,
1030
+ * font size or underline geometry are not finite.
1031
+ * @throws {TypeError} If there is no content context.
1032
+ */
230
1033
  writeText(text: string, x: PosX, y: PosY, options?: WriteTextOptions): this;
1034
+ /**
1035
+ * Draws an image file: JPEG, PNG, TIFF or a PDF page.
1036
+ * @param x - The left edge.
1037
+ * @param y - The bottom edge.
1038
+ * @param imagePath - The image path.
1039
+ * @param options - The image index, transformation and PDF password.
1040
+ * @returns This context.
1041
+ * @throws {TypeError} If the arguments are not 2 numbers, a string and an
1042
+ * optional object. An image that cannot be read draws nothing.
1043
+ * @throws {TypeError} If there is no content context.
1044
+ */
231
1045
  drawImage(
232
1046
  x: PosX,
233
1047
  y: PosY,
@@ -236,11 +1050,21 @@ declare namespace muhammara {
236
1050
  ): this;
237
1051
  }
238
1052
 
1053
+ /** When `drawImage()` scales an image into its transformation box. */
1054
+ export const ImageFit: {
1055
+ /** Always scale the image to the box. */
1056
+ readonly ALWAYS: "always";
1057
+ /** Scale only an image larger than the box. */
1058
+ readonly OVERFLOW: "overflow";
1059
+ };
1060
+ export type ImageFit = (typeof ImageFit)[keyof typeof ImageFit];
1061
+
239
1062
  export interface TransformationObject {
240
1063
  width: number;
241
1064
  height: number;
242
1065
  proportional?: boolean;
243
- fit?: "always" | "overflow";
1066
+ /** ImageFit.OVERFLOW when omitted. */
1067
+ fit?: ImageFit;
244
1068
  }
245
1069
 
246
1070
  export interface ImageOptions {
@@ -256,23 +1080,56 @@ declare namespace muhammara {
256
1080
 
257
1081
  export interface WriteTextOptions extends FontOptions, ColorOptions {
258
1082
  underline?: boolean;
259
- strikeOut?: boolean;
260
- lineWidth?: number;
261
1083
  }
262
1084
 
263
1085
  export interface XObjectContentContext extends AbstractContentContext {}
264
1086
 
265
1087
  export interface PDFWStreamForFile extends WriteStream {
1088
+ /**
1089
+ * Creates a write stream to a file, replacing an existing one.
1090
+ * @param inPath - The file path.
1091
+ */
266
1092
  new (inPath: string): PDFWStreamForFile;
1093
+ /**
1094
+ * Writes bytes to the file.
1095
+ * @param inBytes - The bytes to write; an array of byte values is also
1096
+ * accepted when called directly.
1097
+ * @returns The number of bytes written.
1098
+ */
1099
+ write(inBytes: Buffer | number[]): number;
1100
+ /**
1101
+ * Flushes and closes the file.
1102
+ * @param inCallback - Called once the file is closed.
1103
+ */
267
1104
  close(inCallback?: () => void): void;
268
1105
  }
269
1106
 
270
1107
  export interface PDFStreamForResponse extends WriteStream {
1108
+ /**
1109
+ * Creates a write stream that writes to an HTTP response.
1110
+ * @param res - The response, or any writable stream.
1111
+ */
271
1112
  new (res: NodeJS.WritableStream): PDFStreamForResponse;
1113
+ /**
1114
+ * Writes bytes to the response.
1115
+ * @param inBytes - The bytes to write; an array of byte values is also
1116
+ * accepted when called directly.
1117
+ * @returns The number of bytes written.
1118
+ */
1119
+ write(inBytes: Buffer | number[]): number;
272
1120
  }
273
1121
 
274
1122
  export interface PDFWStreamForBuffer extends WriteStream {
1123
+ /** Creates a write stream that collects the bytes in memory. */
275
1124
  new (): PDFWStreamForBuffer;
1125
+ /**
1126
+ * Writes bytes to the buffer.
1127
+ * @param inBytes - The bytes to write; an array of byte values is also
1128
+ * accepted when called directly.
1129
+ * @returns The number of bytes written.
1130
+ */
1131
+ write(inBytes: Buffer | number[]): number;
1132
+ /** The bytes written so far; null before the first write. */
276
1133
  buffer: Buffer | null;
277
1134
  }
278
1135
 
@@ -287,7 +1144,8 @@ declare namespace muhammara {
287
1144
  export interface PDFWriterToContinueOptions {
288
1145
  modifiedFilePath?: string;
289
1146
  modifiedStream?: PDFRStreamForFile; // TODO
290
- log?: string;
1147
+ /** Log file path or synchronous byte writer returning the number of bytes written. */
1148
+ log?: string | LogStream;
291
1149
  }
292
1150
 
293
1151
  export interface PDFRecryptOptions extends PDFWriterOptions {
@@ -325,6 +1183,12 @@ declare namespace muhammara {
325
1183
  export const ePDFObjectStream = 10;
326
1184
  export const ePDFObjectSymbol = 11;
327
1185
  export type PDFObjectType = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
1186
+ /**
1187
+ * Returns the name of a PDF object type.
1188
+ * @param type - One of the ePDFObject* constants.
1189
+ * @returns The label, for example Dictionary.
1190
+ * @throws {TypeError} If type is not a single valid type number.
1191
+ */
328
1192
  export function getTypeLabel(type: PDFObjectType): string;
329
1193
 
330
1194
  export const ePDFPageContentItemText = 0;
@@ -343,7 +1207,15 @@ declare namespace muhammara {
343
1207
  export const ePDFPageBoxTrimBox = 3;
344
1208
  export const ePDFPageBoxArtBox = 4;
345
1209
  export type PDFPageBoxType = 0 | 1 | 2 | 3 | 4;
346
- export type PageBox = "media" | "crop" | "bleed" | "trim" | "art";
1210
+ /** Page box names. */
1211
+ export const PageBox: {
1212
+ readonly MEDIA: "media";
1213
+ readonly CROP: "crop";
1214
+ readonly BLEED: "bleed";
1215
+ readonly TRIM: "trim";
1216
+ readonly ART: "art";
1217
+ };
1218
+ export type PageBox = (typeof PageBox)[keyof typeof PageBox];
347
1219
 
348
1220
  export const eRangeTypeAll = 0;
349
1221
  export const eRangeTypeSpecific = 1;
@@ -363,20 +1235,93 @@ declare namespace muhammara {
363
1235
 
364
1236
  export interface FormXObject {
365
1237
  id: FormXObjectId;
1238
+ /**
1239
+ * Returns the content context for drawing on the form.
1240
+ * @returns The content context.
1241
+ */
1242
+ getContentContext(): XObjectContentContext;
1243
+ /**
1244
+ * Returns the form content stream.
1245
+ * @returns The stream.
1246
+ */
1247
+ getContentStream(): PDFStream;
1248
+ /**
1249
+ * Returns the form resources.
1250
+ * @returns The resources dictionary.
1251
+ */
1252
+ getResourcesDictionary(): ResourcesDictionary;
366
1253
  }
367
1254
 
368
1255
  export interface ResourcesDictionary {
369
- addFormXObjectMapping(formXObject: FormXObject): string;
1256
+ /**
1257
+ * Adds a form XObject to the resources and returns its resource name.
1258
+ * @param formXObjectId - The object ID.
1259
+ * @returns The resource name to use in content-stream operators.
1260
+ * @throws {TypeError} If formXObjectId is not a single number.
1261
+ */
1262
+ addFormXObjectMapping(formXObjectId: FormXObjectId): string;
1263
+ /**
1264
+ * Adds an image XObject to the resources and returns its resource name.
1265
+ * @param imageXObject - The image, or its object ID.
1266
+ * @returns The resource name to use in content-stream operators.
1267
+ * @throws {TypeError} If imageXObject is neither an image nor a number.
1268
+ */
370
1269
  addImageXObjectMapping(imageXObject: ImageXObject | number): string;
1270
+ /**
1271
+ * Adds a procedure set name to the ProcSet array.
1272
+ * @param procSetName - The procedure set, for example PDF or Text.
1273
+ * @throws {TypeError} If procSetName is not a single string.
1274
+ */
371
1275
  addProcsetResource(procSetName: string): void;
1276
+ /**
1277
+ * Adds a graphics state dictionary to the resources and returns its resource name.
1278
+ * @param stateObjectId - The object ID.
1279
+ * @returns The resource name to use in content-stream operators.
1280
+ * @throws {TypeError} If stateObjectId is not a single number.
1281
+ */
372
1282
  addExtGStateMapping(stateObjectId: number): string;
1283
+ /**
1284
+ * Adds a font to the resources and returns its resource name.
1285
+ * @param fontObjectId - The object ID.
1286
+ * @returns The resource name to use in content-stream operators.
1287
+ * @throws {TypeError} If fontObjectId is not a single number.
1288
+ */
373
1289
  addFontMapping(fontObjectId: number): string;
1290
+ /**
1291
+ * Adds a color space to the resources and returns its resource name.
1292
+ * @param colorSpaceId - The object ID.
1293
+ * @returns The resource name to use in content-stream operators.
1294
+ * @throws {TypeError} If colorSpaceId is not a single number.
1295
+ */
374
1296
  addColorSpaceMapping(colorSpaceId: number): string;
375
- addPatternMapping(colorSpaceId: number): string;
1297
+ /**
1298
+ * Adds a pattern to the resources and returns its resource name.
1299
+ * @param patternObjectId - The object ID.
1300
+ * @returns The resource name to use in content-stream operators.
1301
+ * @throws {TypeError} If patternObjectId is not a single number.
1302
+ */
376
1303
  addPatternMapping(patternObjectId: number): string;
1304
+ /**
1305
+ * Adds a marked-content property list to the resources and returns its resource name.
1306
+ * @param propertyObjectId - The object ID.
1307
+ * @returns The resource name to use in content-stream operators.
1308
+ * @throws {TypeError} If propertyObjectId is not a single number.
1309
+ */
377
1310
  addPropertyMapping(propertyObjectId: number): string;
1311
+ /**
1312
+ * Adds a XObject to the resources and returns its resource name.
1313
+ * @param xObjectId - The object ID.
1314
+ * @returns The resource name to use in content-stream operators.
1315
+ * @throws {TypeError} If xObjectId is not a single number.
1316
+ */
378
1317
  addXObjectMapping(xObjectId: number): string;
379
- addShadingMapping(xObjectId: number): string;
1318
+ /**
1319
+ * Adds a shading to the resources and returns its resource name.
1320
+ * @param shadingObjectId - The object ID.
1321
+ * @returns The resource name to use in content-stream operators.
1322
+ * @throws {TypeError} If shadingObjectId is not a single number.
1323
+ */
1324
+ addShadingMapping(shadingObjectId: number): string;
380
1325
  }
381
1326
 
382
1327
  export type PDFBox = [PosX, PosY, Width, Height];
@@ -388,6 +1333,10 @@ declare namespace muhammara {
388
1333
  trimBox?: PDFBox;
389
1334
  artBox?: PDFBox;
390
1335
  rotate?: number;
1336
+ /**
1337
+ * Returns the page resources.
1338
+ * @returns The resources dictionary.
1339
+ */
391
1340
  getResourcesDictionary(): ResourcesDictionary;
392
1341
  }
393
1342
 
@@ -400,9 +1349,12 @@ declare namespace muhammara {
400
1349
  height: number;
401
1350
  }
402
1351
 
403
- /** A text-showing operation in a page content stream. */
404
- export interface PDFTextElement {
405
- /** Raw character codes from the content stream. Unicode decoding requires a font ToUnicode CMap. */
1352
+ /**
1353
+ * A text-showing operation in a page content stream, as returned when
1354
+ * `extractPageText()` is called with `{ decodeText: false }`.
1355
+ */
1356
+ export interface PDFRawTextElement {
1357
+ /** Raw character codes from the content stream, one byte per code unit. */
406
1358
  content: string;
407
1359
  /** The page resource name selected by the most recent Tf operation. */
408
1360
  fontResource: string;
@@ -411,6 +1363,29 @@ declare namespace muhammara {
411
1363
  textMatrix: [number, number, number, number, number, number];
412
1364
  }
413
1365
 
1366
+ /** A text-showing operation in a page content stream, with decoded text. */
1367
+ export interface PDFTextElement extends PDFRawTextElement {
1368
+ /**
1369
+ * `content` decoded to Unicode through the active font: its `/ToUnicode`
1370
+ * CMap, then its simple-font `/Encoding` and `/Differences`. Codes the font
1371
+ * does not map become U+FFFD, as do codes of fonts whose built-in encoding
1372
+ * cannot be read, the Symbol and ZapfDingbats standard fonts, embedded Type
1373
+ * 1 fonts without `/Encoding`, and Type 3 fonts, unless `/ToUnicode` or
1374
+ * `/Differences` maps them, and every byte shown without a font or with a
1375
+ * font that cannot be resolved or read.
1376
+ */
1377
+ text: string;
1378
+ }
1379
+
1380
+ /** Options for `PDFReader#extractPageText()`. */
1381
+ export interface PDFTextExtractionOptions {
1382
+ /**
1383
+ * Decode each element's `text` through its font. Defaults to true; false
1384
+ * leaves `text` out and skips reading the page's fonts.
1385
+ */
1386
+ decodeText?: boolean;
1387
+ }
1388
+
414
1389
  /** A content-stream operation that produces a page mark. */
415
1390
  export interface PDFPageContentItem {
416
1391
  type: PDFPageContentItemType;
@@ -439,59 +1414,221 @@ declare namespace muhammara {
439
1414
  }
440
1415
 
441
1416
  export interface UsedFont {
1417
+ /**
1418
+ * Measures a string, or a list of glyph ids.
1419
+ * @param text - The text, or the glyph ids.
1420
+ * @param fontSize - The font size; 1 when omitted.
1421
+ * @returns The bounding box of the text at that size.
1422
+ * @throws {TypeError} If text is not a string or glyph id array, or
1423
+ * fontSize is not a number.
1424
+ */
442
1425
  calculateTextDimensions(
443
- text: string | any,
444
- fontSize: number,
1426
+ text: string | number[],
1427
+ fontSize?: number,
445
1428
  ): TextDimension;
446
- getFontMetrics(fontSize?: number): object;
1429
+ /**
1430
+ * Returns the font metrics scaled to a font size.
1431
+ * @param fontSize - The font size; 1 when omitted.
1432
+ * @returns The ascent, descent and related metrics.
1433
+ * @throws {TypeError} If more than one argument is given or the metrics
1434
+ * cannot be read.
1435
+ */
1436
+ getFontMetrics(fontSize?: number): FontMetrics;
1437
+ }
1438
+
1439
+ export interface FontMetrics {
1440
+ pixelsPerEm: { x: number; y: number; xScale: number; yScale: number };
1441
+ ascender: number;
1442
+ descender: number;
1443
+ height: number;
1444
+ max_advance: number;
447
1445
  }
448
1446
 
449
1447
  export interface ByteWriter {
450
- write(buffer: number[]): number;
1448
+ /**
1449
+ * Writes bytes to the stream.
1450
+ * @param buffer - The bytes to write.
1451
+ * @returns The number of bytes written.
1452
+ * @throws {TypeError} If buffer is not a single Uint8Array or byte array.
1453
+ */
1454
+ write(buffer: Uint8Array | number[]): number;
451
1455
  }
452
1456
 
453
1457
  export interface ByteReader {
454
- read(length: number): Array<number>;
1458
+ /**
1459
+ * Reads the next bytes.
1460
+ * @param length - The maximum number of bytes to read.
1461
+ * @returns The bytes read; shorter than requested at the end.
1462
+ * @throws {TypeError} If length is not a single number.
1463
+ * @throws {Error} If the reader has no stream.
1464
+ */
1465
+ read(length: number): Buffer;
1466
+ /**
1467
+ * Tells whether bytes remain.
1468
+ * @returns True while the end has not been reached.
1469
+ * @throws {Error} If the reader has no stream.
1470
+ */
455
1471
  notEnded(): boolean;
456
1472
  }
457
1473
 
458
1474
  export interface ByteReaderWithPosition {
459
- read(length: number): Array<number>;
1475
+ /**
1476
+ * Reads the next bytes.
1477
+ * @param length - The maximum number of bytes to read.
1478
+ * @returns The bytes read; shorter than requested at the end.
1479
+ * @throws {TypeError} If length is not a single number.
1480
+ */
1481
+ read(length: number): Buffer;
1482
+ /**
1483
+ * Tells whether bytes remain.
1484
+ * @returns True while the end has not been reached.
1485
+ */
460
1486
  notEnded(): boolean;
1487
+ /**
1488
+ * Returns the current position.
1489
+ * @returns The byte offset.
1490
+ */
461
1491
  getCurrentPosition(): number;
1492
+ /**
1493
+ * Advances the position without reading.
1494
+ * @param length - The number of bytes to skip.
1495
+ * @returns This reader.
1496
+ * @throws {TypeError} If length is not a single number.
1497
+ */
462
1498
  skip(length: number): this;
1499
+ /**
1500
+ * Moves to a position.
1501
+ * @param position - The byte offset.
1502
+ * @returns This reader.
1503
+ * @throws {TypeError} If position is not a single number.
1504
+ */
463
1505
  setPosition(position: number): this;
464
- moveStartPosition(position: number): this;
1506
+ /**
1507
+ * Moves to a position counted back from the end.
1508
+ * @param position - The number of bytes before the end.
1509
+ * @returns This reader.
1510
+ * @throws {TypeError} If position is not a single number.
1511
+ */
465
1512
  setPositionFromEnd(position: number): this;
466
1513
  }
467
1514
 
468
1515
  export interface PDFReader {
1516
+ /**
1517
+ * Ends the reader and closes its file; later calls throw. Safe to repeat.
1518
+ * @returns This reader.
1519
+ */
469
1520
  end(): PDFReader;
1521
+ /**
1522
+ * Returns the PDF version from the file header, for example 1.7.
1523
+ * @returns The PDF version.
1524
+ * @throws {TypeError} If the reader has ended.
1525
+ */
470
1526
  getPDFLevel(): number;
1527
+ /**
1528
+ * Returns the number of pages.
1529
+ * @returns The page count.
1530
+ * @throws {TypeError} If the reader has ended.
1531
+ */
471
1532
  getPagesCount(): number;
1533
+ /**
1534
+ * Returns the trailer dictionary.
1535
+ * @returns The trailer; undefined when the file has none.
1536
+ * @throws {TypeError} If the reader has ended.
1537
+ */
472
1538
  getTrailer(): PDFDictionary;
1539
+ /**
1540
+ * Returns a dictionary value, resolving an indirect reference.
1541
+ * @param dictionary - The dictionary to read.
1542
+ * @param name - The key, without a leading slash.
1543
+ * @returns The value; undefined when the key is missing.
1544
+ * @throws {TypeError} If the reader has ended or the arguments are not a
1545
+ * dictionary and a string.
1546
+ */
473
1547
  queryDictionaryObject(dictionary: PDFDictionary, name: string): PDFObject;
1548
+ /**
1549
+ * Returns an array item, resolving an indirect reference.
1550
+ * @param objectList - The array to read.
1551
+ * @param index - The zero-based item index.
1552
+ * @returns The item; undefined when the index is out of range.
1553
+ * @throws {TypeError} If the reader has ended or the arguments are not an
1554
+ * array and a number.
1555
+ */
474
1556
  queryArrayObject(
475
1557
  objectList: PDFArray,
476
1558
  index: number,
477
1559
  ): undefined | PDFObject;
1560
+ /**
1561
+ * Parses an indirect object by its ID.
1562
+ * @param objectId - The object ID.
1563
+ * @returns The parsed object.
1564
+ * @throws {TypeError} If the reader has ended, objectId is not a non-negative
1565
+ * integer, or the object cannot be read.
1566
+ */
478
1567
  parseNewObject(objectId: number): PDFObject;
479
- getPageObjectID(objectId: number): number;
1568
+ /**
1569
+ * Returns the object ID of a page.
1570
+ * @param pageIndex - The zero-based page index.
1571
+ * @returns The page object ID; 0 when the page does not exist.
1572
+ * @throws {TypeError} If the reader has ended or pageIndex is not a
1573
+ * non-negative integer.
1574
+ */
1575
+ getPageObjectID(pageIndex: number): number;
1576
+ /**
1577
+ * Parses a page dictionary.
1578
+ * @param pageIndex - The zero-based page index.
1579
+ * @returns The page dictionary.
1580
+ * @throws {TypeError} If the reader has ended.
1581
+ * @throws {TypeError} If pageIndex is not a non-negative integer or the page
1582
+ * cannot be read.
1583
+ */
480
1584
  parsePageDictionary(pageIndex: number): PDFDictionary;
1585
+ /**
1586
+ * Parses a page with helpers for its boxes and rotation.
1587
+ * @param pageIndex - The zero-based page index.
1588
+ * @returns The page.
1589
+ * @throws {TypeError} If the reader has ended.
1590
+ * @throws {TypeError} If pageIndex is not a non-negative integer or the page
1591
+ * cannot be read.
1592
+ */
481
1593
  parsePage(pageIndex: number): PDFPageInput;
482
1594
  /**
483
- * Returns text-showing operations in PDF content-stream drawing order.
484
- * Does not decode font character maps or calculate glyph bounds.
1595
+ * Returns text-showing operations in PDF content-stream drawing order. Each
1596
+ * element's `text` is decoded through the active font and `content` keeps
1597
+ * the raw character codes. Glyph bounds are not calculated. Font decoding
1598
+ * caches each font per reader but charges every call the font's cost: it
1599
+ * ignores a `/ToUnicode` CMap over 4 MiB or beyond 32 MiB per call, and
1600
+ * counts the PDF objects it reads against `maxParsedObjects` on their own,
1601
+ * so results never depend on earlier calls.
485
1602
  *
486
1603
  * Throws when the page exceeds the extraction budget. `limits` may only
487
1604
  * tighten the defaults: higher values are clamped to the built-in ceilings
488
1605
  * of 1,000,000 content objects, 100,000 text operations, 1024 operands, and
489
1606
  * 16 MiB of text.
1607
+ * @param pageIndex - The zero-based page index.
1608
+ * @param limits - Tighter extraction limits.
1609
+ * @param options - `{ decodeText: false }` skips font decoding and leaves
1610
+ * `text` out.
1611
+ * @returns The text elements in drawing order.
1612
+ * @throws {TypeError} If the arguments are not a page index, an optional
1613
+ * limits object, and optional options, or the page cannot be read.
1614
+ * @throws {RangeError} If a limit is not a positive 32-bit integer.
1615
+ * @throws {Error} If the page exceeds the extraction limits.
490
1616
  */
491
1617
  extractPageText(
492
1618
  pageIndex: number,
493
1619
  limits?: PDFExtractionLimits,
1620
+ options?: PDFTextExtractionOptions & { decodeText?: true },
494
1621
  ): PDFTextElement[];
1622
+ extractPageText(
1623
+ pageIndex: number,
1624
+ limits: PDFExtractionLimits | undefined,
1625
+ options: PDFTextExtractionOptions & { decodeText: false },
1626
+ ): PDFRawTextElement[];
1627
+ extractPageText(
1628
+ pageIndex: number,
1629
+ limits?: PDFExtractionLimits,
1630
+ options?: PDFTextExtractionOptions,
1631
+ ): PDFRawTextElement[];
495
1632
  /**
496
1633
  * Returns every direct content-stream operation that produces a page mark.
497
1634
  * White-on-white content is included; non-painting operations are excluded.
@@ -499,34 +1636,109 @@ declare namespace muhammara {
499
1636
  * Shares `extractPageText`'s budget and clamping. `limits.maxTextBytes` is
500
1637
  * accepted for signature parity but has no effect here, because items carry
501
1638
  * an operator name rather than extracted text.
1639
+ * @param pageIndex - The zero-based page index.
1640
+ * @param limits - Tighter extraction limits.
1641
+ * @returns The content items in drawing order.
1642
+ * @throws {TypeError} If the arguments are not a page index and an optional
1643
+ * limits object, or the page cannot be read.
1644
+ * @throws {RangeError} If a limit is not a positive 32-bit integer.
1645
+ * @throws {Error} If the page exceeds the extraction limits.
502
1646
  */
503
1647
  extractPageContentItems(
504
1648
  pageIndex: number,
505
1649
  limits?: PDFExtractionLimits,
506
1650
  ): PDFPageContentItem[];
1651
+ /**
1652
+ * Returns the number of objects in the cross-reference table.
1653
+ * @returns The object count.
1654
+ * @throws {TypeError} If the reader has ended.
1655
+ */
507
1656
  getObjectsCount(): number;
1657
+ /**
1658
+ * Tells whether the PDF is encrypted.
1659
+ * @returns True when the PDF is encrypted.
1660
+ * @throws {TypeError} If the reader has ended.
1661
+ */
508
1662
  isEncrypted(): boolean;
1663
+ /**
1664
+ * Returns the size of the cross-reference table.
1665
+ * @returns The number of cross-reference entries.
1666
+ * @throws {TypeError} If the reader has ended.
1667
+ */
509
1668
  getXrefSize(): number;
1669
+ /**
1670
+ * Returns the cross-reference entry of an object.
1671
+ * @param objectId - The object ID.
1672
+ * @returns The entry: byte position, revision and entry type.
1673
+ * @throws {TypeError} If the reader has ended, objectId is not a non-negative
1674
+ * integer, or it is out of range.
1675
+ */
510
1676
  getXrefEntry(objectId: number): {
511
1677
  objectPosition: number;
512
1678
  revision: number;
513
1679
  type: number;
514
1680
  };
1681
+ /**
1682
+ * Returns the byte position of the last cross-reference section.
1683
+ * @returns The byte position.
1684
+ * @throws {TypeError} If the reader has ended.
1685
+ */
515
1686
  getXrefPosition(): number;
1687
+ /**
1688
+ * Opens a stream's contents with its filters decoded.
1689
+ * @param inputStream - The stream to read.
1690
+ * @returns A reader over the decoded bytes.
1691
+ * @throws {TypeError} If the reader has ended or inputStream is not a stream.
1692
+ * @throws {Error} If the stream cannot be read.
1693
+ */
516
1694
  startReadingFromStream(inputStream: PDFStreamInput): ByteReader;
1695
+ /**
1696
+ * Opens a stream's contents as stored, decrypted but not decoded.
1697
+ * @param inputStream - The stream to read.
1698
+ * @returns A reader over the stored bytes.
1699
+ * @throws {TypeError} If the reader has ended or inputStream is not a stream.
1700
+ * @throws {Error} If the stream cannot be read.
1701
+ */
517
1702
  startReadingFromStreamForPlainCopying(
518
1703
  inputStream: PDFStreamInput,
519
1704
  ): ByteReader;
1705
+ /**
1706
+ * Parses a content stream as a sequence of objects.
1707
+ * @param stream - The stream to parse.
1708
+ * @returns A parser returning one object per call.
1709
+ * @throws {TypeError} If the reader has ended or stream is not a stream.
1710
+ * @throws {Error} If the stream cannot be read.
1711
+ */
520
1712
  startReadingObjectsFromStream(stream: PDFStreamInput): PDFObjectParser;
1713
+ /**
1714
+ * Parses several content streams as one sequence of objects, as for a
1715
+ * page whose Contents is an array.
1716
+ * @param streams - The array of stream references.
1717
+ * @returns A parser returning one object per call.
1718
+ * @throws {TypeError} If the reader has ended or streams is not an array.
1719
+ */
521
1720
  startReadingObjectsFromStreams(streams: PDFArray): PDFObjectParser;
1721
+ /**
1722
+ * Returns the underlying stream the reader parses.
1723
+ * @returns The positioned byte reader.
1724
+ * @throws {TypeError} If the reader has ended.
1725
+ */
522
1726
  getParserStream(): ByteReaderWithPosition;
523
1727
  }
524
1728
 
525
1729
  export interface PDFObjectParser {
1730
+ /**
1731
+ * Parses the next object.
1732
+ * @returns The object; undefined at the end.
1733
+ */
526
1734
  parseNewObject(): PDFObject | undefined;
527
1735
  }
528
1736
 
529
1737
  export interface PDFStream {
1738
+ /**
1739
+ * Returns the writer for the stream contents.
1740
+ * @returns The byte writer.
1741
+ */
530
1742
  getWriteStream(): ByteWriter;
531
1743
  }
532
1744
 
@@ -539,7 +1751,16 @@ declare namespace muhammara {
539
1751
  }
540
1752
 
541
1753
  export interface PDFLiteralString extends PDFObject {
1754
+ /**
1755
+ * Decodes the string as a PDF text string, PDFDocEncoding or UTF-16BE.
1756
+ * @returns The text.
1757
+ */
542
1758
  toText(): string;
1759
+ /**
1760
+ * Returns the raw bytes of the string.
1761
+ * @returns The byte values.
1762
+ */
1763
+ toBytesArray(): number[];
543
1764
  value: string;
544
1765
  }
545
1766
 
@@ -548,7 +1769,15 @@ declare namespace muhammara {
548
1769
  }
549
1770
 
550
1771
  export interface PDFIndirectObjectReference extends PDFObject {
1772
+ /**
1773
+ * Returns the referenced object ID.
1774
+ * @returns The object ID.
1775
+ */
551
1776
  getObjectID(): number;
1777
+ /**
1778
+ * Returns the referenced generation number.
1779
+ * @returns The generation number.
1780
+ */
552
1781
  getVersion(): number;
553
1782
  }
554
1783
 
@@ -557,13 +1786,39 @@ declare namespace muhammara {
557
1786
  }
558
1787
 
559
1788
  export interface PDFDictionary extends PDFObject {
560
- toJSObject(): object;
1789
+ /**
1790
+ * Returns the entries, without resolving indirect references.
1791
+ * @returns The values by key.
1792
+ */
1793
+ toJSObject(): { [key: string]: PDFObject };
1794
+ /**
1795
+ * Tells whether a key exists.
1796
+ * @param inName - The key, without a leading slash.
1797
+ * @returns True when the key exists.
1798
+ * @throws {TypeError} If inName is not a single string.
1799
+ */
561
1800
  exists(inName: string): boolean;
1801
+ /**
1802
+ * Returns a value, without resolving an indirect reference.
1803
+ * @param inName - The key, without a leading slash.
1804
+ * @returns The value.
1805
+ * @throws {TypeError} If inName is not a single string or the key is
1806
+ * missing.
1807
+ */
562
1808
  queryObject(inName: string): PDFObject;
563
1809
  }
564
1810
 
565
1811
  export interface PDFDate {
1812
+ /**
1813
+ * Returns the date in PDF date format, for example
1814
+ * D:20260926120000+02'00'.
1815
+ * @returns The PDF date string.
1816
+ */
566
1817
  toString(): string;
1818
+ /**
1819
+ * Sets the date to now.
1820
+ * @returns This date.
1821
+ */
567
1822
  setToCurrentTime(): this;
568
1823
  }
569
1824
 
@@ -572,23 +1827,85 @@ declare namespace muhammara {
572
1827
  }
573
1828
 
574
1829
  export interface PDFArray extends PDFObject {
1830
+ /**
1831
+ * Returns the items, without resolving indirect references.
1832
+ * @returns The items as PDF objects.
1833
+ */
575
1834
  toJSArray(): Array<any>;
1835
+ /**
1836
+ * Returns an item, without resolving an indirect reference.
1837
+ * @param index - The zero-based item index.
1838
+ * @returns The item as a PDF object.
1839
+ * @throws {TypeError} If index is not a number or is out of range.
1840
+ */
576
1841
  queryObject(index: number): any;
1842
+ /**
1843
+ * Returns the number of items.
1844
+ * @returns The length.
1845
+ */
577
1846
  getLength(): number;
578
1847
  }
579
1848
 
580
1849
  export interface OutputFile {
1850
+ /**
1851
+ * Opens a file for writing.
1852
+ * @param filePath - The file path.
1853
+ * @param append - True to append to an existing file.
1854
+ * @throws {TypeError} If the arguments are wrong or the file cannot be
1855
+ * opened.
1856
+ * @throws {TypeError} If the file object was not obtained from a writer.
1857
+ */
581
1858
  openFile(filePath: FilePath, append?: boolean): void;
1859
+ /**
1860
+ * Closes the file.
1861
+ * @throws {TypeError} If the file object was not obtained from a writer.
1862
+ */
582
1863
  closeFile(): void;
1864
+ /**
1865
+ * Returns the path of the open file.
1866
+ * @returns The path; undefined when no file is open.
1867
+ * @throws {TypeError} If the file object was not obtained from a writer.
1868
+ */
583
1869
  getFilePath(): string | undefined;
1870
+ /**
1871
+ * Returns the writer of the open file.
1872
+ * @returns The writer; undefined when no file is open.
1873
+ * @throws {TypeError} If the file object was not obtained from a writer.
1874
+ */
584
1875
  getOutputStream(): ByteWriterWithPosition | undefined;
585
1876
  }
586
1877
 
587
1878
  export interface InputFile {
1879
+ /**
1880
+ * Opens a file for reading.
1881
+ * @param filePath - The file path.
1882
+ * @throws {TypeError} If filePath is not a single string or the file cannot
1883
+ * be opened.
1884
+ * @throws {TypeError} If the file object was not obtained from a writer.
1885
+ */
588
1886
  openFile(filePath: FilePath): void;
1887
+ /**
1888
+ * Closes the file.
1889
+ * @throws {TypeError} If the file object was not obtained from a writer.
1890
+ */
589
1891
  closeFile(): void;
1892
+ /**
1893
+ * Returns the path of the open file.
1894
+ * @returns The path; undefined when no file is open.
1895
+ * @throws {TypeError} If the file object was not obtained from a writer.
1896
+ */
590
1897
  getFilePath(): string | undefined;
1898
+ /**
1899
+ * Returns the size of the open file.
1900
+ * @returns The size in bytes; undefined when no file is open.
1901
+ * @throws {TypeError} If the file object was not obtained from a writer.
1902
+ */
591
1903
  getFileSize(): number | undefined;
1904
+ /**
1905
+ * Returns the reader of the open file.
1906
+ * @returns The reader; undefined when no file is open.
1907
+ * @throws {TypeError} If the file object was not obtained from a writer.
1908
+ */
592
1909
  getInputStream(): ByteReaderWithPosition | undefined;
593
1910
  }
594
1911
 
@@ -598,13 +1915,60 @@ declare namespace muhammara {
598
1915
  export const EInfoTrappedUnknown = 2;
599
1916
 
600
1917
  export interface InfoDictionary {
1918
+ /**
1919
+ * Sets a custom info entry.
1920
+ * @param key - The entry key.
1921
+ * @param value - The entry text.
1922
+ * @throws {TypeError} If key and value are not two strings.
1923
+ * @throws {TypeError} If the dictionary was not obtained from a document
1924
+ * context.
1925
+ */
601
1926
  addAdditionalInfoEntry(key: string, value: string): void;
1927
+ /**
1928
+ * Removes a custom info entry.
1929
+ * @param key - The entry key.
1930
+ * @throws {TypeError} If key is not a single string.
1931
+ * @throws {TypeError} If the dictionary was not obtained from a document
1932
+ * context.
1933
+ */
602
1934
  removeAdditionalInfoEntry(key: string): void;
1935
+ /**
1936
+ * Removes every custom info entry.
1937
+ * @throws {TypeError} If the dictionary was not obtained from a document
1938
+ * context.
1939
+ */
603
1940
  clearAdditionalInfoEntries(): void;
1941
+ /**
1942
+ * Returns a custom info entry.
1943
+ * @param key - The entry key.
1944
+ * @returns The entry text; an empty string when it is not set.
1945
+ * @throws {TypeError} If key is not a single string.
1946
+ * @throws {TypeError} If the dictionary was not obtained from a document
1947
+ * context.
1948
+ */
604
1949
  getAdditionalInfoEntry(key: string): string;
605
- getAdditionalInfoEntries(key: string): { [key: string]: string };
606
- setCreationDate(date: string | Date): void;
607
- setModDate(date: string | Date): void;
1950
+ /**
1951
+ * Returns every additional Info entry.
1952
+ * @param key - Ignored; kept so 6.x calls that passed a key still compile.
1953
+ * @returns The entries by key.
1954
+ * @throws {TypeError} If the dictionary was not obtained from a document
1955
+ * context.
1956
+ */
1957
+ getAdditionalInfoEntries(): { [key: string]: string };
1958
+ /**
1959
+ * Sets the creation date.
1960
+ * @param date - The date, a PDF date string, or a PDFDate to copy.
1961
+ * @throws {TypeError} If the dictionary was not obtained from a document
1962
+ * context.
1963
+ */
1964
+ setCreationDate(date: string | Date | PDFDate): void;
1965
+ /**
1966
+ * Sets the modification date.
1967
+ * @param date - The date, a PDF date string, or a PDFDate to copy.
1968
+ * @throws {TypeError} If the dictionary was not obtained from a document
1969
+ * context.
1970
+ */
1971
+ setModDate(date: string | Date | PDFDate): void;
608
1972
 
609
1973
  title: string;
610
1974
  author: string;
@@ -621,56 +1985,228 @@ declare namespace muhammara {
621
1985
 
622
1986
  export interface FormObject {
623
1987
  id: number;
1988
+ /**
1989
+ * Returns the content context for drawing on the form.
1990
+ * @returns The content context.
1991
+ */
624
1992
  getContentContext(): XObjectContentContext;
1993
+ /**
1994
+ * Misspelled alias of getResourcesDictionary().
1995
+ * @deprecated Use getResourcesDictionary().
1996
+ * @returns The resources dictionary.
1997
+ */
625
1998
  getResourcesDictinary(): ResourcesDictionary;
1999
+ /**
2000
+ * Returns the form resources.
2001
+ * @returns The resources dictionary.
2002
+ */
626
2003
  getResourcesDictionary(): ResourcesDictionary;
2004
+ /**
2005
+ * Returns the form content stream.
2006
+ * @returns The stream.
2007
+ */
627
2008
  getContentStream(): PDFStream;
628
2009
  }
629
2010
 
630
2011
  export interface DocumentCopyingContext {
2012
+ /**
2013
+ * Ends the copying context and releases its source; later calls throw.
2014
+ * @returns This context.
2015
+ */
631
2016
  end(): DocumentCopyingContext;
2017
+ /**
2018
+ * Creates a form XObject from a source page.
2019
+ * @param sourcePageIndex - The zero-based source page index.
2020
+ * @param ePDFPageBox - The page box to use, or an explicit [left, bottom,
2021
+ * right, top].
2022
+ * @param transformation - The form matrix.
2023
+ * @returns The form object ID.
2024
+ * @throws {TypeError} If the arguments are wrong or the page does not exist.
2025
+ * @throws {TypeError} If the copying context has ended.
2026
+ */
632
2027
  createFormXObjectFromPDFPage(
633
2028
  sourcePageIndex: number,
634
- ePDFPageBox: PDFPageBoxType | PDFBox,
2029
+ /** Defaults to the media box. */
2030
+ ePDFPageBox?: PDFPageBoxType | PDFBox,
635
2031
  transformation?: TransformationMatrix,
636
2032
  ): number;
2033
+ /**
2034
+ * Draws a source page onto a page of this document.
2035
+ * @param target - The target page.
2036
+ * @param sourcePageIndex - The zero-based source page index.
2037
+ * @throws {TypeError} If the arguments are not a page and a number, or the
2038
+ * source page does not exist.
2039
+ * @throws {TypeError} If the copying context has ended.
2040
+ */
637
2041
  mergePDFPageToPage(target: PDFPage, sourcePageIndex: number): void;
638
- appendPDFPageFromPDF(sourcePageNumber: number): number; // stream start bytes?
2042
+ /**
2043
+ * Appends a source page as a new page.
2044
+ * @param sourcePageNumber - The zero-based source page index.
2045
+ * @returns The object ID of the new page.
2046
+ * @throws {TypeError} If the argument is not a number or the page does not
2047
+ * exist.
2048
+ * @throws {TypeError} If the copying context has ended.
2049
+ */
2050
+ appendPDFPageFromPDF(sourcePageNumber: number): number;
2051
+ /**
2052
+ * Draws a source page into a form XObject of this document.
2053
+ * @param targetForm - The target form.
2054
+ * @param sourcePageIndex - The zero-based source page index.
2055
+ * @throws {TypeError} If the arguments are not a form and a number, or the
2056
+ * source page does not exist.
2057
+ * @throws {TypeError} If the copying context has ended.
2058
+ */
639
2059
  mergePDFPageToFormXObject(
640
- sourcePage: PDFPage,
641
- targetPageNumber: number,
2060
+ targetForm: FormXObject,
2061
+ sourcePageIndex: number,
642
2062
  ): void;
643
- getSourceDocumentParser(
644
- input: FilePath | ReadStream,
645
- options?: PDFReaderOptions,
646
- ): PDFReader;
2063
+ /**
2064
+ * Returns the reader of the source document.
2065
+ * @returns The source document reader.
2066
+ * @throws {TypeError} If the copying context has ended.
2067
+ */
2068
+ getSourceDocumentParser(): PDFReader;
2069
+ /**
2070
+ * Writes a source object at the current output position, copying the
2071
+ * objects it references later.
2072
+ * @param objectToCopy - The source object.
2073
+ * @throws {TypeError} If objectToCopy is not a PDF object or cannot be copied.
2074
+ * @throws {TypeError} If the copying context has ended.
2075
+ */
647
2076
  copyDirectObjectAsIs(objectToCopy: PDFObject): void;
2077
+ /**
2078
+ * Copies a source indirect object and the objects it references.
2079
+ * @param objectId - The source object ID.
2080
+ * @returns The object ID in this document.
2081
+ * @throws {TypeError} If objectId is not a number or the object cannot be
2082
+ * copied.
2083
+ * @throws {TypeError} If the copying context has ended.
2084
+ */
648
2085
  copyObject(objectId: number): number;
2086
+ /**
2087
+ * Writes a source object at the current output position. The objects it
2088
+ * references are not copied yet; pass the returned IDs to
2089
+ * copyNewObjectsForDirectObject() once the current object ends.
2090
+ * @param objectToCopy - The source object.
2091
+ * @returns The source IDs of the referenced objects still to copy.
2092
+ * @throws {TypeError} If objectToCopy is not a PDF object or cannot be copied.
2093
+ * @throws {TypeError} If the copying context has ended.
2094
+ */
649
2095
  copyDirectObjectWithDeepCopy(objectToCopy: PDFObject): Array<number>;
2096
+ /**
2097
+ * Copies the objects returned by copyDirectObjectWithDeepCopy().
2098
+ * @param objectIds - The source object IDs.
2099
+ * @throws {TypeError} If objectIds is not an array or the objects cannot be
2100
+ * copied.
2101
+ * @throws {TypeError} If the copying context has ended.
2102
+ */
650
2103
  copyNewObjectsForDirectObject(objectIds: Array<number>): void;
2104
+ /**
2105
+ * Returns the ID in this document of an already copied source object.
2106
+ * @param objectId - The source object ID.
2107
+ * @returns The object ID in this document.
2108
+ * @throws {TypeError} If objectId is not a number or has not been copied.
2109
+ * @throws {TypeError} If the copying context has ended.
2110
+ */
651
2111
  getCopiedObjectID(objectId: number): number;
2112
+ /**
2113
+ * Returns every copied source object ID with its ID in this document.
2114
+ * @returns The map from source object ID to object ID in this document.
2115
+ * @throws {TypeError} If the copying context has ended.
2116
+ */
652
2117
  getCopiedObjects(): { [key: string]: number };
2118
+ /**
2119
+ * Makes later copies reference existing objects instead of copying the
2120
+ * given source objects.
2121
+ * @param replaceMap - The map from source object ID to object ID in this
2122
+ * document.
2123
+ * @throws {TypeError} If replaceMap is not an object or a key is not an
2124
+ * unsigned integer.
2125
+ * @throws {TypeError} If the copying context has ended.
2126
+ */
653
2127
  replaceSourceObjects(replaceMap: { [key: string]: number }): void;
2128
+ /**
2129
+ * Returns the stream the source PDF is read from.
2130
+ * @returns The positioned byte reader.
2131
+ * @throws {TypeError} If the copying context has ended.
2132
+ */
654
2133
  getSourceDocumentStream(): ByteReaderWithPosition;
655
2134
  }
656
2135
 
657
2136
  export interface DocumentContext {
2137
+ /**
2138
+ * Returns the document information dictionary written with the PDF.
2139
+ * @returns The info dictionary.
2140
+ * @throws {TypeError} If the context was not created by a writer.
2141
+ */
658
2142
  getInfoDictionary(): InfoDictionary;
659
2143
  }
660
2144
 
661
2145
  export interface DictionaryContext {
2146
+ /**
2147
+ * Writes a dictionary key.
2148
+ * @param key - The key, without a leading slash.
2149
+ * @returns This dictionary context.
2150
+ * @throws {TypeError} If key is not a single string.
2151
+ */
662
2152
  writeKey(key: string): DictionaryContext;
2153
+ /**
2154
+ * Writes a name as the value of the last key.
2155
+ * @param nameValue - The name, without a leading slash.
2156
+ * @returns This dictionary context.
2157
+ * @throws {TypeError} If nameValue is not a single string.
2158
+ */
663
2159
  writeNameValue(nameValue: string): this;
2160
+ /**
2161
+ * Writes a rectangle array as the value of the last key.
2162
+ * @param values - The rectangle [left, bottom, right, top].
2163
+ * @returns This dictionary context.
2164
+ * @throws {TypeError} If the arguments are not an array of 4 numbers or 4 numbers.
2165
+ */
664
2166
  writeRectangleValue(values: Array<number>): this;
665
2167
  writeRectangleValue(a: number, b: number, c: number, d: number): this;
2168
+ /**
2169
+ * Writes a literal string as the value of the last key.
2170
+ * @param literal - The text, or its byte values.
2171
+ * @returns This dictionary context.
2172
+ * @throws {TypeError} If literal is not a single string or array.
2173
+ */
666
2174
  writeLiteralStringValue(literal: Array<number> | string): this;
2175
+ /**
2176
+ * Writes a boolean as the value of the last key.
2177
+ * @param boolValue - The value.
2178
+ * @returns This dictionary context.
2179
+ * @throws {TypeError} If boolValue is not a single boolean.
2180
+ */
667
2181
  writeBooleanValue(boolValue: boolean): this;
2182
+ /**
2183
+ * Writes a number as the value of the last key.
2184
+ * @param value - The number.
2185
+ * @returns This dictionary context.
2186
+ * @throws {TypeError} If value is not a single number.
2187
+ */
668
2188
  writeNumberValue(value: number): this;
2189
+ /**
2190
+ * Writes an indirect object reference as the value of the last key.
2191
+ * @param objectId - The object ID.
2192
+ * @returns This dictionary context.
2193
+ * @throws {TypeError} If objectId is not a single number.
2194
+ */
669
2195
  writeObjectReferenceValue(objectId: number): this;
670
2196
  }
671
2197
 
672
2198
  export interface ByteWriterWithPosition {
673
- write(bytes: Array<number>): number;
2199
+ /**
2200
+ * Writes bytes at the current position.
2201
+ * @param bytes - The bytes to write.
2202
+ * @returns The number of bytes written.
2203
+ * @throws {TypeError} If bytes is not a single Uint8Array or byte array.
2204
+ */
2205
+ write(bytes: Uint8Array | number[]): number;
2206
+ /**
2207
+ * Returns the current position.
2208
+ * @returns The byte offset.
2209
+ */
674
2210
  getCurrentPosition(): number;
675
2211
  }
676
2212
 
@@ -691,51 +2227,247 @@ declare namespace muhammara {
691
2227
  export const eXrefEntryUndefined = 3;
692
2228
 
693
2229
  export interface ObjectsContext {
2230
+ /**
2231
+ * Reserves a new object ID, for a forward reference or a later object.
2232
+ * @returns The object ID.
2233
+ */
694
2234
  allocateNewObjectID(): FormXObjectId;
2235
+ /**
2236
+ * Writes the start of a dictionary. End it with endDictionary().
2237
+ * @returns The dictionary context for writing keys and values.
2238
+ */
695
2239
  startDictionary(): DictionaryContext;
2240
+ /**
2241
+ * Writes the start of an array. End it with endArray().
2242
+ * @returns This context.
2243
+ */
696
2244
  startArray(): this;
2245
+ /**
2246
+ * Writes a number, as an integer when it has no fraction.
2247
+ * @param value - The number.
2248
+ * @returns This context.
2249
+ * @throws {TypeError} If value is not a single number.
2250
+ */
697
2251
  writeNumber(value: number): this;
2252
+ /**
2253
+ * Writes the end of an array.
2254
+ * @param endType - The separator after the array; a space when omitted.
2255
+ * @returns This context.
2256
+ * @throws {TypeError} If endType is given and is not a number.
2257
+ */
698
2258
  endArray(endType?: ETokenSeparator): this;
2259
+ /**
2260
+ * Writes a line break.
2261
+ * @returns This context.
2262
+ */
699
2263
  endLine(): this;
2264
+ /**
2265
+ * Writes the end of a dictionary.
2266
+ * @param dictionary - The dictionary started last.
2267
+ * @returns This context.
2268
+ * @throws {TypeError} If dictionary is not a dictionary context or not the one started last.
2269
+ */
700
2270
  endDictionary(dictionary: DictionaryContext): this;
2271
+ /**
2272
+ * Writes the end of the current indirect object.
2273
+ * @returns This context.
2274
+ */
701
2275
  endIndirectObject(): this;
2276
+ /**
2277
+ * Writes a reference to an indirect object.
2278
+ * @param objectId - The object ID.
2279
+ * @param generationNumber - The generation number; 0 when omitted.
2280
+ * @returns This context.
2281
+ * @throws {TypeError} If the arguments are not one or two numbers.
2282
+ */
702
2283
  writeIndirectObjectReference(
703
2284
  objectId: FormXObjectId,
704
2285
  generationNumber?: number,
705
2286
  ): this;
2287
+ /**
2288
+ * Starts an indirect object. Without an ID, allocates one and returns it;
2289
+ * with an ID reserved by allocateNewObjectID(), returns this context.
2290
+ * @param objectId - A reserved object ID.
2291
+ * @returns The new object ID, or this context when objectId is given.
2292
+ * @throws {TypeError} If objectId is given and is not a number.
2293
+ */
706
2294
  startNewIndirectObject(objectId: FormXObjectId): this;
707
2295
  startNewIndirectObject(): FormXObjectId;
2296
+ /**
2297
+ * Starts a new version of an existing object of the PDF being modified.
2298
+ * @param objectId - The object ID to replace.
2299
+ * @returns This context.
2300
+ * @throws {TypeError} If objectId is not a single number.
2301
+ */
708
2302
  startModifiedIndirectObject(objectId: FormXObjectId): this;
2303
+ /**
2304
+ * Marks an object as free in the cross-reference table.
2305
+ * @param objectId - The object ID.
2306
+ * @returns This context.
2307
+ * @throws {TypeError} If objectId is not a single number.
2308
+ */
709
2309
  deleteObject(objectId: FormXObjectId): this;
2310
+ /**
2311
+ * Writes a name object, escaping it as needed.
2312
+ * @param name - The name, without a leading slash.
2313
+ * @returns This context.
2314
+ * @throws {TypeError} If name is not a single string.
2315
+ */
710
2316
  writeName(name: string): this;
2317
+ /**
2318
+ * Writes a literal string, escaping it as needed.
2319
+ * @param literal - The text, or its byte values.
2320
+ * @returns This context.
2321
+ * @throws {TypeError} If literal is not a single string or array.
2322
+ */
711
2323
  writeLiteralString(literal: string | number[]): this;
2324
+ /**
2325
+ * Writes a hexadecimal string.
2326
+ * @param hex - The bytes as a string of hex digits, or their byte values.
2327
+ * @returns This context.
2328
+ * @throws {TypeError} If hex is not a single string or array.
2329
+ */
712
2330
  writeHexString(hex: string | number[]): this;
2331
+ /**
2332
+ * Writes a boolean.
2333
+ * @param bool - The value.
2334
+ * @returns This context.
2335
+ * @throws {TypeError} If bool is not a single boolean.
2336
+ */
713
2337
  writeBoolean(bool: boolean): this;
2338
+ /**
2339
+ * Writes a keyword, such as a content-stream operator, unescaped.
2340
+ * @param keyword - The keyword.
2341
+ * @returns This context.
2342
+ * @throws {TypeError} If keyword is not a single string.
2343
+ */
714
2344
  writeKeyword(keyword: string): this;
2345
+ /**
2346
+ * Writes a comment line.
2347
+ * @param comment - The comment, without the percent sign.
2348
+ * @returns This context.
2349
+ * @throws {TypeError} If comment is not a single string.
2350
+ */
715
2351
  writeComment(comment: string): this;
2352
+ /**
2353
+ * Sets whether later streams are Flate compressed.
2354
+ * @param compress - True to compress.
2355
+ * @returns This context.
2356
+ * @throws {TypeError} If compress is not a single boolean.
2357
+ */
716
2358
  setCompressStreams(compress: boolean): this;
717
- startPDFStream(dictionaryContext: DictionaryContext): PDFStream;
718
- startUnfilteredPDFStream(stream: DictionaryContext): PDFStream;
2359
+ /**
2360
+ * Starts a stream that is compressed when compression is on.
2361
+ * @param dictionaryContext - A started stream dictionary to add Length and
2362
+ * Filter to; a new one when omitted.
2363
+ * @returns The stream; write to its write stream, then call endPDFStream().
2364
+ * @throws {TypeError} If dictionaryContext is given and is not a dictionary context.
2365
+ */
2366
+ startPDFStream(dictionaryContext?: DictionaryContext): PDFStream;
2367
+ /**
2368
+ * Starts a stream written as given, never compressed.
2369
+ * @param dictionaryContext - A started stream dictionary to add Length to;
2370
+ * a new one when omitted.
2371
+ * @returns The stream; write to its write stream, then call endPDFStream().
2372
+ * @throws {TypeError} If dictionaryContext is given and is not a dictionary context.
2373
+ */
2374
+ startUnfilteredPDFStream(dictionaryContext?: DictionaryContext): PDFStream;
2375
+ /**
2376
+ * Ends a stream and writes its length.
2377
+ * @param stream - The stream started last.
2378
+ * @returns This context.
2379
+ * @throws {TypeError} If stream is not a stream.
2380
+ */
719
2381
  endPDFStream(stream: PDFStream): this;
2382
+ /**
2383
+ * Gives direct access to the output, for bytes the other methods cannot
2384
+ * write. End it with endFreeContext().
2385
+ * @returns A writer at the current output position.
2386
+ */
720
2387
  startFreeContext(): ByteWriterWithPosition;
2388
+ /**
2389
+ * Ends direct output access.
2390
+ * @returns This context.
2391
+ */
721
2392
  endFreeContext(): this;
722
2393
  }
723
2394
 
724
2395
  export interface PDFObject {
2396
+ /**
2397
+ * Returns the object type.
2398
+ * @returns The type, one of the ePDFObject* constants.
2399
+ */
725
2400
  getType(): PDFObjectType;
726
- toPDFIndirectObjectReference(): PDFIndirectObjectReference;
727
- toPDFArray(): PDFArray;
728
- toPDFDictionary(): PDFDictionary;
729
- toPDFStream(): PDFStream;
730
- toPDFBoolean(): PDFBoolean;
731
- toPDFLiteralString(): PDFLiteralString;
732
- toPDFHexString(): PDFHexString;
733
- toPDFNull(): PDFNull;
734
- toPDFName(): PDFName;
735
- toPDFInteger(): PDFInteger;
736
- toPDFReal(): PDFReal;
737
- toPDFSymbol(): PDFSymbol;
738
- toNumber(): number;
2401
+ /**
2402
+ * Returns this object typed as an indirect object reference.
2403
+ * @returns This object; undefined when it is not an indirect object reference.
2404
+ */
2405
+ toPDFIndirectObjectReference(): PDFIndirectObjectReference | undefined;
2406
+ /**
2407
+ * Returns this object typed as an array.
2408
+ * @returns This object; undefined when it is not an array.
2409
+ */
2410
+ toPDFArray(): PDFArray | undefined;
2411
+ /**
2412
+ * Returns this object typed as a dictionary.
2413
+ * @returns This object; undefined when it is not a dictionary.
2414
+ */
2415
+ toPDFDictionary(): PDFDictionary | undefined;
2416
+ /**
2417
+ * Returns this object typed as a stream.
2418
+ * @returns This object; undefined when it is not a stream.
2419
+ */
2420
+ toPDFStream(): PDFStream | undefined;
2421
+ /**
2422
+ * Returns this object typed as a boolean.
2423
+ * @returns This object; undefined when it is not a boolean.
2424
+ */
2425
+ toPDFBoolean(): PDFBoolean | undefined;
2426
+ /**
2427
+ * Returns this object typed as a literal string.
2428
+ * @returns This object; undefined when it is not a literal string.
2429
+ */
2430
+ toPDFLiteralString(): PDFLiteralString | undefined;
2431
+ /**
2432
+ * Returns this object typed as a hex string.
2433
+ * @returns This object; undefined when it is not a hex string.
2434
+ */
2435
+ toPDFHexString(): PDFHexString | undefined;
2436
+ /**
2437
+ * Returns this object typed as the null object.
2438
+ * @returns This object; undefined when it is not the null object.
2439
+ */
2440
+ toPDFNull(): PDFNull | undefined;
2441
+ /**
2442
+ * Returns this object typed as a name.
2443
+ * @returns This object; undefined when it is not a name.
2444
+ */
2445
+ toPDFName(): PDFName | undefined;
2446
+ /**
2447
+ * Returns this object typed as an integer.
2448
+ * @returns This object; undefined when it is not an integer.
2449
+ */
2450
+ toPDFInteger(): PDFInteger | undefined;
2451
+ /**
2452
+ * Returns this object typed as a real number.
2453
+ * @returns This object; undefined when it is not a real number.
2454
+ */
2455
+ toPDFReal(): PDFReal | undefined;
2456
+ /**
2457
+ * Returns this object typed as a symbol.
2458
+ * @returns This object; undefined when it is not a symbol.
2459
+ */
2460
+ toPDFSymbol(): PDFSymbol | undefined;
2461
+ /**
2462
+ * Returns the value of an integer or real number.
2463
+ * @returns The number; undefined for other types.
2464
+ */
2465
+ toNumber(): number | undefined;
2466
+ /**
2467
+ * Returns the value as text: the name, string, number, symbol or
2468
+ * boolean; the type label for other types.
2469
+ * @returns The text.
2470
+ */
739
2471
  toString(): string;
740
2472
  }
741
2473
 
@@ -748,18 +2480,48 @@ declare namespace muhammara {
748
2480
  }
749
2481
 
750
2482
  export interface PDFStreamInput extends PDFObject {
2483
+ /**
2484
+ * Returns the stream dictionary.
2485
+ * @returns The dictionary.
2486
+ */
751
2487
  getDictionary(): PDFDictionary;
2488
+ /**
2489
+ * Returns the byte position where the stream contents start.
2490
+ * @returns The byte position in the source file.
2491
+ */
752
2492
  getStreamContentStart(): number;
753
2493
  }
754
2494
 
755
2495
  export interface PDFTextString {
2496
+ /**
2497
+ * Returns the encoded bytes, PDFDocEncoding or UTF-16BE with a byte
2498
+ * order mark.
2499
+ * @returns The byte values.
2500
+ */
756
2501
  toBytesArray(): Array<number>;
2502
+ /**
2503
+ * Returns the text.
2504
+ * @returns The decoded text.
2505
+ */
757
2506
  toString(): string;
758
- fromString(value: string): void;
2507
+ /**
2508
+ * Sets the text; a value that is not a string is ignored.
2509
+ * @param value - The text.
2510
+ * @returns This text string.
2511
+ */
2512
+ fromString(value: string): this;
759
2513
  }
760
2514
 
761
2515
  export interface PageContentContext extends AbstractContentContext {
2516
+ /**
2517
+ * Returns the content stream being written.
2518
+ * @returns The stream.
2519
+ */
762
2520
  getCurrentPageContentStream(): PDFStream;
2521
+ /**
2522
+ * Returns the page this context draws on.
2523
+ * @returns The page.
2524
+ */
763
2525
  getAssociatedPage(): PDFPage;
764
2526
  }
765
2527
 
@@ -787,6 +2549,30 @@ declare namespace muhammara {
787
2549
  upperRightY: number,
788
2550
  ];
789
2551
 
2552
+ /** RGB (3 numbers) or CMYK (4 numbers) color components, 0 to 255. */
2553
+ export type TIFFColor =
2554
+ | [r: number, g: number, b: number]
2555
+ | [c: number, m: number, y: number, k: number];
2556
+
2557
+ /** Options for `createFormXObjectFromTIFF()`. */
2558
+ export interface TIFFUsageOptions {
2559
+ /** The zero-based page of a multi-page TIFF. */
2560
+ pageIndex?: number;
2561
+ /** How black-and-white images are drawn. */
2562
+ bwTreatment?: {
2563
+ /** Draw the image as a stencil mask in oneColor. */
2564
+ asImageMask?: boolean;
2565
+ oneColor?: TIFFColor;
2566
+ };
2567
+ /** How grayscale images are drawn. */
2568
+ grayscaleTreatment?: {
2569
+ /** Map gray values between zeroColor and oneColor. */
2570
+ asColorMap?: boolean;
2571
+ oneColor?: TIFFColor;
2572
+ zeroColor?: TIFFColor;
2573
+ };
2574
+ }
2575
+
790
2576
  export interface MergeOptions {
791
2577
  password?: string;
792
2578
  type?: eRangeType;
@@ -795,13 +2581,19 @@ declare namespace muhammara {
795
2581
 
796
2582
  export interface AppendOptions extends MergeOptions {}
797
2583
 
798
- export type inInterPagesCallback = () => {};
2584
+ export type inInterPagesCallback = (this: typeof globalThis) => void;
799
2585
 
800
2586
  /** Stateful methods require an active writer and throw Error("PDF writer has ended") after cleanup. */
801
2587
  export interface PDFWriter {
802
2588
  /**
803
2589
  * Replace direct references to an object in a page dictionary.
804
2590
  * Available only when modifying an existing PDF.
2591
+ * @param pageIndex - The zero-based page index; ignored for the global scope.
2592
+ * @param sourceObjectId - The object ID to stop referencing.
2593
+ * @param replacementObjectId - The object ID to reference instead.
2594
+ * @param options - `scope: ObjectReplacementScope.GLOBAL` replaces on every page.
2595
+ * @returns This writer.
2596
+ * @throws {Error} If the writer does not modify a PDF or the page does not exist.
805
2597
  */
806
2598
  replaceObject(
807
2599
  pageIndex: number,
@@ -809,32 +2601,126 @@ declare namespace muhammara {
809
2601
  replacementObjectId: number,
810
2602
  options?: ObjectReplacementOptions,
811
2603
  ): this;
812
- /** Finalize once; repeated calls return this writer. A failed finalization also ends the writer. */
2604
+ /**
2605
+ * Finalizes the PDF once; repeated calls return this writer. A failed
2606
+ * finalization also ends the writer.
2607
+ * @returns This writer.
2608
+ * @throws {Error} If a dictionary started with `startDictionary()` is still
2609
+ * open; the writer stays usable, so end the dictionary and call `end()`
2610
+ * again.
2611
+ * @throws {TypeError} If the PDF cannot be finalized.
2612
+ */
813
2613
  end(): PDFWriter;
2614
+ /**
2615
+ * Creates a page, optionally with its media box. Write it with writePage().
2616
+ * @param x - The media box left edge.
2617
+ * @param y - The media box bottom edge.
2618
+ * @param width - The media box width.
2619
+ * @param height - The media box height.
2620
+ * @returns The new page.
2621
+ * @throws {Error} If the writer has ended.
2622
+ */
814
2623
  createPage(x: PosX, y: PosY, width: Width, height: Height): PDFPage;
815
2624
  createPage(): PDFPage;
2625
+ /**
2626
+ * Writes a page and ends its content context.
2627
+ * @param page - The page to write.
2628
+ * @returns This writer.
2629
+ * @throws {TypeError} If page is not a page or the page cannot be written.
2630
+ * @throws {Error} If the writer has ended.
2631
+ */
816
2632
  writePage(page: PDFPage): this;
2633
+ /**
2634
+ * Writes a page and ends its content context.
2635
+ * @param page - The page to write.
2636
+ * @returns The page object ID.
2637
+ * @throws {TypeError} If page is not a page or the page cannot be written.
2638
+ * @throws {Error} If the writer has ended.
2639
+ */
817
2640
  writePageAndReturnID(page: PDFPage): number;
2641
+ /**
2642
+ * Starts, or returns the already started, content context of a page.
2643
+ * @param page - The page to draw on.
2644
+ * @returns The page content context.
2645
+ * @throws {TypeError} If page is not a page.
2646
+ * @throws {Error} If the writer has ended.
2647
+ */
818
2648
  startPageContentContext(page: PDFPage): PageContentContext;
2649
+ /**
2650
+ * Ends the current content stream of a page so other objects can be
2651
+ * written; later drawing starts a new stream on the same page.
2652
+ * @param pageContextContext - The content context to pause.
2653
+ * @returns This writer.
2654
+ * @throws {TypeError} If the argument is not a started page content context.
2655
+ * @throws {Error} If the writer has ended.
2656
+ */
819
2657
  pausePageContentContext(pageContextContext: PageContentContext): this;
2658
+ /**
2659
+ * Starts a form XObject. Draw on its content context, then call
2660
+ * endFormXObject().
2661
+ * @param left - The bounding box left edge.
2662
+ * @param bottom - The bounding box bottom edge.
2663
+ * @param right - The bounding box right edge.
2664
+ * @param top - The bounding box top edge.
2665
+ * @param objectId - A forward-reference object ID reserved earlier.
2666
+ * @returns The form.
2667
+ * @throws {TypeError} If the arguments are not four or five numbers.
2668
+ * @throws {Error} If the writer has ended.
2669
+ */
820
2670
  createFormXObject(
821
- x: PosX,
822
- y: PosY,
823
- width: Width,
824
- height: Height,
2671
+ left: number,
2672
+ bottom: number,
2673
+ right: number,
2674
+ top: number,
825
2675
  objectId?: FormXObjectId,
826
2676
  ): FormXObject;
2677
+ /**
2678
+ * Ends and writes a form XObject.
2679
+ * @param formXObject - The form to end.
2680
+ * @returns This writer.
2681
+ * @throws {TypeError} If formXObject is not a form or cannot be written.
2682
+ * @throws {Error} If the writer has ended.
2683
+ */
827
2684
  endFormXObject(formXObject: FormXObject): this;
2685
+ /**
2686
+ * Creates a form XObject showing a JPEG image.
2687
+ * @param file - The image path or a read stream.
2688
+ * @param objectId - A forward-reference object ID reserved earlier.
2689
+ * @returns The form.
2690
+ * @throws {TypeError} If the arguments are wrong or the image cannot be read.
2691
+ * @throws {Error} If the writer has ended.
2692
+ */
828
2693
  createFormXObjectFromJPG(
829
- file: FilePath | PDFRStreamForFile,
2694
+ file: FilePath | ReadStream,
830
2695
  objectId?: FormXObjectId,
831
2696
  ): FormXObject;
2697
+ /**
2698
+ * Loads a font file for text drawing.
2699
+ * @param inFontFilePath - The font file path.
2700
+ * @param inOptionalMetricsFile - The metrics file of a Type 1 font.
2701
+ * @param index - The font index in a collection such as TTC or DFont.
2702
+ * @returns The font.
2703
+ * @throws {TypeError} If the arguments are wrong or the font cannot be loaded.
2704
+ * @throws {Error} If the writer has ended.
2705
+ */
832
2706
  getFontForFile(inFontFilePath: FilePath, index?: number): UsedFont;
833
2707
  getFontForFile(
834
2708
  inFontFilePath: FilePath,
835
2709
  inOptionalMetricsFile?: string,
836
2710
  index?: number,
837
2711
  ): UsedFont;
2712
+ /**
2713
+ * Adds a link annotation to the page written next.
2714
+ * @param url - The ASCII link target.
2715
+ * @param left - The clickable area left edge.
2716
+ * @param bottom - The clickable area bottom edge.
2717
+ * @param right - The clickable area right edge.
2718
+ * @param top - The clickable area top edge.
2719
+ * @returns This writer.
2720
+ * @throws {TypeError} If the arguments are not a string and four numbers, or
2721
+ * the URL cannot be encoded as ASCII.
2722
+ * @throws {Error} If the writer has ended.
2723
+ */
838
2724
  attachURLLinktoCurrentPage(
839
2725
  url: string,
840
2726
  left: PosX,
@@ -842,41 +2728,136 @@ declare namespace muhammara {
842
2728
  right: PosX,
843
2729
  top: PosY,
844
2730
  ): this;
845
- /** Save continuation state and retire this writer, including when saving fails. */
2731
+ /**
2732
+ * Saves the continuation state for createWriterToContinue() and retires
2733
+ * this writer, including when saving fails.
2734
+ * @param outputFilePath - The state file path.
2735
+ * @returns This writer.
2736
+ * @throws {TypeError} If the path is missing or the state cannot be saved.
2737
+ * @throws {Error} If the writer has ended.
2738
+ */
846
2739
  shutdown(outputFilePath: FilePath): this;
2740
+ /**
2741
+ * Creates a form XObject showing a TIFF image.
2742
+ * @param filePath - The image path or a read stream.
2743
+ * @param objectId - A forward-reference object ID, or TIFF options.
2744
+ * @returns The form.
2745
+ * @throws {TypeError} If the arguments are wrong, a color is not 3 or 4
2746
+ * numbers, or the image cannot be read.
2747
+ * @throws {Error} If the writer has ended.
2748
+ */
847
2749
  createFormXObjectFromTIFF(
848
- filePath: FilePath | PDFRStreamForFile,
849
- objectId?: FormXObjectId,
2750
+ filePath: FilePath | ReadStream,
2751
+ objectId?: FormXObjectId | TIFFUsageOptions,
850
2752
  ): FormXObject;
2753
+ /**
2754
+ * Creates an image XObject from a JPEG image.
2755
+ * @param filePath - The image path or a read stream.
2756
+ * @param objectId - A forward-reference object ID reserved earlier.
2757
+ * @returns The image.
2758
+ * @throws {TypeError} If the arguments are wrong or the image cannot be read.
2759
+ * @throws {Error} If the writer has ended.
2760
+ */
851
2761
  createImageXObjectFromJPG(
852
- filePath: FilePath | PDFRStreamForFile,
2762
+ filePath: FilePath | ReadStream,
853
2763
  objectId?: FormXObjectId,
854
2764
  ): ImageXObject;
2765
+ /**
2766
+ * Creates a form XObject showing a PNG image.
2767
+ * @param filePath - The image path or a read stream.
2768
+ * @param objectId - A forward-reference object ID reserved earlier.
2769
+ * @returns The form.
2770
+ * @throws {TypeError} If the arguments are wrong or the image cannot be read.
2771
+ * @throws {Error} If the writer has ended.
2772
+ */
855
2773
  createFormXObjectFromPNG(
856
- filePath: FilePath | PDFRStreamForFile,
2774
+ filePath: FilePath | ReadStream,
857
2775
  objectId?: FormXObjectId,
858
2776
  ): FormXObject;
2777
+ /**
2778
+ * Reads the header information of a JPEG file.
2779
+ * @param filePath - The image path.
2780
+ * @returns The image information.
2781
+ * @throws {TypeError} If the argument is wrong or the file cannot be read.
2782
+ * @throws {Error} If the writer has ended.
2783
+ */
859
2784
  retrieveJPGImageInformation(filePath: FilePath): JPEGInformation;
2785
+ /**
2786
+ * Returns the context for writing PDF objects directly.
2787
+ * @returns The objects context.
2788
+ * @throws {Error} If the writer has ended.
2789
+ */
860
2790
  getObjectsContext(): ObjectsContext;
2791
+ /**
2792
+ * Returns the document context, for extensions and the info dictionary.
2793
+ * @returns The document context.
2794
+ * @throws {Error} If the writer has ended.
2795
+ */
861
2796
  getDocumentContext(): DocumentContext;
2797
+ /**
2798
+ * Appends pages of another PDF as new pages.
2799
+ * @param source - The PDF path or a read stream.
2800
+ * @param options - The page range and the source password.
2801
+ * @returns The object IDs of the appended pages.
2802
+ * @throws {TypeError} If the arguments are wrong or the pages cannot be
2803
+ * appended; the writer is aborted then.
2804
+ * @throws {RangeError} If the page range is invalid.
2805
+ * @throws {Error} If the writer has ended.
2806
+ */
862
2807
  appendPDFPagesFromPDF(
863
2808
  source: FilePath | ReadStream,
864
2809
  options?: AppendOptions,
865
2810
  ): number[];
2811
+ /**
2812
+ * Draws pages of another PDF onto a page. The optional callback runs
2813
+ * between pages, with no arguments and globalThis as its receiver.
2814
+ * @param page - The target page.
2815
+ * @param file - The PDF path or a read stream.
2816
+ * @param options - The page range and the source password.
2817
+ * @param callback - Called between merged pages.
2818
+ * @returns This writer.
2819
+ * @throws {TypeError} If page is not a page, file is neither a path nor a
2820
+ * stream, or the pages cannot be merged.
2821
+ * @throws {RangeError} If the page range is invalid.
2822
+ * @throws {Error} If the writer has ended.
2823
+ */
866
2824
  mergePDFPagesToPage(
867
2825
  page: PDFPage,
868
- file: FilePath | PDFRStreamForFile,
2826
+ file: FilePath | ReadStream,
869
2827
  options?: MergeOptions,
870
2828
  callback?: inInterPagesCallback,
871
2829
  ): this;
872
2830
  mergePDFPagesToPage(
873
2831
  page: PDFPage,
874
- file: FilePath | PDFRStreamForFile,
2832
+ file: FilePath | ReadStream,
875
2833
  callback?: inInterPagesCallback,
876
2834
  ): this;
2835
+ /**
2836
+ * Opens a PDF for copying objects and pages into this document.
2837
+ * @param source - The PDF path, a read stream, or an open reader.
2838
+ * @param options - The source password.
2839
+ * @returns The copying context; call end() on it when done.
2840
+ * @throws {TypeError} If the arguments are wrong, the reader has ended, or the
2841
+ * PDF cannot be read.
2842
+ * @throws {Error} If the writer has ended.
2843
+ */
877
2844
  createPDFCopyingContext(
878
- source: FilePath | ReadStream,
2845
+ source: FilePath | ReadStream | PDFReader,
2846
+ options?: PDFReaderOptions,
879
2847
  ): DocumentCopyingContext;
2848
+ /**
2849
+ * Creates one form XObject per page of another PDF.
2850
+ * @param file - The PDF path.
2851
+ * @param box - The page box to use, or an explicit [left, bottom, right, top].
2852
+ * @param options - The page range and the source password.
2853
+ * @param transformation - The form matrix.
2854
+ * @param objectIds - Further source object IDs to copy.
2855
+ * @returns The form object IDs, one per page.
2856
+ * @throws {TypeError} If the arguments are wrong or the forms cannot be
2857
+ * created.
2858
+ * @throws {RangeError} If the page range is invalid.
2859
+ * @throws {Error} If the writer has ended.
2860
+ */
880
2861
  createFormXObjectsFromPDF(
881
2862
  file: FilePath,
882
2863
  box?: PDFBox | PDFPageBoxType,
@@ -884,33 +2865,141 @@ declare namespace muhammara {
884
2865
  transformation?: TransformationMatrix,
885
2866
  objectIds?: FormXObjectId[],
886
2867
  ): FormXObjectId[];
2868
+ /**
2869
+ * Opens the PDF being modified for copying its objects.
2870
+ * @returns The copying context; call end() on it when done.
2871
+ * @throws {TypeError} If the writer does not modify a PDF.
2872
+ * @throws {Error} If the writer has ended.
2873
+ */
887
2874
  createPDFCopyingContextForModifiedFile(): DocumentCopyingContext;
888
- createPDFTextString(): PDFTextString;
2875
+ /**
2876
+ * Creates a PDF text string, encoded as PDFDocEncoding or UTF-16 as needed.
2877
+ * Works after the writer has ended.
2878
+ * @param value - The text, or its UTF-16 code units.
2879
+ * @returns The text string.
2880
+ */
2881
+ createPDFTextString(value?: string | number[]): PDFTextString;
2882
+ /**
2883
+ * Creates a PDF date. Works after the writer has ended.
2884
+ * @param value - The date, or a PDF date string; now when omitted.
2885
+ * @returns The date.
2886
+ */
889
2887
  createPDFDate(value?: string | Date): PDFDate;
2888
+ /**
2889
+ * Returns the size of an image in points.
2890
+ * @param imagePath - The image path or a read stream.
2891
+ * @param imageIndex - The image or page index of a multi-image file.
2892
+ * @param options - The password of a PDF source.
2893
+ * @returns The width and height.
2894
+ * @throws {TypeError} If the arguments are wrong.
2895
+ * @throws {Error} If the writer has ended.
2896
+ */
890
2897
  getImageDimensions(
891
- inFontFilePath: FilePath | ReadStream,
2898
+ imagePath: FilePath | ReadStream,
2899
+ imageIndex?: number,
2900
+ options?: PDFReaderOptions,
892
2901
  ): RectangleDimension;
2902
+ /**
2903
+ * Returns the number of pages or images in an image file.
2904
+ * @param imagePath - The image path.
2905
+ * @param options - The password of a PDF source.
2906
+ * @returns The page count.
2907
+ * @throws {TypeError} If the arguments are wrong.
2908
+ * @throws {Error} If the writer has ended.
2909
+ */
893
2910
  getImagePagesCount(
894
2911
  imagePath: FilePath,
895
2912
  options?: { password?: string },
896
2913
  ): number;
2914
+ /**
2915
+ * Detects the type of an image file.
2916
+ * @param imagePath - The image path.
2917
+ * @returns The type; undefined when it is not a supported image.
2918
+ * @throws {TypeError} If imagePath is not a single argument.
2919
+ * @throws {Error} If the writer has ended.
2920
+ */
897
2921
  getImageType(imagePath: FilePath): PDFImageType | undefined;
2922
+ /**
2923
+ * Returns a reader of the PDF being modified.
2924
+ * @returns The reader.
2925
+ * @throws {TypeError} If the writer does not modify a PDF.
2926
+ * @throws {Error} If the writer has ended.
2927
+ */
898
2928
  getModifiedFileParser(): PDFReader;
2929
+ /**
2930
+ * Returns the input file of the PDF being modified.
2931
+ * @returns The input file.
2932
+ * @throws {TypeError} If the writer does not modify a PDF.
2933
+ * @throws {Error} If the writer has ended.
2934
+ */
899
2935
  getModifiedInputFile(): InputFile;
2936
+ /**
2937
+ * Returns the output file.
2938
+ * @returns The output file.
2939
+ * @throws {TypeError} If the output is not a file.
2940
+ * @throws {Error} If the writer has ended.
2941
+ */
900
2942
  getOutputFile(): OutputFile;
2943
+ /**
2944
+ * Adds an annotation to the Annots array of the page written next.
2945
+ * @param annotationId - The annotation object ID.
2946
+ * @returns This writer.
2947
+ * @throws {TypeError} If annotationId is not a number.
2948
+ * @throws {Error} If the writer has ended.
2949
+ */
901
2950
  registerAnnotationReferenceForNextPageWrite(annotationId: number): this;
2951
+ /**
2952
+ * Makes a modified PDF write a new catalog when it ends, so catalog
2953
+ * changes from extensions are kept.
2954
+ * @throws {Error} If the writer has ended.
2955
+ */
902
2956
  requireCatalogUpdate(): void;
903
2957
 
904
2958
  /* Js Extensions (in muhammara.js) */
2959
+ /**
2960
+ * Returns the writer's event emitter, created on first use.
2961
+ * @returns The emitter for writer events.
2962
+ */
905
2963
  getEvents(): EventEmitter;
2964
+ /**
2965
+ * Emits an event on the writer's emitter after setting `eventParams.writer`
2966
+ * to this writer.
2967
+ * @param eventName - The event name.
2968
+ * @param eventParams - The event parameters; gains a `writer` key.
2969
+ * @throws {TypeError} If eventParams is not an object.
2970
+ */
906
2971
  triggerDocumentExtensionEvent(
907
2972
  eventName: string | symbol,
908
2973
  eventParams: any,
909
2974
  ): void;
910
2975
  }
911
2976
 
2977
+ /** Scopes for the `replaceObject()` scope option. */
2978
+ export const ObjectReplacementScope: {
2979
+ /** Replace the reference on every page. */
2980
+ readonly GLOBAL: "global";
2981
+ };
2982
+ export type ObjectReplacementScope =
2983
+ (typeof ObjectReplacementScope)[keyof typeof ObjectReplacementScope];
2984
+
912
2985
  export interface ObjectReplacementOptions {
913
- scope?: "global";
2986
+ scope?: ObjectReplacementScope;
2987
+ }
2988
+
2989
+ export interface RemoveTextOptions {
2990
+ /** Also remove text from the Form XObjects the page paints, including nested forms. Defaults to `false`. */
2991
+ forms?: boolean;
2992
+ }
2993
+
2994
+ export interface DeletePageOptions {
2995
+ /**
2996
+ * Remove references to the deleted pages from retained structures -
2997
+ * outlines, link annotations, named destinations, form widgets,
2998
+ * tagged-PDF structure elements and the open action - instead of
2999
+ * refusing the deletion. Defaults to `false`. Once enabled, it applies to
3000
+ * every queued deletion.
3001
+ */
3002
+ pruneReferences?: boolean;
914
3003
  }
915
3004
 
916
3005
  export interface RecipePageInfo {
@@ -962,32 +3051,22 @@ declare namespace muhammara {
962
3051
  * Passes a colorspace argument through when it is valid, and otherwise
963
3052
  * resolves to the accepted set so the compiler names the valid values
964
3053
  * instead of reporting the bare `never` the optional parameter would
965
- * collapse to. A plain `string` stays accepted for runtime-computed values.
3054
+ * collapse to.
966
3055
  */
967
3056
  type ValidColorspace<Value extends string | undefined> = [Value] extends [
968
3057
  undefined,
969
3058
  ]
970
3059
  ? Value
971
- : string extends Exclude<Value, undefined>
3060
+ : Exclude<Value, undefined> extends Colorspace | ""
972
3061
  ? Value
973
- : Exclude<Value, undefined> extends Colorspace | ""
974
- ? Value
975
- : Colorspace | "";
3062
+ : Colorspace | "";
976
3063
  type ExtensionCallback<
977
3064
  Arguments extends unknown[] = never[],
978
3065
  Result = unknown,
979
3066
  > = (this: Recipe, ...args: Arguments) => Result;
980
3067
 
981
- type CommentOptionsFlag =
982
- | "invisible"
983
- | "hidden"
984
- | "print"
985
- | "nozoom"
986
- | "norotate"
987
- | "noview"
988
- | "readonly"
989
- | "locked"
990
- | "togglenoview";
3068
+ /** @deprecated Use `AnnotFlag`; comments accept the same flags. */
3069
+ type CommentOptionsFlag = AnnotOptionsFlag;
991
3070
 
992
3071
  type AnnotSubtype =
993
3072
  | "Text"
@@ -1042,16 +3121,121 @@ declare namespace muhammara {
1042
3121
 
1043
3122
  type RecipeCoordinate = number | "center";
1044
3123
 
3124
+ /** Named page sizes, with string compatibility for other names. */
3125
+ type PageSize =
3126
+ | "executive"
3127
+ | "folio"
3128
+ | "legal"
3129
+ | "letter"
3130
+ | "ledger"
3131
+ | "tabloid"
3132
+ | "a0"
3133
+ | "a1"
3134
+ | "a2"
3135
+ | "a3"
3136
+ | "a4"
3137
+ | "a5"
3138
+ | "a6"
3139
+ | "a7"
3140
+ | "a8"
3141
+ | "a9"
3142
+ | "a10"
3143
+ | "b0"
3144
+ | "b1"
3145
+ | "b2"
3146
+ | "b3"
3147
+ | "b4"
3148
+ | "b5"
3149
+ | "b6"
3150
+ | "b7"
3151
+ | "b8"
3152
+ | "b9"
3153
+ | "b10"
3154
+ | "c0"
3155
+ | "c1"
3156
+ | "c2"
3157
+ | "c3"
3158
+ | "c4"
3159
+ | "c5"
3160
+ | "c6"
3161
+ | "c7"
3162
+ | "c8"
3163
+ | "c9"
3164
+ | "c10"
3165
+ | "ra0"
3166
+ | "ra1"
3167
+ | "ra2"
3168
+ | "ra3"
3169
+ | "ra4"
3170
+ | "sra0"
3171
+ | "sra1"
3172
+ | "sra2"
3173
+ | "sra3"
3174
+ | "sra4"
3175
+ | (string & {});
3176
+
3177
+ /** A `Recipe.TextWrap` value. */
3178
+ type TextWrap = "auto" | "clip" | "trim" | "ellipsis";
3179
+ /** A `Recipe.TableRowNth` value. */
3180
+ type TableRowNth = "even" | "odd";
3181
+ /** A `Recipe.LineCap` value. */
3182
+ type LineCap = "butt" | "round" | "square";
3183
+ /** A `Recipe.LineJoin` value. */
3184
+ type LineJoin = "miter" | "round" | "bevel";
3185
+ /** A `Recipe.ArrowAt` value. */
3186
+ type ArrowAt = "head" | "tail";
3187
+ /** A `Recipe.ArrowType` value. */
3188
+ type ArrowType = "triangle" | "dart" | "kite";
3189
+ /** A `Recipe.PageLayout` value. */
3190
+ type PageLayout = "portrait" | "landscape";
3191
+ /** A `Recipe.FontStyle` value. */
3192
+ type FontStyle = "regular" | "bold" | "italic" | "bold-italic";
3193
+ /** A `Recipe.Permission` value. */
3194
+ type Permission = PermissionName;
3195
+ /** A `Recipe.Coordinate` value. */
3196
+ type Coordinate = "center";
3197
+ /** A `Recipe.AnnotFlag` value. */
3198
+ type AnnotFlag = AnnotOptionsFlag;
3199
+ /** A `Recipe.AnnotIcon` value. */
3200
+ type AnnotIcon = AnnotOptionsIcon;
3201
+ /** A `Recipe.ChromaCommand` value. */
3202
+ type ChromaCommand = "!load";
3203
+ /** A `Recipe.Source` value. */
3204
+ type Source = "new";
3205
+ /** The low-level `DeviceColorSpace` values; same as `DeviceColorspace`. */
3206
+ type DeviceColorSpace = DeviceColorspace;
3207
+ type HorizontalAlign = "left" | "center" | "right";
3208
+ type VerticalAlign = "top" | "center" | "bottom";
3209
+ type TextAlign = "left" | "center" | "right" | "justify";
3210
+ /** Known text-box alignments, with string compatibility for computed values. */
3211
+ type TextBoxAlign =
3212
+ TextAlign | `${TextAlign} ${VerticalAlign}` | (string & {});
3213
+ /** Known alignments, with string compatibility for computed values. */
3214
+ type ImageAlign =
3215
+ HorizontalAlign | `${HorizontalAlign} ${VerticalAlign}` | (string & {});
3216
+
1045
3217
  type RecipeFontStyle =
1046
3218
  "regular" | "bold" | "italic" | "bold-italic" | "r" | "b" | "i" | "bi";
1047
3219
 
1048
3220
  interface RecipeOptions {
3221
+ /** PDF version of a new PDF: 1.0 through 1.7 or 2.0; other values use 1.7. */
1049
3222
  version?: number;
1050
3223
  author?: string;
1051
3224
  title?: string;
1052
3225
  subject?: string;
1053
3226
  keywords?: string[];
3227
+ /** Default colorspace; see `Recipe.Colorspace`. */
1054
3228
  colorspace?: Colorspace;
3229
+ /** Owner password; also opens a protected source PDF. */
3230
+ password?: string;
3231
+ /** The 'view' password; also enables encryption. */
3232
+ userPassword?: string;
3233
+ /** The 'edit' password. */
3234
+ ownerPassword?: string;
3235
+ /** Encryption permission flags, see `Recipe#permission()`. */
3236
+ userProtectionFlag?: number;
3237
+ /** Directory location(s) of additional fonts. */
3238
+ fontSrcPath?: string | string[];
1055
3239
  }
1056
3240
 
1057
3241
  interface RecipeMargins {
@@ -1061,39 +3245,75 @@ declare namespace muhammara {
1061
3245
  bottom?: number;
1062
3246
  }
1063
3247
 
1064
- interface CommentOptions {
1065
- title?: string;
1066
- date?: string;
1067
- open?: boolean;
1068
- richText?: boolean;
1069
- flag?: CommentOptionsFlag;
1070
- /** Replies linked to this comment annotation. */
1071
- replies?: readonly AnnotReply[];
1072
- }
3248
+ /**
3249
+ * `comment()` options: the `annot()` options except `text`, which is
3250
+ * `comment()`'s first argument. `width` and `height` size the rectangle
3251
+ * down from (x, y), as for `annot()`.
3252
+ */
3253
+ interface CommentOptions extends Omit<AnnotOptions, "text"> {}
1073
3254
 
1074
3255
  interface AnnotOptions {
3256
+ /** The annotation content. */
3257
+ text?: string;
3258
+ /** The annotation content when `text` is empty, as in `@muhammara/wasm`. */
3259
+ contents?: string;
1075
3260
  title?: string;
1076
3261
  open?: boolean;
1077
3262
  richText?: boolean;
1078
- flag?: AnnotOptionsFlag;
3263
+ flag?: AnnotOptionsFlag | number;
3264
+ /** Flag bits when `flag` is omitted. */
3265
+ flags?: number;
1079
3266
  icon?: AnnotOptionsIcon;
3267
+ /** The `/Name` icon when `icon` is omitted. */
3268
+ name?: string;
3269
+ /** A finite width of at least zero; other values throw a `TypeError`. */
1080
3270
  width?: number;
3271
+ /** A finite height of at least zero; other values throw a `TypeError`. */
1081
3272
  height?: number;
1082
- /** Annotation opacity from 0 (transparent) to 1 (opaque). Defaults to 1. */
3273
+ /** Annotation opacity from 0 (transparent) to 1 (opaque). Defaults to 1; other values throw a `TypeError`. */
1083
3274
  opacity?: number;
1084
- date?: string;
3275
+ /** The `/M` modification date; omitted writes no `/M`, and text that is not a date is written as given. */
3276
+ date?: string | Date;
1085
3277
  subject?: string;
1086
3278
  replies?: readonly AnnotReply[];
3279
+ /**
3280
+ * The border width, or its `width` and `dash` pattern. A negative width
3281
+ * writes no `/Border`. Text markup annotations default to 0.
3282
+ */
3283
+ border?: number | { width?: number; dash?: readonly number[] };
3284
+ /** The border width; overrides `border.width`. */
3285
+ borderWidth?: number;
3286
+ /** The border dash pattern; overrides `border.dash`. */
3287
+ borderDash?: readonly number[];
3288
+ /** Quad points, eight numbers per quadrilateral, written as given. */
3289
+ quadPoints?: readonly number[];
3290
+ /** `#rrggbb`, `%r,g,b`, a color registered with `chroma()`, a CSS color name, or one (gray), three (RGB), or four (CMYK) numbers from 0 to 255. Other values throw a `TypeError`. */
3291
+ color?: Color;
3292
+ /** Keep the annotation unrotated on a rotated source page. */
3293
+ followOriginalPageRotation?: boolean;
1087
3294
  }
1088
3295
 
1089
3296
  interface AnnotReply {
3297
+ /** Ignored: a reply uses the subtype of the annotation it answers. */
1090
3298
  subtype?: AnnotSubtype;
1091
- text: string;
3299
+ text?: string;
3300
+ /** The reply content when `text` is empty. */
3301
+ contents?: string;
1092
3302
  title?: string;
1093
3303
  richText?: boolean;
1094
- flag?: AnnotOptionsFlag;
3304
+ flag?: AnnotOptionsFlag | number;
3305
+ /** Flag bits when `flag` is omitted. */
3306
+ flags?: number;
3307
+ /** Whether the reply opens; defaults to the parent's `open`. */
3308
+ open?: boolean;
3309
+ /** The reply icon; defaults to the parent's icon. */
3310
+ icon?: AnnotOptionsIcon;
3311
+ /** The `/Name` icon when `icon` is omitted. */
3312
+ name?: string;
3313
+ /** Opacity from 0 to 1; defaults to 1. Other values throw a `TypeError`. */
1095
3314
  opacity?: number;
1096
- date?: string;
3315
+ /** The reply's `/M` date; defaults to the parent's `date`. */
3316
+ date?: string | Date;
1097
3317
  subject?: string;
1098
3318
  }
1099
3319
 
@@ -1120,7 +3340,8 @@ declare namespace muhammara {
1120
3340
  scale?: number;
1121
3341
  keepAspectRatio?: boolean;
1122
3342
  opacity?: number;
1123
- align?: string;
3343
+ /** `Recipe.HorizontalAlign`, optionally followed by a space and `Recipe.VerticalAlign`. */
3344
+ align?: ImageAlign;
1124
3345
  rotation?: number;
1125
3346
  rotationOrigin?: [number, number];
1126
3347
  skewX?: number;
@@ -1148,7 +3369,7 @@ declare namespace muhammara {
1148
3369
  interface MetadataPage {
1149
3370
  pageNumber: number;
1150
3371
  mediaBox: number[];
1151
- layout: "portrait" | "landscape";
3372
+ layout: PageLayout;
1152
3373
  rotate: number;
1153
3374
  width: number;
1154
3375
  height: number;
@@ -1205,8 +3426,9 @@ declare namespace muhammara {
1205
3426
  minHeight?: number;
1206
3427
  padding?: number | readonly number[];
1207
3428
  lineHeight?: number;
1208
- wrap?: boolean | "auto" | "clip" | "trim" | "ellipsis";
1209
- textAlign?: string;
3429
+ wrap?: boolean | TextWrap;
3430
+ /** `Recipe.TextAlign`, optionally followed by a space and `Recipe.VerticalAlign`. */
3431
+ textAlign?: TextBoxAlign;
1210
3432
  clipIfExceedsBox?: boolean;
1211
3433
  onClip?: (recipe: Recipe, result: TextBoxClipResult) => void;
1212
3434
  style?: TextBoxStyle;
@@ -1226,8 +3448,11 @@ declare namespace muhammara {
1226
3448
  /** Make the rendered text open this URL. */
1227
3449
  link?: string;
1228
3450
  charSpace?: number;
3451
+ /** Text fill color: `#gg`, `#rrggbb`, `#ccmmyykk`, `%r,g,b` percentages, a 0-255 component array, or a name registered with `chroma()`. Missing or unknown colors use `#1777d1`. */
1229
3452
  color?: Color;
1230
3453
  colorspace?: Colorspace;
3454
+ /** The Separation ink name of a `"separation"` color given by value. */
3455
+ colorName?: string;
1231
3456
  flow?: boolean;
1232
3457
  overflow?: TextOverflowCallback;
1233
3458
  layout?: number | string;
@@ -1235,13 +3460,14 @@ declare namespace muhammara {
1235
3460
  rotation?: number;
1236
3461
  rotationOrigin?: readonly [number, number];
1237
3462
  font?: string;
1238
- /** Font size in points for text() and textDimensions(); defaults to 14 when both fontSize and size are omitted. */
3463
+ /** Font size in points for text() and textDimensions(); defaults to 14 when both fontSize and size are omitted. A size that is not a finite number greater than zero throws RangeError. */
1239
3464
  fontSize?: number;
1240
- /** Font size in points for text() and textDimensions(); defaults to 14. */
3465
+ /** Font size in points for text() and textDimensions(); defaults to 14. A size that is not a finite number greater than zero throws RangeError. */
1241
3466
  size?: number;
1242
3467
  bold?: boolean;
1243
3468
  italic?: boolean;
1244
- align?: string;
3469
+ /** `Recipe.HorizontalAlign`, optionally followed by a space and `Recipe.VerticalAlign`. */
3470
+ align?: ImageAlign;
1245
3471
  highlight?: boolean | TextMarkupOptions;
1246
3472
  underline?: boolean | TextMarkupOptions;
1247
3473
  strikeOut?: boolean | TextMarkupOptions;
@@ -1257,7 +3483,7 @@ declare namespace muhammara {
1257
3483
  title?: string;
1258
3484
  open?: boolean;
1259
3485
  richText?: boolean;
1260
- flag?: AnnotOptionsFlag;
3486
+ flag?: AnnotOptionsFlag | number;
1261
3487
  icon?: AnnotOptionsIcon;
1262
3488
  date?: string;
1263
3489
  subject?: string;
@@ -1301,14 +3527,20 @@ declare namespace muhammara {
1301
3527
  name: Field;
1302
3528
  text?: string;
1303
3529
  width?: number;
3530
+ /** Cell text-box options, including onClip callbacks preserved during table layout. */
1304
3531
  cell?: TextBox;
3532
+ /** Header text styles, independent of body styles; booleans use the default header style. Table-level header options take precedence. */
1305
3533
  header?: boolean | TextOptions;
3534
+ /** Final header text-box overrides, applied after header styles and alignToData. */
1306
3535
  hcell?: TextBox;
1307
3536
  renderer?: (
1308
3537
  this: void,
3538
+ /** The own cell value; missing, inherited, and nullish values arrive as `""`. */
1309
3539
  text: undefined extends TableFieldValue<RecordType, Field>
1310
- ? Exclude<TableFieldValue<RecordType, Field>, undefined> | ""
1311
- : TableFieldValue<RecordType, Field>,
3540
+ ? Exclude<TableFieldValue<RecordType, Field>, null | undefined> | ""
3541
+ : null extends TableFieldValue<RecordType, Field>
3542
+ ? Exclude<TableFieldValue<RecordType, Field>, null | undefined> | ""
3543
+ : TableFieldValue<RecordType, Field>,
1312
3544
  record: RecordType,
1313
3545
  field: Field,
1314
3546
  row: number,
@@ -1335,16 +3567,20 @@ declare namespace muhammara {
1335
3567
  interface TableOptions<
1336
3568
  RecordType extends object = Record<string, unknown>,
1337
3569
  > extends Omit<TextOptions, "overflow"> {
3570
+ /** Per-segment height, also bounded by the current page's bottom margin. */
1338
3571
  height?: number;
3572
+ /** Comma-separated names are trimmed; array entries preserve exact keys. */
1339
3573
  order?:
1340
3574
  | string
1341
3575
  | TableField<RecordType>[]
1342
3576
  | readonly [TableField<RecordType>, ...TableField<RecordType>[]];
1343
3577
  columns?: readonly TableColumnOptions<RecordType>[];
3578
+ /** Enables headers and overrides column header styles; body text styles are not inherited. */
1344
3579
  header?:
1345
3580
  boolean | (TextOptions & { alignToData?: boolean; cell?: TextBox });
1346
3581
  border?: boolean | PolygonOptions;
1347
- row?: TextOptions & { nth?: "even" | "odd"; cell?: TextBox };
3582
+ row?: TextOptions & { nth?: TableRowNth; cell?: TextBox };
3583
+ /** Called once per overflow. A continuing destination must fit the row and repeated header or table() throws RangeError; ending the page without starting another throws Error. */
1348
3584
  overflow?: (
1349
3585
  this: Recipe,
1350
3586
  recipe: Recipe,
@@ -1363,6 +3599,8 @@ declare namespace muhammara {
1363
3599
  attributes: Array<{ name: string; value: string | null }>;
1364
3600
  styles: Record<string, string | number | number[]>;
1365
3601
  needsLineBreaker: boolean;
3602
+ /** True for a `<br>` element, which ends the current line. */
3603
+ lineBreak: boolean;
1366
3604
  size: number | undefined;
1367
3605
  sizeRatio: number;
1368
3606
  sizeRatios: number[];
@@ -1374,6 +3612,8 @@ declare namespace muhammara {
1374
3612
  color?: Color;
1375
3613
  stroke?: Color;
1376
3614
  colorspace?: Colorspace;
3615
+ /** The Separation ink name of a `"separation"` color given by value. */
3616
+ colorName?: string;
1377
3617
  lineWidth?: number;
1378
3618
  width?: number;
1379
3619
  opacity?: number;
@@ -1382,8 +3622,8 @@ declare namespace muhammara {
1382
3622
  }
1383
3623
 
1384
3624
  interface PathOptions extends DrawingOptions {
1385
- lineCap?: "butt" | "round" | "square";
1386
- lineJoin?: "miter" | "round" | "bevel";
3625
+ lineCap?: LineCap;
3626
+ lineJoin?: LineJoin;
1387
3627
  miterLimit?: number;
1388
3628
  }
1389
3629
 
@@ -1426,8 +3666,8 @@ declare namespace muhammara {
1426
3666
  | readonly [number, number, number];
1427
3667
  shaft?: number | readonly [number] | readonly [number, number];
1428
3668
  double?: boolean;
1429
- type?: 0 | 1 | 2 | "triangle" | "dart" | "kite";
1430
- at?: "head" | "tail";
3669
+ type?: 0 | 1 | 2 | ArrowType;
3670
+ at?: ArrowAt;
1431
3671
  }
1432
3672
 
1433
3673
  interface TriangleBaseOptions extends ShapeOptions {
@@ -1477,6 +3717,8 @@ declare namespace muhammara {
1477
3717
  interface RectangleOptions
1478
3718
  extends DrawingOptions, TransformOptions, LinkFillOptions {
1479
3719
  borderRadius?: BorderRadius;
3720
+ /** Take `x` and `y` as PDF coordinates of the bottom-left corner instead of Recipe top-left coordinates. */
3721
+ useGivenCoords?: boolean;
1480
3722
  }
1481
3723
 
1482
3724
  interface LineStyleOptions {
@@ -1495,16 +3737,276 @@ declare namespace muhammara {
1495
3737
  }
1496
3738
 
1497
3739
  export class Recipe {
3740
+ /**
3741
+ * @param src - `Recipe.Source.NEW` ("new", or `Buffer.from("new")`) for a new PDF,
3742
+ * otherwise the path or Buffer of the PDF to edit.
3743
+ * @param output - The output path. For a path source it defaults to
3744
+ * the source path; for a Buffer source the result is only returned by
3745
+ * `endPDF()` unless an output path is given.
3746
+ * @param options - The options for pdfDoc
3747
+ * @param options.version - The PDF version of a new PDF: 1.0 through
3748
+ * 1.7 or 2.0. Other values fall back to 1.7.
3749
+ * @param options.author - The author
3750
+ * @param options.title - The title
3751
+ * @param options.subject - The subject
3752
+ * @param options.keywords - The array of keywords
3753
+ * @param options.colorspace - The default colorspace, one
3754
+ * of the `Recipe.Colorspace` values.
3755
+ * @param options.password - Owner password; also opens a protected source.
3756
+ * @param options.userPassword - The 'view' password; also enables encryption.
3757
+ * @param options.ownerPassword - The 'edit' password.
3758
+ * @param options.userProtectionFlag - Encryption permission flags, see `permission()`.
3759
+ * @param options.fontSrcPath - Directory location(s) of additional fonts.
3760
+ * @throws {Error} If an existing source PDF cannot be read or opened for editing.
3761
+ */
1498
3762
  constructor(
1499
3763
  src: string,
1500
3764
  output?: string | null,
1501
3765
  options?: Recipe.RecipeOptions,
1502
3766
  );
1503
3767
 
3768
+ /** Special Recipe sources, such as `Recipe.Source.NEW` for a new PDF. */
3769
+ static readonly Source: {
3770
+ readonly NEW: "new";
3771
+ };
3772
+ /** How text that does not fit a text-box line is handled. */
3773
+ static readonly TextWrap: {
3774
+ readonly AUTO: "auto";
3775
+ readonly CLIP: "clip";
3776
+ readonly TRIM: "trim";
3777
+ readonly ELLIPSIS: "ellipsis";
3778
+ };
3779
+ /** Horizontal alignments of text inside a text box. */
3780
+ static readonly TextAlign: {
3781
+ readonly LEFT: "left";
3782
+ readonly CENTER: "center";
3783
+ readonly RIGHT: "right";
3784
+ readonly JUSTIFY: "justify";
3785
+ };
3786
+ /** Which table rows the `row` options apply to. */
3787
+ static readonly TableRowNth: {
3788
+ readonly EVEN: "even";
3789
+ readonly ODD: "odd";
3790
+ };
3791
+ /** Line cap styles for the `lineCap` options. */
3792
+ static readonly LineCap: {
3793
+ readonly BUTT: "butt";
3794
+ readonly ROUND: "round";
3795
+ readonly SQUARE: "square";
3796
+ };
3797
+ /** Line join styles for the `lineJoin` options. */
3798
+ static readonly LineJoin: {
3799
+ readonly MITER: "miter";
3800
+ readonly ROUND: "round";
3801
+ readonly BEVEL: "bevel";
3802
+ };
3803
+ /** The arrow point placed at the `arrow()` coordinates. */
3804
+ static readonly ArrowAt: {
3805
+ readonly HEAD: "head";
3806
+ readonly TAIL: "tail";
3807
+ };
3808
+ /** Arrow head shapes for the `arrow()` type option. */
3809
+ static readonly ArrowType: {
3810
+ readonly TRIANGLE: "triangle";
3811
+ readonly DART: "dart";
3812
+ readonly KITE: "kite";
3813
+ };
3814
+ /** How `triangle()` traits define the triangle. */
3815
+ static readonly TriangleTrait: {
3816
+ readonly SSS: "sss";
3817
+ readonly SAS: "sas";
3818
+ readonly ASA: "asa";
3819
+ readonly VTX: "vtx";
3820
+ };
3821
+ /** The triangle point placed at the `triangle()` coordinates. */
3822
+ static readonly TrianglePosition: {
3823
+ readonly A: "a";
3824
+ readonly B: "b";
3825
+ readonly C: "c";
3826
+ readonly CENTROID: "centroid";
3827
+ readonly CIRCUMCENTER: "circumcenter";
3828
+ readonly INCENTER: "incenter";
3829
+ };
3830
+ /** Page orientations reported in page metadata. */
3831
+ static readonly PageLayout: {
3832
+ readonly PORTRAIT: "portrait";
3833
+ readonly LANDSCAPE: "landscape";
3834
+ };
3835
+ /** Named page sizes for `createPage()`. */
3836
+ static readonly PageSize: {
3837
+ readonly EXECUTIVE: "executive";
3838
+ readonly FOLIO: "folio";
3839
+ readonly LEGAL: "legal";
3840
+ readonly LETTER: "letter";
3841
+ readonly LEDGER: "ledger";
3842
+ readonly TABLOID: "tabloid";
3843
+ readonly A0: "a0";
3844
+ readonly A1: "a1";
3845
+ readonly A2: "a2";
3846
+ readonly A3: "a3";
3847
+ readonly A4: "a4";
3848
+ readonly A5: "a5";
3849
+ readonly A6: "a6";
3850
+ readonly A7: "a7";
3851
+ readonly A8: "a8";
3852
+ readonly A9: "a9";
3853
+ readonly A10: "a10";
3854
+ readonly B0: "b0";
3855
+ readonly B1: "b1";
3856
+ readonly B2: "b2";
3857
+ readonly B3: "b3";
3858
+ readonly B4: "b4";
3859
+ readonly B5: "b5";
3860
+ readonly B6: "b6";
3861
+ readonly B7: "b7";
3862
+ readonly B8: "b8";
3863
+ readonly B9: "b9";
3864
+ readonly B10: "b10";
3865
+ readonly C0: "c0";
3866
+ readonly C1: "c1";
3867
+ readonly C2: "c2";
3868
+ readonly C3: "c3";
3869
+ readonly C4: "c4";
3870
+ readonly C5: "c5";
3871
+ readonly C6: "c6";
3872
+ readonly C7: "c7";
3873
+ readonly C8: "c8";
3874
+ readonly C9: "c9";
3875
+ readonly C10: "c10";
3876
+ readonly RA0: "ra0";
3877
+ readonly RA1: "ra1";
3878
+ readonly RA2: "ra2";
3879
+ readonly RA3: "ra3";
3880
+ readonly RA4: "ra4";
3881
+ readonly SRA0: "sra0";
3882
+ readonly SRA1: "sra1";
3883
+ readonly SRA2: "sra2";
3884
+ readonly SRA3: "sra3";
3885
+ readonly SRA4: "sra4";
3886
+ };
3887
+ /** Horizontal alignments. */
3888
+ static readonly HorizontalAlign: {
3889
+ readonly LEFT: "left";
3890
+ readonly CENTER: "center";
3891
+ readonly RIGHT: "right";
3892
+ };
3893
+ /** Vertical alignments. */
3894
+ static readonly VerticalAlign: {
3895
+ readonly TOP: "top";
3896
+ readonly CENTER: "center";
3897
+ readonly BOTTOM: "bottom";
3898
+ };
3899
+ /** Font styles for `registerFont()`. */
3900
+ static readonly FontStyle: {
3901
+ readonly REGULAR: "regular";
3902
+ readonly BOLD: "bold";
3903
+ readonly ITALIC: "italic";
3904
+ readonly BOLD_ITALIC: "bold-italic";
3905
+ };
3906
+ /** User access permission names for `permission()`. */
3907
+ static readonly Permission: {
3908
+ readonly PRINT: "print";
3909
+ readonly MODIFY: "modify";
3910
+ readonly COPY: "copy";
3911
+ readonly EDIT: "edit";
3912
+ readonly FILL_FORM: "fillform";
3913
+ readonly EXTRACT: "extract";
3914
+ readonly ASSEMBLE: "assemble";
3915
+ readonly PRINT_BEST: "printbest";
3916
+ };
3917
+ /** Named coordinates, accepted wherever a `RecipeCoordinate` is. */
3918
+ static readonly Coordinate: {
3919
+ readonly CENTER: "center";
3920
+ };
3921
+ /** Colorspaces accepted by the `colorspace` options. */
3922
+ static readonly Colorspace: {
3923
+ readonly RGB: "rgb";
3924
+ readonly CMYK: "cmyk";
3925
+ readonly GRAY: "gray";
3926
+ readonly SEPARATION: "separation";
3927
+ };
3928
+ /** Annotation subtypes for `annot()`. */
3929
+ static readonly AnnotSubtype: {
3930
+ readonly TEXT: "Text";
3931
+ readonly LINK: "Link";
3932
+ readonly FREE_TEXT: "FreeText";
3933
+ readonly LINE: "Line";
3934
+ readonly SQUARE: "Square";
3935
+ readonly CIRCLE: "Circle";
3936
+ readonly POLYGON: "Polygon";
3937
+ readonly POLY_LINE: "PolyLine";
3938
+ readonly HIGHLIGHT: "Highlight";
3939
+ readonly UNDERLINE: "Underline";
3940
+ readonly SQUIGGLY: "Squiggly";
3941
+ readonly STRIKE_OUT: "StrikeOut";
3942
+ readonly CARET: "Caret";
3943
+ readonly STAMP: "Stamp";
3944
+ readonly INK: "Ink";
3945
+ readonly POPUP: "Popup";
3946
+ readonly FILE_ATTACHMENT: "FileAttachment";
3947
+ readonly SOUND: "Sound";
3948
+ readonly MOVIE: "Movie";
3949
+ readonly SCREEN: "Screen";
3950
+ readonly WIDGET: "Widget";
3951
+ readonly PRINTER_MARK: "PrinterMark";
3952
+ readonly TRAP_NET: "TrapNet";
3953
+ readonly WATERMARK: "Watermark";
3954
+ readonly THREE_D: "3D";
3955
+ readonly REDACT: "Redact";
3956
+ readonly PROJECTION: "Projection";
3957
+ readonly RICH_MEDIA: "RichMedia";
3958
+ };
3959
+ /** Annotation flag names for the `flag` options. */
3960
+ static readonly AnnotFlag: {
3961
+ readonly INVISIBLE: "invisible";
3962
+ readonly HIDDEN: "hidden";
3963
+ readonly PRINT: "print";
3964
+ readonly NO_ZOOM: "nozoom";
3965
+ readonly NO_ROTATE: "norotate";
3966
+ readonly NO_VIEW: "noview";
3967
+ readonly READ_ONLY: "readonly";
3968
+ readonly LOCKED: "locked";
3969
+ readonly TOGGLE_NO_VIEW: "togglenoview";
3970
+ readonly LOCKED_CONTENTS: "lockedcontents";
3971
+ };
3972
+ /** Special `chroma()` names that run a command instead of naming a color. */
3973
+ static readonly ChromaCommand: {
3974
+ readonly LOAD: "!load";
3975
+ };
3976
+ /** Text annotation icons for the `icon` option. */
3977
+ static readonly AnnotIcon: {
3978
+ readonly COMMENT: "Comment";
3979
+ readonly KEY: "Key";
3980
+ readonly NOTE: "Note";
3981
+ readonly HELP: "Help";
3982
+ readonly NEW_PARAGRAPH: "NewParagraph";
3983
+ readonly PARAGRAPH: "Paragraph";
3984
+ readonly INSERT: "Insert";
3985
+ };
3986
+
1504
3987
  readonly position: { x: number; y: number };
1505
3988
  /** Current document metadata, keyed by one-based page number. */
1506
3989
  readonly metadata: Recipe.Metadata;
3990
+ /**
3991
+ * Read PDF metadata: the page count and, keyed by one-based page number,
3992
+ * each page's media box, rotation, layout and size.
3993
+ * @param inSrc - A PDF path or Buffer to read instead of
3994
+ * the recipe source. Reading another PDF does not change the recipe state.
3995
+ * @returns The PDF metadata.
3996
+ * @throws {Error} If the PDF cannot be read or has no pages.
3997
+ */
1507
3998
  read(inSrc?: string | Buffer): Recipe.ReadMetadata;
3999
+ /**
4000
+ * Register a callback procedure with MuhammaraJS.
4001
+ * @param key - Name assigned to the callback. When a named function is
4002
+ * registered, and its given name is what is to be used to access it, the key is unnecessary.
4003
+ * @param callback - Callback procedure that can be accessed through MuhammaraJS.
4004
+ * It is added to the shared Recipe prototype, so every Recipe instance gets it.
4005
+ * @throws {string} If the callback function is unnamed when no key is provided.
4006
+ * @throws {string} If the key conflicts with an existing Recipe prototype member.
4007
+ * @throws {string} If the callback is not a function.
4008
+ * @returns The recipe instance.
4009
+ */
1508
4010
  register<Arguments extends unknown[], Result>(
1509
4011
  key: string,
1510
4012
  callback: Recipe.ExtensionCallback<Arguments, Result>,
@@ -1519,41 +4021,150 @@ declare namespace muhammara {
1519
4021
  options?: Recipe.RecipeOptions,
1520
4022
  );
1521
4023
 
4024
+ /**
4025
+ * Create a comment annotation: a Text annotation with the Comment icon. It is
4026
+ * written when the PDF ends.
4027
+ * @param text - The text content; defaults to ''.
4028
+ * @param x - The coordinate x
4029
+ * @param y - The top coordinate y; (x, y) is the top-left corner, as for `annot()`.
4030
+ * @param options - The options
4031
+ * @param options.title - The title.
4032
+ * @param options.date - The date.
4033
+ * @param options.width - The rectangle width, as for `annot()`.
4034
+ * @param options.height - The rectangle height, extending down from y.
4035
+ * @param options.open - Open the annotation by default?; defaults to false.
4036
+ * @param options.richText - Display with rich text format, text will be transformed automatically, or you may pass in your own rich text starts with "<?xml..."
4037
+ * @param options.replies - Array of annotation replies, each with text and optional title, date, subject, richText, and flag.
4038
+ * @param options.flag - The flag property, one of the `Recipe.AnnotFlag` values.
4039
+ * @returns The recipe instance.
4040
+ */
1522
4041
  comment(
1523
4042
  text: string,
1524
- x: number,
1525
- y: number,
4043
+ x: Recipe.RecipeCoordinate,
4044
+ y: Recipe.RecipeCoordinate,
1526
4045
  options?: Recipe.CommentOptions,
1527
4046
  ): Recipe;
1528
4047
 
4048
+ /**
4049
+ * Add a clickable URL link to the current page.
4050
+ * @param url - The URL to open.
4051
+ * @param x - The top-left x coordinate.
4052
+ * @param y - The top-left y coordinate.
4053
+ * @param width - The link width.
4054
+ * @param height - The link height.
4055
+ * @returns The recipe instance.
4056
+ * @throws {TypeError} If no page is active.
4057
+ */
1529
4058
  link(
1530
4059
  url: string,
1531
- x: number,
1532
- y: number,
4060
+ x: Recipe.RecipeCoordinate,
4061
+ y: Recipe.RecipeCoordinate,
1533
4062
  width: number,
1534
4063
  height: number,
1535
4064
  ): Recipe;
1536
4065
 
4066
+ /**
4067
+ * Create an annotation. It is written when the PDF ends.
4068
+ * @todo support for rich text RC
4069
+ * @param x - The left edge of the annotation rectangle.
4070
+ * @param y - The top edge of the annotation rectangle. Like
4071
+ * `rectangle()` and `link()`, (x, y) is the rectangle's top-left corner, and
4072
+ * the rectangle extends `options.height` down from it.
4073
+ * @param subtype - The annotation subtype, one of the
4074
+ * `Recipe.AnnotSubtype` values.
4075
+ * @param options - The options
4076
+ * @param options.text - The annotation content; defaults to ''.
4077
+ * @param options.title - The title.
4078
+ * @param options.open - Open the annotation. Annotation will be closed by default. Specific to text annotations; subtype='Text'; defaults to false.
4079
+ * @param options.richText - Rich text
4080
+ * @param options.flag - The flag property, one of the `Recipe.AnnotFlag` values.
4081
+ * @param options.icon - The icon of a Text annotation, one
4082
+ * of the `Recipe.AnnotIcon` values. Viewers show 'Note' when it is omitted.
4083
+ * @param options.width - Width
4084
+ * @param options.height - Height
4085
+ * @param options.date - Date of annotation
4086
+ * @param options.subject - The subject.
4087
+ * @param options.replies - Array of annotation replies
4088
+ * @param options.border - The border width.
4089
+ * @param options.color - The annotation color, as HexColor,
4090
+ * PercentColor or DecimalColor.
4091
+ * @param options.opacity - Annotation opacity from 0 (transparent) to 1 (opaque); defaults to 1.
4092
+ * @param options.followOriginalPageRotation - Preserve the original page rotation when positioning the annotation; defaults to false.
4093
+ * @returns The recipe instance.
4094
+ */
1537
4095
  annot(
1538
- x: number,
1539
- y: number,
4096
+ x: Recipe.RecipeCoordinate,
4097
+ y: Recipe.RecipeCoordinate,
1540
4098
  subtype: Recipe.AnnotSubtype,
1541
4099
  options?: Recipe.AnnotOptions,
1542
4100
  ): Recipe;
1543
4101
 
4102
+ /**
4103
+ * Append pages from the other pdf to the current pdf. An active page is
4104
+ * finished first, so appended pages follow it in the output.
4105
+ * @param pdfSrc - The path for the other pdf.
4106
+ * @param pages - ] - A one-based page; defaults to [.
4107
+ * number or array of page numbers and inclusive ranges. Omitting it appends all
4108
+ * pages; endpoints beyond the source are clamped to its final page.
4109
+ * @returns The recipe instance.
4110
+ * @throws {RangeError} If a selection is not a positive integer or a two-value
4111
+ * range in ascending order.
4112
+ * @throws {Error} If pages were deleted with deletePage() on this Recipe.
4113
+ * @throws {Error} If the source PDF cannot be read.
4114
+ */
1544
4115
  appendPage(
1545
4116
  pdfSrc: string,
1546
4117
  pages?: number | (number | [number, number])[],
1547
4118
  ): Recipe;
1548
4119
 
4120
+ /**
4121
+ * Encrypt the pdf
4122
+ * @param options - The options
4123
+ * @param options.password - The permission password.
4124
+ * @param options.ownerPassword - The password for editing.
4125
+ * @param options.userPassword - The password for viewing & encryption.
4126
+ * @param options.userProtectionFlag - The flag for the security level, see `permission()`.
4127
+ * @returns The recipe instance. The file is encrypted by `endPDF()`;
4128
+ * Buffer sources are not encrypted.
4129
+ */
1549
4130
  encrypt(options?: Recipe.EncryptOptions): Recipe;
1550
4131
 
4132
+ /**
4133
+ * Register a custom font
4134
+ * @param fontName - The font name used in text, matched case-insensitively; defaults to ''.
4135
+ * @param fontSrcPath - The path to the font file; defaults to ''.
4136
+ * @param type - The style this file provides,; defaults to 'regular'.
4137
+ * one of the `Recipe.FontStyle` values or its short form r, b, i or bi.
4138
+ * Any other value registers the regular style.
4139
+ * @returns The recipe instance.
4140
+ */
1551
4141
  registerFont(
1552
4142
  fontName: string,
1553
4143
  fontSrcPath: string,
1554
4144
  type?: Recipe.RecipeFontStyle,
1555
4145
  ): Recipe;
1556
4146
 
4147
+ /**
4148
+ * Place images to pdf
4149
+ * @param imgSrc - The path for the image. [JPEG, PNG, TIFF, PDF]
4150
+ * @param x - The coordinate x of the top-left corner
4151
+ * @param y - The coordinate y of the top-left corner
4152
+ * @param options - The options
4153
+ * @returns The recipe instance.
4154
+ * @param options.width - The new width
4155
+ * @param options.height - The new height
4156
+ * @param options.scale - Scale the image from the original width and height.
4157
+ * @param options.keepAspectRatio - Keep the aspect ratio; defaults to true.
4158
+ * @param options.opacity - The opacity.
4159
+ * @param options.align - A `Recipe.HorizontalAlign` value, optionally
4160
+ * followed by a space and a `Recipe.VerticalAlign` value, for example
4161
+ * "center center". Horizontal center moves the image left by half its width
4162
+ * and right moves it right by half; vertical center moves it up by half its
4163
+ * height and bottom moves it down by half from its top-left placement.
4164
+ * @param options.link - Make the image open this URL.
4165
+ * @throws {TypeError} If no page is active.
4166
+ * @throws {Error} If the image cannot be read.
4167
+ */
1557
4168
  image(
1558
4169
  imgSrc: string,
1559
4170
  x: Recipe.RecipeCoordinate,
@@ -1561,16 +4172,65 @@ declare namespace muhammara {
1561
4172
  options?: Recipe.ImageOptions,
1562
4173
  ): Recipe;
1563
4174
 
1564
- info(options?: Recipe.InfoOptions): Recipe;
4175
+ /**
4176
+ * @param options - The options (when missing obtains existing PDF information)
4177
+ * @param options.author - The author
4178
+ * @param options.title - The title
4179
+ * @param options.subject - The subject
4180
+ * @param options.keywords - The array of keywords
4181
+ * @returns The existing information dictionary when options are omitted, otherwise the recipe instance.
4182
+ * A new PDF has no existing information, so the call without options returns undefined.
4183
+ * @throws {Error} If the source information cannot be read.
4184
+ */
4185
+ info(options: Recipe.InfoOptions): Recipe;
4186
+ /**
4187
+ * Read the existing information dictionary of the source PDF.
4188
+ * @returns The information keyed by lower-cased entry name, or undefined
4189
+ * for a new PDF or a source without an Info dictionary.
4190
+ * @throws {Error} If the source information cannot be read.
4191
+ */
4192
+ info(): Record<string, string> | undefined;
1565
4193
 
4194
+ /**
4195
+ * @param key - The key
4196
+ * @param value - The value; other values are converted with toString().
4197
+ * @returns The recipe instance.
4198
+ * @throws {TypeError} If the key or value is null or undefined.
4199
+ */
1566
4200
  custom(key: string, value: string): Recipe;
1567
4201
 
4202
+ /**
4203
+ * Insert a page from the other pdf
4204
+ * @param afterPageNumber - The one-based page number to insert after; 0 inserts before the first page.
4205
+ * @param pdfSrc - The path for the other pdf
4206
+ * @param srcPageNumber - The one-based page number to be inserted from the other pdf.
4207
+ * @returns The recipe instance. Pages are inserted by `endPDF()`;
4208
+ * Buffer sources do not support insertion.
4209
+ * @throws {Error} If pages were deleted with deletePage() on this Recipe.
4210
+ * @throws {Error} If afterPageNumber is not a number.
4211
+ * @throws {TypeError} If pdfSrc or srcPageNumber is missing.
4212
+ */
1568
4213
  insertPage(
1569
4214
  afterPageNumber: number,
1570
4215
  pdfSrc: string,
1571
4216
  srcPageNumber: number,
1572
4217
  ): Recipe;
1573
4218
 
4219
+ /**
4220
+ * Overlay a pdf to the current pdf
4221
+ * @param pdfSrc - The path for the overlay pdf
4222
+ * @param x - The PDF x offset from the left edge, or options when using the two-argument form; defaults to 0.
4223
+ * @param y - The offset from the top edge; defaults to 0.
4224
+ * @param options - The options.
4225
+ * @param options.scale - Scale the overlay pdf, default is 1
4226
+ * @param options.page - Page of the overlay pdf, default is 1
4227
+ * @param options.keepAspectRatio - To keep the aspect ratio when scaling, default is true
4228
+ * @param options.fitWidth - To set the width to 100% (use with keepAspectRatio=true)
4229
+ * @param options.fitHeight - To set the height to 100% (use with keepAspectRatio=true)
4230
+ * @returns The recipe instance.
4231
+ * @throws {TypeError} If no page is active.
4232
+ * @throws {Error} If the overlay PDF cannot be read.
4233
+ */
1574
4234
  overlay(pdfSrc: string, options?: Recipe.OverlayOptions): Recipe;
1575
4235
  overlay(
1576
4236
  pdfSrc: string,
@@ -1579,34 +4239,147 @@ declare namespace muhammara {
1579
4239
  options?: Recipe.OverlayOptions,
1580
4240
  ): Recipe;
1581
4241
 
4242
+ /**
4243
+ * Create a new page, specifying either actual width and height, or the name
4244
+ * of a supported page size (eg. 'letter', 'letter-size')
4245
+ * '-size' will be removed from string but is discouraged to use.
4246
+ * @param pageWidth - The page width, or a `Recipe.PageSize` name.
4247
+ * Known named medium sizes: executive, folio, legal, letter, ledger, tabloid, a0-a10, b0-b10, c0-c10, ra0-ra4, sra0-sra4.
4248
+ * Unknown names use the default letter size.
4249
+ * @param pageHeight - The page height, or rotation (90) when page size name given.
4250
+ * @param margins - page margin definitions.
4251
+ * @param margins.left - Left margin.
4252
+ * @param margins.right - Right margin.
4253
+ * @param margins.top - Top margin.
4254
+ * @param margins.bottom - Bottom margin.
4255
+ * @returns The recipe instance.
4256
+ * @throws {Error} If pages were deleted with deletePage() on this Recipe.
4257
+ */
1582
4258
  createPage(
1583
4259
  pageWidth?: number,
1584
4260
  pageHeight?: number,
1585
4261
  margins?: Recipe.RecipeMargins,
1586
4262
  ): Recipe;
1587
4263
  createPage(
1588
- pageType: string,
4264
+ pageType: Recipe.PageSize,
1589
4265
  rotation?: number,
1590
4266
  margins?: Recipe.RecipeMargins,
1591
4267
  ): Recipe;
4268
+ /**
4269
+ * Set the rotation of the current page.
4270
+ * @param rotation - The page rotation in degrees, a multiple of 90.
4271
+ * @returns The recipe instance.
4272
+ * @throws {TypeError} If no page is active.
4273
+ */
1592
4274
  rotate(rotation: number): Recipe;
4275
+ /**
4276
+ * Finish a page. Without an active page this does nothing.
4277
+ * @returns The recipe instance.
4278
+ * @throws {Error} If the page cannot be written.
4279
+ */
1593
4280
  endPage(): Recipe;
4281
+ /**
4282
+ * Set a page box on the active new page.
4283
+ * @param box - An `ePDFPageBox*` constant or a `PageBox` name.
4284
+ * @param left - The PDF left coordinate.
4285
+ * @param bottom - The PDF bottom coordinate.
4286
+ * @param right - The PDF right coordinate.
4287
+ * @param top - The PDF top coordinate.
4288
+ * @returns The recipe instance.
4289
+ * @throws {RangeError} If the page box is unknown.
4290
+ * @throws {TypeError} If no page is active or a coordinate is a BigInt.
4291
+ */
1594
4292
  setPageBox(
1595
- box: PDFPageBoxType,
4293
+ box: PDFPageBoxType | PageBox,
1596
4294
  left: number,
1597
4295
  bottom: number,
1598
4296
  right: number,
1599
4297
  top: number,
1600
4298
  ): Recipe;
1601
4299
 
4300
+ /**
4301
+ * Start editing a page
4302
+ * @param pageNumber - The one-based page number to be edited.
4303
+ * @returns The recipe instance.
4304
+ * @throws {Error} If the page does not exist in the source PDF.
4305
+ */
1602
4306
  editPage(pageNumber: number): Recipe;
1603
- deletePage(pageNumbers: number | number[]): Recipe;
4307
+ /**
4308
+ * Delete one or more pages from an existing PDF.
4309
+ * Page numbers are one-based and refer to the original source document.
4310
+ * @param pageNumbers - Page number or page numbers to delete.
4311
+ * @param options - Deletion options.
4312
+ * @returns The recipe instance.
4313
+ * @throws {TypeError} If options is not an object or pruneReferences is
4314
+ * not a boolean.
4315
+ * @throws {RangeError} If a page number does not identify an original page.
4316
+ * @throws {Error} If the Recipe has no existing source, has ended, would delete
4317
+ * every page, combines deletion with page composition, or the page tree,
4318
+ * page labels or retained references cannot be rewritten. A failed call
4319
+ * leaves the queued deletions unchanged.
4320
+ */
4321
+ deletePage(
4322
+ pageNumbers: number | number[],
4323
+ options?: DeletePageOptions,
4324
+ ): Recipe;
1604
4325
 
4326
+ /**
4327
+ * Replace text shown with `Tj` in a page's single content stream. Each
4328
+ * operand is decoded through the font selected by `Tf` and compared with
4329
+ * `text`; a match is rewritten with `replacement`, encoded through the same
4330
+ * font in the operand's original literal or hex form. `TJ`, `'`, and `"`
4331
+ * operands and text split across operators are not replaced.
4332
+ *
4333
+ * @param text - Text to replace, as any Unicode string.
4334
+ * @param replacement - Replacement text. It can only use glyphs the font
4335
+ * already has; embedded subset fonts usually carry just their original
4336
+ * text's glyphs.
4337
+ * @param pageNumber - One-based page number.
4338
+ * @returns The Recipe instance.
4339
+ * @throws {TypeError} If text or replacement is not a string, or if the
4340
+ * page number is not a positive integer.
4341
+ * @throws {RangeError} If the source document has no such page.
4342
+ * @throws {Error} If the page does not have one indirect content stream, or
4343
+ * the matched font cannot be read, has a malformed `/Widths` array, or has
4344
+ * no glyph for a replacement character.
4345
+ */
1605
4346
  replaceText(text: string, replacement: string, pageNumber: number): Recipe;
4347
+ /**
4348
+ * Removes shown text from an existing page's content streams, and
4349
+ * optionally its Form XObjects.
4350
+ * @param pageNumber - One-based page number.
4351
+ * @param options - Removal options.
4352
+ * @returns The Recipe instance.
4353
+ * @throws {TypeError} If the page number is not a positive integer, or the
4354
+ * options are not an object.
4355
+ * @throws {RangeError} If the source document has no such page.
4356
+ * @throws {Error} If the page's Contents holds a direct stream.
4357
+ */
4358
+ removeText(pageNumber: number, options?: RemoveTextOptions): Recipe;
1606
4359
 
4360
+ /**
4361
+ * Get page information
4362
+ * @param pageNumber - The one-based page number.
4363
+ * @returns The page information.
4364
+ * @throws {TypeError} If the page is unknown.
4365
+ */
1607
4366
  pageInfo(pageNumber: number): RecipePageInfo;
4367
+ /**
4368
+ * Get information about the current page.
4369
+ * @returns The current page information, or null when no page has been created or edited.
4370
+ */
1608
4371
  getCurrentPageInfo(): RecipePageInfo | null;
1609
4372
 
4373
+ /**
4374
+ * Set/Get current page margins.
4375
+ * @param left - Left margin width or an object holding margin properties to be set.
4376
+ * Valid margin property names are: left, right, top, bottom.
4377
+ * @param right - Right margin width.
4378
+ * @param top - Top margin height.
4379
+ * @param bottom - Bottom margin height.
4380
+ * @returns When parameters are given, the value returned is the recipe handle. When no
4381
+ * parameters given, the return value is the current page margin object.
4382
+ */
1610
4383
  margins(): Required<Recipe.RecipeMargins>;
1611
4384
  margins(margins: Recipe.RecipeMargins): Recipe;
1612
4385
  margins(
@@ -1615,12 +4388,114 @@ declare namespace muhammara {
1615
4388
  top?: number,
1616
4389
  bottom?: number,
1617
4390
  ): Recipe;
4391
+ /**
4392
+ * Get the document information dictionary.
4393
+ * @returns The document information dictionary.
4394
+ */
1618
4395
  getPageInfo(): InfoDictionary;
4396
+ /**
4397
+ * Pause the current page content context.
4398
+ * @returns The recipe instance.
4399
+ * @throws {Error} If there is no active page content context.
4400
+ */
1619
4401
  pauseContext(): Recipe;
4402
+ /**
4403
+ * Resume the current page content context after it has been paused.
4404
+ * @returns The recipe instance.
4405
+ * @throws {Error} If there is no paused page content context.
4406
+ */
1620
4407
  resumeContext(): Recipe;
1621
- rotateContent(degrees: number, x?: number, y?: number): Recipe;
4408
+ /**
4409
+ * Rotate subsequent content around a point in Recipe coordinates.
4410
+ * @param degrees - Clockwise rotation in degrees.
4411
+ * @param x - Rotation origin x coordinate; defaults to 0.
4412
+ * @param y - Rotation origin y coordinate; defaults to 0.
4413
+ * @returns The recipe instance.
4414
+ * @throws {TypeError} If no page is active.
4415
+ */
4416
+ rotateContent(
4417
+ degrees: number,
4418
+ x?: Recipe.RecipeCoordinate,
4419
+ y?: Recipe.RecipeCoordinate,
4420
+ ): Recipe;
4421
+ /**
4422
+ * Split the pdf
4423
+ * @param outputDir - The path for the output PDFs; defaults to ''.
4424
+ * @param prefix - The output filename prefix. Defaults to the
4425
+ * source filename; pass one for a Buffer source, which has no filename.
4426
+ * @returns The recipe instance. Each page is written to
4427
+ * `<outputDir>/<prefix>-<pageNumber>.pdf`.
4428
+ * @throws {Error} If the source reader was released by endPDF(), or an output
4429
+ * file cannot be written.
4430
+ */
1622
4431
  split(outputDir?: string, prefix?: string): Recipe;
1623
4432
 
4433
+ /**
4434
+ * Write text elements
4435
+ * @todo support break words
4436
+ * @param text - The text content; defaults to ''.
4437
+ * @param x - The coordinate x, or the options to continue at the current position
4438
+ * @param y - The coordinate y
4439
+ * @param options - The options
4440
+ * @param options.color - Text color (HexColor, PercentColor or DecimalColor)
4441
+ * @param options.opacity - opacity; defaults to 1.
4442
+ * @param options.rotation - Accept: +/- 0 through 360; defaults to 0.
4443
+ * @param options.rotationOrigin - ] - [originX, originY]; defaults to [x,y.
4444
+ * @param options.font - The font. 'Arial', 'Helvetica'; defaults to Helvetica.
4445
+ * @param options.size - The font size; defaults to 14.
4446
+ * @param options.charSpace - space to be added between characters, units in points; defaults to 0.
4447
+ * @param options.align - This is the alignment of the text in relationship to its position; defaults to 'left top'.
4448
+ * coordinates, specified as 'horizontal vertical': a `Recipe.HorizontalAlign` value, optionally followed by a
4449
+ * space and a `Recipe.VerticalAlign` value.
4450
+ * @param options.highlight - Text markup annotation.
4451
+ * @param options.underline - Text markup annotation.
4452
+ * @param options.strikeOut - Text markup annotation.
4453
+ * @param options.html - Interpret text as html
4454
+ * @param options.flow - Used to activate/deactivate text flow which is the; defaults to false.
4455
+ * ability to use multiple calls to 'text' to create an overall text box.
4456
+ * @param options.layout - An identifier of the layout to be associated with given text.
4457
+ * @param options.overflow - Called when the text is going to exceed the area
4458
+ * of the given text object. Intended for column layouts. Its parameter is (self) where 'self' is the recipe handle so
4459
+ * that other recipe interfaces can be called. The return value can be 'true' which indicates that text processing
4460
+ * should stop, or 'false' which indicates that the text should continue being processed with the original [x,y]
4461
+ * coordinates, or it can be an object containing a 'column' property indicating either a layout column index
4462
+ * or a set of [x,y] coordinates where the next set of layout columns should be positioned for the remaining text.
4463
+ * @param options.hilite - Used to hilite given text; defaults to false.
4464
+ * @param options.hilite.color - text hilite color (HexColor, PercentColor or DecimalColor); defaults to yellow.
4465
+ * @param options.hilite.opacity - text hilite color opacity; defaults to .5.
4466
+ * @param options.textBox - Text Box to fit in.
4467
+ * @param options.textBox.width - Text Box width; defaults to 100.
4468
+ * @param options.textBox.height - Text Box fixed height
4469
+ * @param options.textBox.minHeight - Text Box minimum height; defaults to 0.
4470
+ * @param options.textBox.padding - Text Box padding, [top, right, bottom, left]; defaults to 0.
4471
+ * @param options.textBox.lineHeight - Text Box line height; defaults to 0.
4472
+ * @param options.textBox.wrap - Text wrapping mechanism, may be true, false,; defaults to 'auto'.
4473
+ * or a `Recipe.TextWrap` value: 'auto', 'clip', 'trim', 'ellipsis'. All the option values that are not equivalent to 'auto' dictate
4474
+ * how the text which does not fit on a line is to be truncated. True is equivalent to 'auto'. False is equivalent to 'ellipsis'.
4475
+ * @param options.textBox.textAlign - Alignment inside text box, specified as 'horizontal vertical',; defaults to 'left top'.
4476
+ * where horizontal is a `Recipe.TextAlign` value and vertical a `Recipe.VerticalAlign` value.
4477
+ * @param options.textBox.clipIfExceedsBox - Render only complete lines that fit within the text box height; defaults to false.
4478
+ * @param options.textBox.onClip - Called as onClip(recipe, result) when clipping leaves text unrendered.
4479
+ * Do not call endPage() or endPDF() in this callback because the text operation is still active.
4480
+ * @param options.textBox.style - Text Box styles
4481
+ * @param options.textBox.style.lineWidth - Text Box border width; defaults to 2.
4482
+ * @param options.textBox.style.stroke - Text Box border color (HexColor, PercentColor or DecimalColor)
4483
+ * @param options.textBox.style.dash - ] - Text Box border border dash style [number, number]; defaults to [.
4484
+ * @param options.textBox.style.fill - Text Box border background color (HexColor, PercentColor or DecimalColor)
4485
+ * @param options.textBox.style.opacity - Text Box border background opacity; defaults to 1.
4486
+ * @param options.textBox.style.borderRadius - Border radius to apply to get rounded corners; defaults to 0.
4487
+ * @param options.title - Title of annotation
4488
+ * @param options.open - Open the annotation. Annotation will be closed by default. Specific to text annotations; subtype='Text'; defaults to false.
4489
+ * @param options.richText - Rich text in annotation
4490
+ * @param options.flag - The annotation flag, a `Recipe.AnnotFlag` value.
4491
+ * @param options.icon - The icon of annotation, a `Recipe.AnnotIcon` value. Specific to text annotations; defaults to 'Note'.
4492
+ * @param options.date - Date of text to show up on annotation
4493
+ * @param options.subject - Subject of annotation.
4494
+ * @param options.link - Make the text open this URL.
4495
+ * @returns The recipe instance. Without an active page nothing is drawn.
4496
+ * @throws {TypeError} If `options.charSpace` is not a finite number; nothing is drawn.
4497
+ * @throws {Error} If an overflow callback names an undefined layout, or a font cannot be loaded.
4498
+ */
1624
4499
  text(text: string, options?: Recipe.TextOptions): Recipe;
1625
4500
  text(
1626
4501
  text: string,
@@ -1628,10 +4503,43 @@ declare namespace muhammara {
1628
4503
  y: Recipe.RecipeCoordinate,
1629
4504
  options?: Recipe.TextOptions,
1630
4505
  ): Recipe;
4506
+ /**
4507
+ * Get text dimensions
4508
+ * @param text - text to be measured
4509
+ * @param options - The options
4510
+ * @param options.font - name of font from which measurements are to be taken; defaults to 'helvetica'.
4511
+ * @param options.size - size of font to be used in taking measurements; defaults to 14.
4512
+ * @param options.charSpace - character spacing being applied to the given text; defaults to 0.
4513
+ * @param options.bold - Measure with the bold style of the font.
4514
+ * @param options.italic - Measure with the italic style of the font.
4515
+ * @returns measurement components of given text: width, height, xMin, xMax, yMin, yMax
4516
+ * @throws {Error} If the font file cannot be loaded.
4517
+ */
1631
4518
  textDimensions(text: string, options?: Recipe.TextOptions): TextDimension;
4519
+ /**
4520
+ * Move text positioning down N lines in text box
4521
+ * @param lines - the number of lines to reposition x and y coordinates; defaults to 1.
4522
+ * @param returnCoords - indicate whether or not to return [x,y] coordinates; defaults to false.
4523
+ * @returns - when returnCoord false, the recipe object, when true, the new [x,y] coordinates.
4524
+ */
1632
4525
  movedown(lines?: number, returnCoords?: false): Recipe;
1633
4526
  movedown(lines: number, returnCoords: true): number[];
1634
4527
  movedown(lines?: number, returnCoords?: boolean): Recipe | number[];
4528
+ /**
4529
+ * Define text column layout
4530
+ * @param id - The identifier to be associated with the layout. (See 'text' layout option)
4531
+ * @param x - The coordinate x used to position text columns on page. When zero or omitted, left margin used.
4532
+ * @param y - The coordinate y used to position text columns on page. When zero or omitted, top margin used.
4533
+ * @param width - The width of a text column. When zero or omitted, space between left and right margin used.
4534
+ * @param height - The height of a text column. When zero or omitted, space between top and bottom margin used.
4535
+ * @param options - The options.
4536
+ * @param options.columns - Represents the number of columns in which to divide the given width.
4537
+ * @param options.gap - Defines the separation between layout columns, units in points; defaults to 18.
4538
+ * @param options.reset - True indicates that the a new layout should be produced for the given
4539
+ * layout id, so any previous layout associated with the given id will be lost.
4540
+ * @returns The recipe instance.
4541
+ * @throws {TypeError} If width or height is omitted while no page is active.
4542
+ */
1635
4543
  layout(
1636
4544
  id: string | number,
1637
4545
  x?: number,
@@ -1640,6 +4548,63 @@ declare namespace muhammara {
1640
4548
  height?: number,
1641
4549
  options?: Recipe.LayoutOptions,
1642
4550
  ): Recipe;
4551
+ /**
4552
+ * Display text data in tabular form
4553
+ * Rows and headers use their rendered text-box heights, including padding,
4554
+ * minimum heights, fixed heights, and HTML layout. Empty contents or no selected
4555
+ * columns leave the Recipe unchanged. Array-form order preserves exact keys.
4556
+ * Header text styles are independent of body styles: column header options
4557
+ * (or defaults) are overridden by table header options, then alignToData
4558
+ * and column hcell box overrides are applied.
4559
+ * @param x - The coordinate x used to position table on page
4560
+ * @param y - The coordinate y used to position table on page
4561
+ * @param contents - the data to be placed into the table
4562
+ * @param options - The options
4563
+ * @param options.height - The height designation of the table
4564
+ * @param options.order - Defines the order of the named columns in the table.
4565
+ * It can also be used to choose a subset of the actual data found in the given contents.
4566
+ * @param options.columns - Holds the defining options for columns in the table.
4567
+ * @param options.columns - [].name] - The name of the content data field to be associated with the column.
4568
+ * This field is mandatory when supplying column options.
4569
+ * @param options.columns - [].text] - The title to be applied to the column header.
4570
+ * When missing, the data field name is used.
4571
+ * @param options.columns - [].width=100] - The width of table column.
4572
+ * @param options.columns - [].cell] - Holds the options to be applied to a column table cell.
4573
+ * All textBox options from the 'text' interface can be used here.
4574
+ * @param options.columns - [].color] - Text color (HexColor, PercentColor or DecimalColor)
4575
+ * @param options.columns - [].opacity=1] - opacity
4576
+ * @param options.columns - [].font=Helvetica] - The font. 'Arial', 'Helvetica'...
4577
+ * @param options.columns - [].size=14] - The font size
4578
+ * @param options.columns - [].renderer] - function to be called which can be used to modify the text options for a particular
4579
+ * table cell. The function is called with `(text, data, field, row)`, where `text` is the text to be written in the cell,
4580
+ * `data` holds the text elements in the table row, `field` is the column field, and `row` is the one-based row number. The function returns an object with the text attributes that
4581
+ * are to be modified for the table cell.
4582
+ * @param options.header - When true, the column name associated with a column will; defaults to false.
4583
+ * appear at the top of the column. When presented as an object it is the set of unique options to be applied to column headers.
4584
+ * All 'text' interface options can be used.
4585
+ * @param options.header.cell - All textBox options from the 'text' interface can be used here.
4586
+ * @param options.border - Used to define table and cell border characteristics
4587
+ * @param options.border.width - Thickness of lines used in the border; defaults to .5.
4588
+ * @param options.border.stroke - line color (HexColor, PercentColor or DecimalColor)
4589
+ * @param options.overflow - Called when the next table entry is going to expand the table
4590
+ * beyond the given height or page boundary. Its parameters are (self, row) where 'self' is the recipe handle so
4591
+ * that other recipe interfaces can be called, and the row number of the data which caused the data overflow.
4592
+ * The callback's `this` is also the Recipe instance.
4593
+ * The return value can be 'true' which indicates that data processing should stop, or 'false' which indicates that
4594
+ * the data should continue being processed with the original [x,y] coordinates, or it can be an object containing
4595
+ * a 'position' property indicating the [x,y] coordinates where the next table for the remaining data should start.
4596
+ * @param options.row - text properties to be applied to all cells in a table row.
4597
+ * @param options.row.cell - All textBox options from the 'text' interface can be used here.
4598
+ * @param options.row.nth - A `Recipe.TableRowNth` value, indicating that the
4599
+ * properties should be applied only to 'even' or 'odd' rows.
4600
+ * @returns The recipe instance.
4601
+ * @throws {TypeError} If no page is active.
4602
+ * @throws {RangeError} If the overflow callback continues into an area too small
4603
+ * for the pending row and its repeated header. Return true to stop, or provide
4604
+ * enough space; rows are not split and the callback is called once per overflow.
4605
+ * @throws {Error} If the overflow callback continues after ending the page
4606
+ * without starting another one.
4607
+ */
1643
4608
  table<RecordType extends object>(
1644
4609
  x: number,
1645
4610
  y: number,
@@ -1647,59 +4612,282 @@ declare namespace muhammara {
1647
4612
  options?: Recipe.TableOptions<RecordType>,
1648
4613
  ): Recipe;
1649
4614
 
4615
+ /**
4616
+ * move the current position to target position
4617
+ * @param x - The coordinate x
4618
+ * @param y - The coordinate y
4619
+ * @returns The recipe instance.
4620
+ * @throws {TypeError} If no page is active.
4621
+ */
1650
4622
  moveTo(x: number, y: number): Recipe;
1651
4623
 
4624
+ /**
4625
+ * Draw a line from current position
4626
+ * @param x - The coordinate x
4627
+ * @param y - The coordinate y
4628
+ * @param options - The options
4629
+ * @returns The recipe instance.
4630
+ * @throws {TypeError} If no page is active.
4631
+ * @param options.color - HexColor, PercentColor or DecimalColor
4632
+ * @param options.stroke - HexColor, PercentColor or DecimalColor
4633
+ * @param options.lineWidth - The line width
4634
+ * @param options.opacity - how transparent should line be, from 0: invisible to 1: opaque
4635
+ * @param options.dash - The dash pattern [dashSize, gapSize] or [dashAndGapSize]
4636
+ * @param options.dashPhase - distance into dash pattern at which to start dash (default: 0, immediately)
4637
+ * @param options.lineCap - open line end style, a `Recipe.LineCap` value (default: 'round')
4638
+ * @param options.lineJoin - joined line end style, a `Recipe.LineJoin` value (default: 'round')
4639
+ * @param options.miterLimit - limit at which 'miter' joins are forced to 'bevel' (default: 1.414)
4640
+ */
1652
4641
  lineTo(x: number, y: number, options?: Recipe.LineToOptions): Recipe;
1653
4642
 
4643
+ /**
4644
+ * Draw a line through coordinate pairs, or from (startX, startY) to
4645
+ * (endX, endY) when called as `line(startX, startY, endX, endY, options?)`.
4646
+ * @param coordinates - The array of coordinate [[x,y], [m,n]], or the start x
4647
+ * @param options - The options, or the start y in the four-number form
4648
+ * @returns The recipe instance.
4649
+ * @param options.color - HexColor, PercentColor or DecimalColor
4650
+ * @param options.stroke - HexColor, PercentColor or DecimalColor
4651
+ * @param options.lineWidth - The line width
4652
+ * @param options.opacity - how transparent should line be, from 0: invisible to 1: opaque
4653
+ * @param options.dash - The dash pattern [dashSize, gapSize] or [dashAndGapSize]
4654
+ * @param options.dashPhase - distance into dash pattern at which to start dash (default: 0, immediately)
4655
+ * @param options.lineCap - open line end style, a `Recipe.LineCap` value (default: 'round')
4656
+ * @param options.lineJoin - joined line end style, a `Recipe.LineJoin` value (default: 'round')
4657
+ * @param options.miterLimit - limit at which 'miter' joins are forced to 'bevel' (default: 1.414)
4658
+ * @throws {TypeError} If no page is active.
4659
+ */
1654
4660
  line(coordinates: number[][], options?: Recipe.LineOptions): Recipe;
4661
+ line(
4662
+ startX: number,
4663
+ startY: number,
4664
+ endX: number,
4665
+ endY: number,
4666
+ options?: Recipe.LineOptions,
4667
+ ): Recipe;
1655
4668
 
4669
+ /**
4670
+ * Draw a polygon
4671
+ * @param coordinates - The array of coordinate [[x,y], ... [m,n]]
4672
+ * @param options - The options
4673
+ * @returns The recipe instance.
4674
+ * @param options.color - HexColor, PercentColor or DecimalColor
4675
+ * @param options.stroke - HexColor, PercentColor or DecimalColor
4676
+ * @param options.fill - HexColor, PercentColor or DecimalColor
4677
+ * @param options.lineWidth - The line width
4678
+ * @param options.opacity - The opacity
4679
+ * @param options.dash - The dash pattern [dashSize, gapSize] or [dashAndGapSize]
4680
+ * @param options.dashPhase - distance into dash pattern at which to start dash (default: 0, immediately)
4681
+ * @param options.rotation - Accept: +/- 0 through 360. Default: 0
4682
+ * @param options.rotationOrigin - [originX, originY] Default: x, y
4683
+ * @param options.lineCap - open line end style, a `Recipe.LineCap` value (default: 'round')
4684
+ * @param options.lineJoin - joined line end style, a `Recipe.LineJoin` value (default: 'round')
4685
+ * @param options.miterLimit - limit at which 'miter' joins are forced to 'bevel' (default: 1.414)
4686
+ * @param options.link - Make the polygon's bounding box open this URL.
4687
+ * @throws {TypeError} If no page is active or there are no coordinates.
4688
+ */
1656
4689
  polygon(coordinates: number[][], options?: Recipe.PolygonOptions): Recipe;
1657
4690
 
4691
+ /**
4692
+ * Draw a circle
4693
+ * @param x - The coordinate x of the center
4694
+ * @param y - The coordinate y of the center
4695
+ * @param radius - The radius
4696
+ * @param options - The options
4697
+ * @param options.color - HexColor, PercentColor or DecimalColor
4698
+ * @param options.stroke - HexColor, PercentColor or DecimalColor
4699
+ * @param options.fill - HexColor, PercentColor or DecimalColor
4700
+ * @param options.lineWidth - The line width
4701
+ * @param options.opacity - The opacity
4702
+ * @param options.dash - The dash style [number, number]
4703
+ * @param options.link - Make the circle's bounding square open this URL.
4704
+ * @returns The recipe instance.
4705
+ * @throws {TypeError} If no page is active.
4706
+ */
1658
4707
  circle(
1659
- x: number,
1660
- y: number,
4708
+ x: Recipe.RecipeCoordinate,
4709
+ y: Recipe.RecipeCoordinate,
1661
4710
  radius: number,
1662
4711
  options?: Recipe.CircleOptions,
1663
4712
  ): Recipe;
1664
4713
 
4714
+ /**
4715
+ * Draw a rectangle
4716
+ * @param x - The coordinate x of the top-left corner
4717
+ * @param y - The coordinate y of the top-left corner
4718
+ * @param width - The width
4719
+ * @param height - The height
4720
+ * @param options - The options
4721
+ * @param options.color - HexColor, PercentColor or DecimalColor
4722
+ * @param options.stroke - HexColor, PercentColor or DecimalColor
4723
+ * @param options.fill - HexColor, PercentColor or DecimalColor
4724
+ * @param options.lineWidth - The line width
4725
+ * @param options.opacity - The opacity
4726
+ * @param options.dash - The dash style [number, number]
4727
+ * @param options.rotation - Accept: +/- 0 through 360. Default: 0
4728
+ * @param options.rotationOrigin - [originX, originY] Default: x, y
4729
+ * @param options.borderRadius - Radius size for rounded corners.
4730
+ * When a one to four number array can be used to give specific sizees to each corner.
4731
+ * The numbering starts from the top, left corner, and goes clockwise around the text box.
4732
+ * Missing values in the array are filled in by opposite corner values.
4733
+ * @param options.link - Make the rectangle open this URL.
4734
+ * @param options.useGivenCoords - Take x and y as PDF coordinates of the bottom-left corner.
4735
+ * @returns The recipe instance.
4736
+ * @throws {TypeError} If no page is active.
4737
+ */
1665
4738
  rectangle(
1666
- x: number,
1667
- y: number,
4739
+ x: Recipe.RecipeCoordinate,
4740
+ y: Recipe.RecipeCoordinate,
1668
4741
  width: number,
1669
4742
  height: number,
1670
4743
  options?: Recipe.RectangleOptions,
1671
4744
  ): Recipe;
1672
4745
 
4746
+ /**
4747
+ * Draw an ellipse
4748
+ * @param cx - x-coordinate of center point of ellipse
4749
+ * @param cy - y-coordinate of center point of ellipse
4750
+ * @param rx - radius length from the center point along x-axis
4751
+ * @param ry - radius length from the center point along y-axis
4752
+ * @param options -
4753
+ * @param options.color - HexColor, PercentColor or DecimalColor
4754
+ * @param options.stroke - HexColor, PercentColor or DecimalColor
4755
+ * @param {string|number[]}[ options.fill] - HexColor, PercentColor or DecimalColor
4756
+ * @param options.lineWidth - The line width
4757
+ * @param options.opacity - The opacity
4758
+ * @param options.dash - The dash style [number, number]
4759
+ * @param options.rotation - Accept: +/- 0 through 360. Default: 0
4760
+ * @param options.rotationOrigin - [originX, originY] Default: x, y
4761
+ * @returns The recipe instance.
4762
+ * @throws {TypeError} If no page is active.
4763
+ */
1673
4764
  ellipse(
1674
- cx: number,
1675
- cy: number,
4765
+ cx: Recipe.RecipeCoordinate,
4766
+ cy: Recipe.RecipeCoordinate,
1676
4767
  rx: number,
1677
4768
  ry: number,
1678
4769
  options?: Recipe.EllipseOptions,
1679
4770
  ): Recipe;
4771
+ /**
4772
+ * Draw an arc of a circle.
4773
+ * @param x - the x coordinate of the arc center point
4774
+ * @param y - the y coordinate of the arc center point
4775
+ * @param radius - the distance from the given x,y coordinates from which to produce the arc
4776
+ * @param startAngle - the start of the arc in degree units +/- 0 through 360. Positive values go clockwise, Negative values, counterclockwise; defaults to 0.
4777
+ * @param endAngle - the end of the arc in degree units +/- 0 through 360. Positive values go clockwise, Negative values, counterclockwise; defaults to 360.
4778
+ * @param options -
4779
+ * @param options.color - HexColor, PercentColor or DecimalColor
4780
+ * @param options.stroke - HexColor, PercentColor or DecimalColor
4781
+ * @param {string|number[]}[ options.fill] - HexColor, PercentColor or DecimalColor
4782
+ * @param options.lineWidth - The line width
4783
+ * @param options.opacity - The opacity
4784
+ * @param options.dash - The dash style [number, number]
4785
+ * @param options.rotation - Accept: +/- 0 through 360; defaults to 0.
4786
+ * @param options.rotationOrigin - [originX, originY] Default: x, y
4787
+ * @returns The recipe instance.
4788
+ * @throws {TypeError} If no page is active.
4789
+ */
1680
4790
  arc(
1681
- x: number,
1682
- y: number,
4791
+ x: Recipe.RecipeCoordinate,
4792
+ y: Recipe.RecipeCoordinate,
1683
4793
  radius: number,
1684
4794
  startAngle?: number,
1685
4795
  endAngle?: number,
1686
4796
  options?: Recipe.EllipseOptions,
1687
4797
  ): Recipe;
4798
+ /**
4799
+ * Draw a closed sector of a circle.
4800
+ * @param x - the x coordinate of the pie center point
4801
+ * @param y - the y coordinate of the pie center point
4802
+ * @param radius - the distance from the center point to the arc
4803
+ * @param startAngle - the start of the arc in degree units; defaults to 0.
4804
+ * @param endAngle - the end of the arc in degree units; defaults to 360.
4805
+ * @param options - The path options.
4806
+ * @returns The recipe instance.
4807
+ * @throws {TypeError} If no page is active.
4808
+ */
1688
4809
  pie(
1689
- x: number,
1690
- y: number,
4810
+ x: Recipe.RecipeCoordinate,
4811
+ y: Recipe.RecipeCoordinate,
1691
4812
  radius: number,
1692
4813
  startAngle?: number,
1693
4814
  endAngle?: number,
1694
4815
  options?: Recipe.EllipseOptions,
1695
4816
  ): Recipe;
4817
+ /**
4818
+ * Set the line style for the current page content context.
4819
+ * @param options - The line style options.
4820
+ * @param options.width - The line width.
4821
+ * @param options.lineWidth - Alias for width.
4822
+ * @param options.cap - The PDF line cap style, a `LineCapStyle` value.
4823
+ * @param options.join - The PDF line join style: 0 miter, 1 round, 2 bevel.
4824
+ * @param options.miterLimit - The miter limit.
4825
+ * @param options.dash - The dash pattern.
4826
+ * @param options.dashPhase - The dash pattern phase.
4827
+ * @returns The recipe instance.
4828
+ * @throws {TypeError} If no page is active.
4829
+ */
1696
4830
  lineStyle(options?: Recipe.LineStyleOptions): Recipe;
4831
+ /**
4832
+ * Set the line width.
4833
+ *
4834
+ * @param width - The line width.
4835
+ * @returns The recipe instance.
4836
+ * @throws {TypeError} If no page is active.
4837
+ */
1697
4838
  lineWidth(width: number): Recipe;
1698
- /** Set fill and stroke opacity from 0 (transparent) to 1 (opaque). */
4839
+ /**
4840
+ * Sets fill and stroke opacity.
4841
+ * @param opacity - From 0 (transparent) to 1 (opaque).
4842
+ * @returns The Recipe instance.
4843
+ * @throws {RangeError} If opacity is not a finite number from 0 to 1.
4844
+ */
1699
4845
  opacity(opacity: number): Recipe;
1700
- fill(color?: Recipe.Color): Recipe;
1701
- stroke(color?: Recipe.Color): Recipe;
1702
- fillAndStroke(fill?: Recipe.Color, stroke?: Recipe.Color): Recipe;
4846
+ /**
4847
+ * Fill the current path.
4848
+ *
4849
+ * This compatibility method currently has no effect.
4850
+ * @returns The recipe instance.
4851
+ */
4852
+ fill(): Recipe;
4853
+ /**
4854
+ * Stroke the current path.
4855
+ *
4856
+ * This compatibility method currently has no effect.
4857
+ * @returns The recipe instance.
4858
+ */
4859
+ stroke(): Recipe;
4860
+ /**
4861
+ * Fill and stroke the current path.
4862
+ *
4863
+ * This compatibility method currently has no effect.
4864
+ * @returns The recipe instance.
4865
+ */
4866
+ fillAndStroke(): Recipe;
4867
+ /**
4868
+ * Draw an N-sided regular polygon
4869
+ * @param cx - x-coordinate of center point of regular polygon
4870
+ * @param cy - y-coordinate of center point of regular polygon
4871
+ * @param radius - The radius, distance from the center of the polygon to a vertice.
4872
+ * @param sides - the number of sides of the regular polygon, at least 3;; defaults to 3.
4873
+ * or the options when the side count is omitted.
4874
+ * @param options - The options
4875
+ * @param options.color - HexColor or DecimalColor
4876
+ * @param options.stroke - HexColor or DecimalColor
4877
+ * @param options.fill - HexColor or DecimalColor
4878
+ * @param options.lineWidth - The line width
4879
+ * @param options.opacity - The opacity
4880
+ * @param options.dash - The dash style [number, number]
4881
+ * @param options.rotation - Accept: +/- 0 through 360; defaults to 0.
4882
+ * @param options.rotationOrigin - ] - [originX, originY]; defaults to [cx,cy.
4883
+ * @param options.rotationVertice - the number of the vertice to be used as rotation origin
4884
+ * @param options.skewX - the angle skew off the x-axis
4885
+ * @param options.skewY - the angle skew off the y-axis.
4886
+ * @param options.link - Make the polygon's bounding square open this URL.
4887
+ * @param options.debug - Also draw the circumscribed circle and center.
4888
+ * @returns The recipe instance.
4889
+ * @throws {TypeError} If no page is active.
4890
+ */
1703
4891
  n_gon(
1704
4892
  cx: number,
1705
4893
  cy: number,
@@ -1707,6 +4895,29 @@ declare namespace muhammara {
1707
4895
  sides?: number | Recipe.NGonOptions,
1708
4896
  options?: Recipe.NGonOptions,
1709
4897
  ): Recipe;
4898
+ /**
4899
+ * Draw an N pointed star
4900
+ * @param cx - x-coordinate of center point of regular polygon
4901
+ * @param cy - y-coordinate of center point of regular polygon
4902
+ * @param radius - The radius, distance from the center to a star point.
4903
+ * @param points - number of points on star, at least 5; or; defaults to 5.
4904
+ * the options when the point count is omitted.
4905
+ * @param options - The options
4906
+ * @param options.color - HexColor or DecimalColor
4907
+ * @param options.stroke - HexColor or DecimalColor
4908
+ * @param options.fill - HexColor or DecimalColor
4909
+ * @param options.lineWidth - The line width
4910
+ * @param options.opacity - The opacity
4911
+ * @param options.dash - The dash style [number, number]
4912
+ * @param options.rotation - Accept: +/- 0 through 360. Default: 0
4913
+ * @param options.rotationOrigin - [originX, originY] Default: x, y
4914
+ * @param options.skewX - the angle skew off the x-axis
4915
+ * @param options.skewY - the angle skew off the y-axis.
4916
+ * @param options.link - Make the star's bounding square open this URL.
4917
+ * @param options.debug - Also draw the circumscribed circle and center.
4918
+ * @returns The recipe instance.
4919
+ * @throws {TypeError} If no page is active.
4920
+ */
1710
4921
  star(
1711
4922
  cx: number,
1712
4923
  cy: number,
@@ -1714,6 +4925,38 @@ declare namespace muhammara {
1714
4925
  points?: number | Recipe.ShapeOptions,
1715
4926
  options?: Recipe.ShapeOptions,
1716
4927
  ): Recipe;
4928
+ /**
4929
+ * Draw a triangle, by specifying three side lengths, two side lengths and one inclusive angle, one side length and two adjacent angles, or with a set of vertices.
4930
+ * @param x - x-coordinate used to position triangle, by default associated with left vertex of triangle base.
4931
+ * @param y - y-coordinate used to position triangle, by default associated with left vertex of triangle base.
4932
+ * @param traits - the data defining the triangle. Angles are specified as degrees, sides in units of points (1/72 in.).
4933
+ * @param options - The options
4934
+ * @param options.traitID - indicates what type of data is being passed in the traits parameter,; defaults to 'sss'.
4935
+ * one of the `Recipe.TriangleTrait` values:
4936
+ * ('sss'- three side lengths, 'sas' - side-angle-side (sideA, <C, sideB), 'asa' - angle-side-angle (<B, sideC, <A),
4937
+ * or 'vtx' - three vertex points [x,y])
4938
+ * @param options.position - the position of the triangle to be set at the given x,y coordinates,; defaults to 'b'.
4939
+ * one of the `Recipe.TrianglePosition` values.
4940
+ * The values can be one of: 'A' - the A vertex (right vertex of triangle base), 'B' - the B vertex (left vertex of triangle base),
4941
+ * 'C' - the C vertex (apex of triangle), 'centroid', 'circumcenter', or 'incenter' of the triangle.
4942
+ * @param options.flipX - flip triangle up to down through rotation point; defaults to false.
4943
+ * @param options.flipY - flip triangle right to left through rotation point; defaults to false.
4944
+ * @param options.color - HexColor or DecimalColor
4945
+ * @param options.stroke - HexColor or DecimalColor
4946
+ * @param options.fill - HexColor or DecimalColor
4947
+ * @param options.lineWidth - The line width
4948
+ * @param options.opacity - The opacity
4949
+ * @param options.dash - The dash style [number, number]
4950
+ * @param options.rotation - Accept: +/- 0 through 360. Default: 0
4951
+ * @param options.rotationOrigin - [originX, originY] Default: x, y
4952
+ * @param options.skewX - the angle skew off the x-axis
4953
+ * @param options.skewY - the angle skew off the y-axis.
4954
+ * @returns The recipe instance.
4955
+ * @param options.link - Make the triangle's bounding box open this URL.
4956
+ * @param options.debug - Also draw the reference points and labels.
4957
+ * @throws {Error} If traits does not contain three values or does not define a valid triangle.
4958
+ * @throws {TypeError} If no page is active.
4959
+ */
1717
4960
  triangle(
1718
4961
  x: number,
1719
4962
  y: number,
@@ -1732,21 +4975,113 @@ declare namespace muhammara {
1732
4975
  traits: Recipe.MutableTriangleVertices,
1733
4976
  options: Recipe.TriangleVertexOptions,
1734
4977
  ): Recipe;
4978
+ /**
4979
+ * Draw an arrow
4980
+ * @param x - x-coordinate position
4981
+ * @param y - y-coordinate position
4982
+ * @param options - arrow and polygon options
4983
+ * @param options.type - indicates the type of arrow head to produce,; defaults to 0.
4984
+ * a `Recipe.ArrowType` value or its number (0-'triangle', 1-'dart', 2-'kite').
4985
+ * Note, that the value of base offset in head option overrides this value.
4986
+ * @param options.head - ] defines the length, width and base offset of arrow head; defaults to [10,20,0.
4987
+ * A single number can be used to assign both the length and width of arrow, giving the base offset value as zero.
4988
+ * @param options.shaft - ] defines the length and width of the arrow shaft; defaults to [10,10.
4989
+ * @param options.double - indicate double headed arrow production; defaults to false.
4990
+ * @param options.at - position and/or rotate at the `Recipe.ArrowAt` head or tail of arrow instead of at center.
4991
+ * @param options.debug - Draw the drop point; 2 also labels the reference points.
4992
+ * @returns The recipe instance.
4993
+ * @throws {TypeError} If no page is active.
4994
+ */
1735
4995
  arrow(x: number, y: number, options?: Recipe.ArrowOptions): Recipe;
4996
+ /**
4997
+ * Associate color values to names
4998
+ *
4999
+ * The colorspace parameter is optional. When it is missing, the colorspace
5000
+ * is automatically determined by the given color value. Note that the special
5001
+ * PDF color space called 'separation' may also be used. The color value is then
5002
+ * treated as the alternative color when the named 'separation' color is unavailable.
5003
+ *
5004
+ * If the 'name' parameter is `Recipe.ChromaCommand.LOAD` ('!load'), the second parameter is the name of a JSON
5005
+ * formatted file containing a formatted list of defined colors associated with the
5006
+ * color spaces rgb, cmyk, gray, or separation (think PANTONE color definitions).
5007
+ * This file will be merged with existing set of known colors. The color values
5008
+ * must be specified as hex values.
5009
+ *
5010
+ * For example,
5011
+ * {
5012
+ * 'rgb': {'purple':'ff00ff', 'red':'#ff0000'},
5013
+ * 'cmyk': {'cyan':'ff000000', 'magenta':'%0,100,0,0'},
5014
+ * 'gray': {'grey':'#33'}
5015
+ * }
5016
+ *
5017
+ * @param name - the name to be associated to given color value, or `Recipe.ChromaCommand.LOAD`
5018
+ * @param value - the color value (HexColor, DecimalColor, or PercentColor), or the path of the JSON file to load
5019
+ * @param colorspace - One of the `Recipe.Colorspace`; defaults to ''.
5020
+ * values; empty picks gray, rgb or cmyk from the value length.
5021
+ * @returns The recipe instance.
5022
+ * @throws {Error} If the file to load cannot be read or is not valid JSON.
5023
+ * @throws {Error} If a loaded color definition has an unrecognized colorspace.
5024
+ * @throws {Error} If a color value has an invalid size.
5025
+ * @throws {TypeError} If the colorspace is unknown.
5026
+ */
1736
5027
  chroma<ColorspaceValue extends string | undefined = undefined>(
1737
5028
  name: string,
1738
5029
  value: Recipe.Color,
1739
5030
  colorspace?: Recipe.ValidColorspace<ColorspaceValue>,
1740
5031
  ): Recipe;
5032
+ /**
5033
+ * Encryption user access permissions
5034
+ *
5035
+ * This function supplies the numeric value for the encrypt function's 'userProtectionFlag'
5036
+ * option. When no argument is given, the default 'print' value is used.
5037
+ *
5038
+ * @param flags - One or more `Recipe.Permission` values; defaults to 'print'.
5039
+ * (print, modify, copy, edit, fillform, extract, assemble, printbest),
5040
+ * separated by commas, for example `[Permission.PRINT, Permission.COPY].join()`.
5041
+ * @returns The numeric user protection flag.
5042
+ * @throws {Error} If a name is not a `Recipe.Permission` value.
5043
+ */
1741
5044
  permission(flags?: Recipe.PermissionList): number;
5045
+ /**
5046
+ * Write the PDF object structure to a file.
5047
+ * @param output - The output file path.
5048
+ * @returns The recipe instance.
5049
+ * @throws {Error} If the source reader was released by endPDF(), or the
5050
+ * output file cannot be written.
5051
+ */
1742
5052
  structure(output: string): Recipe;
5053
+ /**
5054
+ * Convert HTML into Recipe text layout objects.
5055
+ * @param htmlCodes - The HTML source. Tag names are matched case-insensitively.
5056
+ * @param options - Text options used to initialize the objects.
5057
+ * @param options.font - The font of every object.
5058
+ * @param options.size - The base font size of every object.
5059
+ * @returns The parsed text layout objects: one per child node,
5060
+ * each with its value, tag, style flags, link, font size ratio and childs.
5061
+ */
1743
5062
  htmlToTextObjects(
1744
5063
  htmlCodes: string,
1745
5064
  options?: Recipe.TextOptions,
1746
5065
  ): Recipe.HtmlTextObject[];
1747
5066
 
5067
+ /**
5068
+ * End the pdfDoc. Finalization happens once; later calls do not rewrite the
5069
+ * PDF and invoke the callback with the completed output when applicable.
5070
+ * An active page is finished first, so a forgotten endPage() does not cost
5071
+ * that page. A failed finalization retires the Recipe and later calls
5072
+ * rethrow the original error.
5073
+ * @param callback - Called when the PDF is
5074
+ * finished: with the output Buffer for a Buffer source without an output
5075
+ * path, with the output path for a Buffer source with one, and without an
5076
+ * argument for a path source.
5077
+ * @returns The callback result, or undefined without a callback.
5078
+ * @throws {Error} If pages are being deleted while a page is still open.
5079
+ * @throws {Error} If finalization fails; later calls rethrow the same error.
5080
+ */
1748
5081
  endPDF(): void;
1749
5082
  endPDF<T>(callback: (output?: Buffer | string) => T): T;
5083
+ /** The 6.x callback shape, also accepted as `Recipe.EndPDFCallback`. */
5084
+ endPDF<T>(callback: (buffer: Buffer) => T): T;
1750
5085
  }
1751
5086
  }
1752
5087