@ironsoftware/ironpdf 2026.2.1 → 2026.4.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.
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +4 -2
- package/src/index.js.map +1 -1
- package/src/index.ts +2 -2
- package/src/internal/IronPdfEngine.ProtoFiles/iron_pdf_service.proto +2 -0
- package/src/internal/IronPdfEngine.ProtoFiles/qpdf.proto +17 -0
- package/src/internal/generated_proto/iron_pdf_service.d.ts +2 -0
- package/src/internal/generated_proto/iron_pdf_service.d.ts.map +1 -1
- package/src/internal/generated_proto/iron_pdf_service.ts +2 -0
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts +14 -0
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.d.ts.map +1 -1
- package/src/internal/generated_proto/ironpdfengineproto/IronPdfService.ts +18 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestIdP.d.ts +10 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestIdP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestIdP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestIdP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestIdP.ts +13 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestStreamP.d.ts +18 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestStreamP.d.ts.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestStreamP.js +4 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestStreamP.js.map +1 -0
- package/src/internal/generated_proto/ironpdfengineproto/QPdfCompressInMemoryRequestStreamP.ts +21 -0
- package/src/internal/grpc_layer/pdfium/compress.d.ts +7 -0
- package/src/internal/grpc_layer/pdfium/compress.d.ts.map +1 -1
- package/src/internal/grpc_layer/pdfium/compress.js +81 -1
- package/src/internal/grpc_layer/pdfium/compress.js.map +1 -1
- package/src/internal/grpc_layer/pdfium/compress.ts +121 -0
- package/src/internal/grpc_layer/pdfium/pdfa.d.ts +1 -0
- package/src/internal/grpc_layer/pdfium/pdfa.d.ts.map +1 -1
- package/src/internal/grpc_layer/pdfium/pdfa.js +22 -1
- package/src/internal/grpc_layer/pdfium/pdfa.js.map +1 -1
- package/src/internal/grpc_layer/pdfium/pdfa.ts +26 -0
- package/src/internal/grpc_layer/pdfium/signing.d.ts +2 -1
- package/src/internal/grpc_layer/pdfium/signing.d.ts.map +1 -1
- package/src/internal/grpc_layer/pdfium/signing.js +38 -1
- package/src/internal/grpc_layer/pdfium/signing.js.map +1 -1
- package/src/internal/grpc_layer/pdfium/signing.ts +44 -1
- package/src/public/pdfDocument.d.ts +57 -2
- package/src/public/pdfDocument.d.ts.map +1 -1
- package/src/public/pdfDocument.js +118 -1
- package/src/public/pdfDocument.js.map +1 -1
- package/src/public/pdfDocument.ts +2226 -2074
- package/src/public/signature.d.ts +33 -0
- package/src/public/signature.d.ts.map +1 -1
- package/src/public/signature.ts +34 -0
|
@@ -1,2074 +1,2226 @@
|
|
|
1
|
-
import {Buffer} from "buffer";
|
|
2
|
-
import {
|
|
3
|
-
BarcodeStampOptions,
|
|
4
|
-
BarcodeType, ChangeTrackingModes,
|
|
5
|
-
ChromePdfRenderOptions,
|
|
6
|
-
DigitalSignature,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
56
|
-
import {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
import
|
|
64
|
-
import {
|
|
65
|
-
import {
|
|
66
|
-
import {
|
|
67
|
-
import {
|
|
68
|
-
import {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
import {
|
|
79
|
-
import
|
|
80
|
-
import {
|
|
81
|
-
import {
|
|
82
|
-
import {
|
|
83
|
-
import {
|
|
84
|
-
import {
|
|
85
|
-
import {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
*
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
//
|
|
138
|
-
// *
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
(
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
*
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
*
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* -
|
|
212
|
-
*
|
|
213
|
-
* -
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* ```
|
|
254
|
-
*
|
|
255
|
-
*
|
|
256
|
-
*
|
|
257
|
-
*
|
|
258
|
-
*
|
|
259
|
-
* @
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
(
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
(
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
*
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
(
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
*
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
//#
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
*
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
/**
|
|
406
|
-
*
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
) {
|
|
433
|
-
return z.function()
|
|
434
|
-
.args(
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
)
|
|
438
|
-
.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
*
|
|
445
|
-
* @param
|
|
446
|
-
* @param
|
|
447
|
-
*/
|
|
448
|
-
public async
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return z.function()
|
|
518
|
-
.args(
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
*
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
.
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
.
|
|
646
|
-
(
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
.
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
}
|
|
684
|
-
|
|
685
|
-
//#endregion
|
|
686
|
-
|
|
687
|
-
//#region
|
|
688
|
-
/**
|
|
689
|
-
*
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
.
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
*
|
|
725
|
-
* @param
|
|
726
|
-
*/
|
|
727
|
-
public async
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
.
|
|
734
|
-
(
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
}
|
|
755
|
-
|
|
756
|
-
/**
|
|
757
|
-
*
|
|
758
|
-
*/
|
|
759
|
-
public async
|
|
760
|
-
return this.
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
/**
|
|
774
|
-
*
|
|
775
|
-
* @param
|
|
776
|
-
* @param
|
|
777
|
-
*/
|
|
778
|
-
public async
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
): Promise<void> {
|
|
782
|
-
return z.function()
|
|
783
|
-
.args(
|
|
784
|
-
.returns(z.promise(z.void()))
|
|
785
|
-
.implement(this.
|
|
786
|
-
(
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
/**
|
|
790
|
-
*
|
|
791
|
-
* @param
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
* @param
|
|
825
|
-
*/
|
|
826
|
-
public async
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
*
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
*
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
.
|
|
903
|
-
(
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
*
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
.
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
.
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
.
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
*
|
|
1026
|
-
* @
|
|
1027
|
-
*/
|
|
1028
|
-
public async
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
//#
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
* @
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
/**
|
|
1154
|
-
*
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
case "
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
): Promise<PdfDocument> {
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
*
|
|
1412
|
-
* @param
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
*
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
return
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
|
-
/**
|
|
1512
|
-
*
|
|
1513
|
-
* @param
|
|
1514
|
-
* @param
|
|
1515
|
-
*/
|
|
1516
|
-
private async
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
): Promise<void> {
|
|
1561
|
-
await
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
*
|
|
1658
|
-
*
|
|
1659
|
-
* @
|
|
1660
|
-
*/
|
|
1661
|
-
private async
|
|
1662
|
-
|
|
1663
|
-
options?: {
|
|
1664
|
-
/**
|
|
1665
|
-
* @default "all"
|
|
1666
|
-
*/
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
*
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
}
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
}
|
|
1753
|
-
|
|
1754
|
-
/**
|
|
1755
|
-
*
|
|
1756
|
-
*
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
|
|
1836
|
-
|
|
1837
|
-
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
*
|
|
1925
|
-
*
|
|
1926
|
-
*
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
*
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
);
|
|
1992
|
-
}
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
await
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2044
|
-
|
|
2045
|
-
|
|
2046
|
-
|
|
2047
|
-
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2052
|
-
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
*
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
1
|
+
import {Buffer} from "buffer";
|
|
2
|
+
import {
|
|
3
|
+
BarcodeStampOptions,
|
|
4
|
+
BarcodeType, ChangeTrackingModes,
|
|
5
|
+
ChromePdfRenderOptions,
|
|
6
|
+
DigitalSignature,
|
|
7
|
+
VerifiedSignature,
|
|
8
|
+
HtmlAffix,
|
|
9
|
+
HtmlFilePath,
|
|
10
|
+
HtmlStampOptions,
|
|
11
|
+
HtmlString,
|
|
12
|
+
HttpLoginCredentials,
|
|
13
|
+
ImageBuffer,
|
|
14
|
+
ImageFilePath,
|
|
15
|
+
ImageStampOptions,
|
|
16
|
+
ImageToPdfOptions,
|
|
17
|
+
ImageType,
|
|
18
|
+
PageInfo,
|
|
19
|
+
PageRotation,
|
|
20
|
+
PdfInput,
|
|
21
|
+
PdfPageSelection,
|
|
22
|
+
PdfPaperSize,
|
|
23
|
+
PdfPassword, PdfPermission,
|
|
24
|
+
SaveOptions,
|
|
25
|
+
TextAffix,
|
|
26
|
+
TextStampOptions,
|
|
27
|
+
} from "./types";
|
|
28
|
+
|
|
29
|
+
import {
|
|
30
|
+
barcodeTypeSchema, booleanSchema, bufferArraySchema, bufferSchema, changeTrackingModesSchema,
|
|
31
|
+
filePathSchema,
|
|
32
|
+
htmlFilePathSchema,
|
|
33
|
+
htmlStringSchema,
|
|
34
|
+
imageBufferSchema,
|
|
35
|
+
imageFilePathSchema,
|
|
36
|
+
mapStringSchema,
|
|
37
|
+
numberSchema, pdfFilePathSchema,
|
|
38
|
+
pdfInputSchema,
|
|
39
|
+
pdfPageSelectionSchema, pdfPasswordSchema, saveOptionsSchema, stringArraySchema,
|
|
40
|
+
stringSchema, urlSchema
|
|
41
|
+
} from "../internal/zod/typeSchema";
|
|
42
|
+
import {z} from "zod";
|
|
43
|
+
import {pdfPermissionSchema} from "../internal/zod/securitySchema";
|
|
44
|
+
import {pdfDocumentSchema} from "../internal/zod/pdfDocumentSchema";
|
|
45
|
+
import {
|
|
46
|
+
barcodeStampOptionsSchema,
|
|
47
|
+
htmlStampOptionsSchema,
|
|
48
|
+
imageStampOptionsSchema,
|
|
49
|
+
textStampOptionsSchema
|
|
50
|
+
} from "../internal/zod/stampSchema";
|
|
51
|
+
import {htmlAffixSchema, textAffixSchema} from "../internal/zod/affixSchema";
|
|
52
|
+
import {digitalSignatureSchema} from "../internal/zod/signatureSchema";
|
|
53
|
+
import {imageToPdfOptionsSchema, imageTypeSchema} from "../internal/zod/imageSchema";
|
|
54
|
+
import {pdfPaperSizeSchema} from "../internal/zod/paperSchema";
|
|
55
|
+
import {pageRotationSchema} from "../internal/zod/pageSchema";
|
|
56
|
+
import {chromePdfRenderOptionsSchema, httpLoginCredentialsSchema} from "../internal/zod/renderSchema";
|
|
57
|
+
import {
|
|
58
|
+
getFileName,
|
|
59
|
+
getImageExtType,
|
|
60
|
+
separateImageBufferOrImagePathInput,
|
|
61
|
+
separatePdfInput
|
|
62
|
+
} from "../internal/grpc_layer/util";
|
|
63
|
+
import fs from "fs";
|
|
64
|
+
import {mergePdfs, renderHtmlToPdf, renderHtmlZipToPdf, renderUrlToPdf, renderHtmlFileToPdf} from "../internal/grpc_layer/chrome/render";
|
|
65
|
+
import {disposePdf, getBinaryData, openPdfFileBuffer} from "../internal/grpc_layer/pdfium/io";
|
|
66
|
+
import {Access} from "../internal/access";
|
|
67
|
+
import {renderImagesBufferToPdf, renderImagesFilesToPdf} from "../internal/grpc_layer/chrome/image";
|
|
68
|
+
import {compressAndSaveAs, compressImage, compressInMemory, compressInMemoryStream, compressStructTree} from "../internal/grpc_layer/pdfium/compress";
|
|
69
|
+
import {Readable} from "stream";
|
|
70
|
+
import {
|
|
71
|
+
duplicate,
|
|
72
|
+
getPageInfo,
|
|
73
|
+
insertPdf,
|
|
74
|
+
removePage,
|
|
75
|
+
resizePage,
|
|
76
|
+
setPageRotation
|
|
77
|
+
} from "../internal/grpc_layer/pdfium/page";
|
|
78
|
+
import {extractRawImages, rasterizeToImageBuffers} from "../internal/grpc_layer/pdfium/image";
|
|
79
|
+
import Jimp from "jimp";
|
|
80
|
+
import {extractAllText, replaceText} from "../internal/grpc_layer/pdfium/text";
|
|
81
|
+
import {PdfAVersions, PdfUAVersions, toPdfA, toPdfUA} from "../internal/grpc_layer/pdfium/pdfa";
|
|
82
|
+
import {getMetadataDict, removeMetadata, setMetadata, setMetadataDict} from "../internal/grpc_layer/pdfium/metadata";
|
|
83
|
+
import {getSignatureCount, getVerifiedSignatures, signPdf} from "../internal/grpc_layer/pdfium/signing";
|
|
84
|
+
import {addHtmlAffix, addTextAffix} from "../internal/grpc_layer/pdfium/headerFooter";
|
|
85
|
+
import {stampBarcode, stampHtml, stampImage, stampText} from "../internal/grpc_layer/chrome/stamp";
|
|
86
|
+
import {addBackgroundForeground} from "../internal/grpc_layer/pdfium/BackgroundForeground";
|
|
87
|
+
import {
|
|
88
|
+
getPermission,
|
|
89
|
+
removePasswordsAndEncryption,
|
|
90
|
+
setOwnerPasswords, setSecurity,
|
|
91
|
+
setUserPasswords
|
|
92
|
+
} from "../internal/grpc_layer/pdfium/security";
|
|
93
|
+
import { NaturalLanguages } from "./naturalLanguages";
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Represents a PDF document. Allows: loading, editing, manipulating, merging, signing printing and saving PDFs.
|
|
97
|
+
*
|
|
98
|
+
* @remark Make sure that you call {@link PdfDocument.close} or {@link cleanUp} to free the memory, when you stop using the PdfDocument object.
|
|
99
|
+
*/
|
|
100
|
+
export class PdfDocument{
|
|
101
|
+
|
|
102
|
+
//#region io
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Open or Create a PdfDocument from a {@link PdfInput}
|
|
106
|
+
* @param pdfInput {@link PdfInput}
|
|
107
|
+
* @param options including {@link PdfPassword} {@link ChromePdfRenderOptions} {@link HttpLoginCredentials} mainHtmlFile
|
|
108
|
+
*/
|
|
109
|
+
public static async open(
|
|
110
|
+
pdfInput: PdfInput,
|
|
111
|
+
options?: {
|
|
112
|
+
/**
|
|
113
|
+
* required for open a protected PDF file
|
|
114
|
+
* @default undefined
|
|
115
|
+
*/
|
|
116
|
+
password?: PdfPassword | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
119
|
+
* @default undefined
|
|
120
|
+
*/
|
|
121
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
122
|
+
/**
|
|
123
|
+
* Apply httpLoginCredentials if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
124
|
+
* @default undefined
|
|
125
|
+
*/
|
|
126
|
+
httpLoginCredentials?: HttpLoginCredentials | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* Apply mainHtmlFile if PdfInput is {@link ZipFilePath}
|
|
129
|
+
* @default index.html
|
|
130
|
+
*/
|
|
131
|
+
mainHtmlFile?: string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Optionally track changes to the document (for use with incremental saves)
|
|
134
|
+
* @default {@link ChangeTrackingModes.AutoChangeTracking}
|
|
135
|
+
*/
|
|
136
|
+
trackChanges?: ChangeTrackingModes | undefined;
|
|
137
|
+
// /**
|
|
138
|
+
// * Apply baseUrl if
|
|
139
|
+
// * The HTML base URL for which references to external CSS, Javascript and Image files will be relative.
|
|
140
|
+
// * @default undefined
|
|
141
|
+
// */
|
|
142
|
+
// baseUrl ?: string | undefined; //not supported
|
|
143
|
+
} | undefined
|
|
144
|
+
): Promise<PdfDocument> {
|
|
145
|
+
return z.function()
|
|
146
|
+
.args(
|
|
147
|
+
pdfInputSchema,
|
|
148
|
+
z.object({
|
|
149
|
+
password: pdfPasswordSchema.optional(),
|
|
150
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
151
|
+
httpLoginCredentials: httpLoginCredentialsSchema.optional(),
|
|
152
|
+
mainHtmlFile: stringSchema.optional(),
|
|
153
|
+
trackChanges: changeTrackingModesSchema.optional(),
|
|
154
|
+
}).optional()
|
|
155
|
+
)
|
|
156
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
157
|
+
.implement(this.internal_open.bind(this))
|
|
158
|
+
(pdfInput, options);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Open a PdfDocument from .pdf file
|
|
163
|
+
* @param pdfFilePath A path to .pdf file
|
|
164
|
+
* @param Optionally track changes to the document (for use with incremental saves)
|
|
165
|
+
*/
|
|
166
|
+
public static async fromFile(
|
|
167
|
+
pdfFilePath: string, trackChanges?: ChangeTrackingModes | undefined
|
|
168
|
+
): Promise<PdfDocument> {
|
|
169
|
+
return z.function()
|
|
170
|
+
.args(
|
|
171
|
+
pdfFilePathSchema,
|
|
172
|
+
changeTrackingModesSchema.optional()
|
|
173
|
+
)
|
|
174
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
175
|
+
.implement(this.internal_fromFile.bind(this))
|
|
176
|
+
(pdfFilePath, trackChanges);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Create a PdfDocument from an Url
|
|
181
|
+
* @param url A website Url
|
|
182
|
+
* @param options including {@link ChromePdfRenderOptions}
|
|
183
|
+
*/
|
|
184
|
+
public static async fromUrl(
|
|
185
|
+
url: URL | string,
|
|
186
|
+
options?: {
|
|
187
|
+
/**
|
|
188
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
189
|
+
* @default undefined
|
|
190
|
+
*/
|
|
191
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
192
|
+
} | undefined
|
|
193
|
+
): Promise<PdfDocument> {
|
|
194
|
+
return z.function()
|
|
195
|
+
.args(
|
|
196
|
+
z.union([urlSchema, stringSchema]),
|
|
197
|
+
z.object({
|
|
198
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
199
|
+
}).optional()
|
|
200
|
+
)
|
|
201
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
202
|
+
.implement(this.internal_fromUrl.bind(this))
|
|
203
|
+
(url, options);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Creates a PDF file from a local Zip file, and returns it as a {@link PdfDocument}.
|
|
208
|
+
* IronPDF is a W3C standards compliant HTML rendering based on Google's Chromium browser.
|
|
209
|
+
* If your output PDF does not look as expected:
|
|
210
|
+
*
|
|
211
|
+
* - Validate your HTML file using https://validator.w3.org/ & CSS https://jigsaw.w3.org/css-validator/
|
|
212
|
+
*
|
|
213
|
+
* - To debug HTML, view the file in Chrome web browser's print preview which will work almost exactly as IronPDF.
|
|
214
|
+
*
|
|
215
|
+
* - Read our detailed documentation on pixel perfect HTML to PDF: https://ironpdf.com/tutorials/pixel-perfect-html-to-pdf/
|
|
216
|
+
*
|
|
217
|
+
* @param zipFilePath Path to a Zip to be rendered as a PDF.
|
|
218
|
+
* @param options including {@link ChromePdfRenderOptions} and `mainHtmlFile` a main .html file default: `index.html`
|
|
219
|
+
*/
|
|
220
|
+
public static async fromZip(
|
|
221
|
+
zipFilePath: string,
|
|
222
|
+
options?: {
|
|
223
|
+
/**
|
|
224
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
225
|
+
* @default undefined
|
|
226
|
+
*/
|
|
227
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
228
|
+
/**
|
|
229
|
+
* a main .html file default: `index.html`
|
|
230
|
+
*/
|
|
231
|
+
mainHtmlFile?: string | undefined;
|
|
232
|
+
} | undefined
|
|
233
|
+
): Promise<PdfDocument> {
|
|
234
|
+
return z.function()
|
|
235
|
+
.args(
|
|
236
|
+
stringSchema,
|
|
237
|
+
z.object({
|
|
238
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
239
|
+
mainHtmlFile: stringSchema.optional()
|
|
240
|
+
}).optional()
|
|
241
|
+
)
|
|
242
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
243
|
+
.implement(this.internal_fromZip.bind(this))
|
|
244
|
+
(zipFilePath, options);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Creates a PDF file from a Html string, and returns it as an {@link PdfDocument} object which can be edited and saved to disk or served on a website.
|
|
249
|
+
*
|
|
250
|
+
* ------------------------------------------------
|
|
251
|
+
*
|
|
252
|
+
* **Usage:**
|
|
253
|
+
* ```ts
|
|
254
|
+
* const pdf = await fromHtml(htmlStringOrHtmlFilePath, renderOptions);
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* ------------------------------------------------
|
|
258
|
+
*
|
|
259
|
+
* @param htmlStringOrHtmlFilePath The Html to be rendered as a PDF.
|
|
260
|
+
* @param options including {@link ChromePdfRenderOptions}
|
|
261
|
+
* @returns A `PdfDocument` generated from the provided HTML file.
|
|
262
|
+
*
|
|
263
|
+
* ---
|
|
264
|
+
* ### Important Notes:
|
|
265
|
+
*
|
|
266
|
+
* 🐳 **Docker Limitation:**
|
|
267
|
+
* This method **does not work** for **HTML file path** when the application runs inside a Docker environment
|
|
268
|
+
* due to rendering engine restrictions.
|
|
269
|
+
* In such cases, use `fromZip()` instead.
|
|
270
|
+
*
|
|
271
|
+
* 📄 **Input:** Requires access to a local HTML file on disk if htmlFilePath is passing.
|
|
272
|
+
*
|
|
273
|
+
* ---
|
|
274
|
+
* ### Related Methods:
|
|
275
|
+
* 📌 `fromZip()` — Recommended alternative for rendering from HTML file when running inside Docker.
|
|
276
|
+
*/
|
|
277
|
+
public static async fromHtml(
|
|
278
|
+
htmlStringOrHtmlFilePath: string,
|
|
279
|
+
options?: {
|
|
280
|
+
/**
|
|
281
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
282
|
+
* @default undefined
|
|
283
|
+
*/
|
|
284
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
285
|
+
} | undefined
|
|
286
|
+
): Promise<PdfDocument> {
|
|
287
|
+
return z.function()
|
|
288
|
+
.args(
|
|
289
|
+
stringSchema,
|
|
290
|
+
z.object({
|
|
291
|
+
renderOptions: chromePdfRenderOptionsSchema.optional(),
|
|
292
|
+
}).optional()
|
|
293
|
+
)
|
|
294
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
295
|
+
.implement(this.internal_fromHtml.bind(this))
|
|
296
|
+
(htmlStringOrHtmlFilePath, options);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Converts multiple image files to a PDF document. Each image creates 1 page which matches the image
|
|
301
|
+
* dimensions. The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize.
|
|
302
|
+
* Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.
|
|
303
|
+
* @param images The image file path name(s) or {@link ImageBuffer} object(s)
|
|
304
|
+
* @param options including {@link ImageToPdfOptions}
|
|
305
|
+
*/
|
|
306
|
+
public static async fromImage(
|
|
307
|
+
images: ImageFilePath | ImageFilePath[] | ImageBuffer | ImageBuffer[],
|
|
308
|
+
options?: {
|
|
309
|
+
/**
|
|
310
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
311
|
+
* @default undefined
|
|
312
|
+
*/
|
|
313
|
+
imageToPdfOptions?: ImageToPdfOptions | undefined;
|
|
314
|
+
}
|
|
315
|
+
): Promise<PdfDocument> {
|
|
316
|
+
return z.function()
|
|
317
|
+
.args(
|
|
318
|
+
z.union([imageFilePathSchema, z.array(imageFilePathSchema), imageBufferSchema, z.array(imageBufferSchema)]),
|
|
319
|
+
z.object({
|
|
320
|
+
imageToPdfOptions: imageToPdfOptionsSchema.optional(),
|
|
321
|
+
}).optional()
|
|
322
|
+
)
|
|
323
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
324
|
+
.implement(this.internal_fromImage.bind(this))
|
|
325
|
+
(images, options);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Static method that joins (concatenates) multiple PDF documents together into one compiled PDF document.
|
|
330
|
+
* If the PDF contains form fields the form field in the resulting PDF's name will be appended with '_{index}' e.g. 'Name' will be 'Name_0'
|
|
331
|
+
* @param pdfs array of PDF
|
|
332
|
+
*/
|
|
333
|
+
public static async mergePdf(pdfs: PdfInput[]): Promise<PdfDocument> {
|
|
334
|
+
return z.function()
|
|
335
|
+
.args(
|
|
336
|
+
z.array(pdfInputSchema)
|
|
337
|
+
)
|
|
338
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
339
|
+
.implement(this.internal_mergePdf.bind(this))
|
|
340
|
+
(pdfs);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Saves the PdfDocument to a file.
|
|
345
|
+
* @param filePath Target file path
|
|
346
|
+
* @param saveOptions see {@link SaveOptions}
|
|
347
|
+
*/
|
|
348
|
+
public saveAs(filePath: string, saveOptions?: SaveOptions | undefined): Promise<void> {
|
|
349
|
+
return z.function()
|
|
350
|
+
.args(
|
|
351
|
+
stringSchema,
|
|
352
|
+
saveOptionsSchema.optional()
|
|
353
|
+
)
|
|
354
|
+
.returns(z.promise(z.void()))
|
|
355
|
+
.implement(this.internal_saveAs.bind(this))
|
|
356
|
+
(filePath, saveOptions);
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Saves the PdfDocument to a binary (Buffer)
|
|
361
|
+
* @param saveOptions see {@link SaveOptions}
|
|
362
|
+
*/
|
|
363
|
+
public async saveAsBuffer(saveOptions?: SaveOptions | undefined): Promise<Buffer> {
|
|
364
|
+
return z.function()
|
|
365
|
+
.args(
|
|
366
|
+
saveOptionsSchema.optional()
|
|
367
|
+
)
|
|
368
|
+
.returns(z.promise(bufferSchema))
|
|
369
|
+
.implement(this.internal_saveAsBuffer.bind(this))
|
|
370
|
+
(saveOptions);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
//#endregion
|
|
374
|
+
|
|
375
|
+
//#region compress
|
|
376
|
+
/**
|
|
377
|
+
* Compress existing PDF images using JPG encoding and the specified settings.
|
|
378
|
+
* @deprecated Use {@link compressAndSaveAs}, {@link compressPdfToBytes}, or {@link compressPdfToStream} instead for better compression results.
|
|
379
|
+
* @param imageQuality Quality (1 - 100) to use during compression
|
|
380
|
+
* @param scaleToVisibleSize Scale down the image resolution according to its visible size in the PDF document
|
|
381
|
+
*/
|
|
382
|
+
public async compressSize(
|
|
383
|
+
imageQuality: number,
|
|
384
|
+
scaleToVisibleSize = false
|
|
385
|
+
): Promise<void> {
|
|
386
|
+
return await z.function()
|
|
387
|
+
.args(
|
|
388
|
+
numberSchema,
|
|
389
|
+
booleanSchema.optional()
|
|
390
|
+
)
|
|
391
|
+
.returns(z.promise(z.void()))
|
|
392
|
+
.implement(this.internal_compressSize.bind(this))
|
|
393
|
+
(imageQuality, scaleToVisibleSize);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Remove document struct tree information which describes the logical layout of the document.
|
|
398
|
+
* Removing the "structure tree" can significantly reduce the disk space used by the document.
|
|
399
|
+
* Removing the "structure tree" of a complicated document can negatively impact text selection.
|
|
400
|
+
*/
|
|
401
|
+
public async compressStructTree(): Promise<void> {
|
|
402
|
+
return this.internal_compressStructTree()
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Compress the PDF and return the result as a Buffer (byte array).
|
|
407
|
+
* Uses QPdf compression which can significantly reduce file size.
|
|
408
|
+
* @param imageQuality Optional JPEG quality (1-100) for image compression. If omitted, default compression is applied.
|
|
409
|
+
* @returns A Promise resolving to a Buffer containing the compressed PDF bytes.
|
|
410
|
+
*/
|
|
411
|
+
public async compressPdfToBytes(
|
|
412
|
+
imageQuality?: number
|
|
413
|
+
): Promise<Buffer> {
|
|
414
|
+
return await z.function()
|
|
415
|
+
.args(
|
|
416
|
+
numberSchema.optional()
|
|
417
|
+
)
|
|
418
|
+
.returns(z.promise(z.instanceof(Buffer)))
|
|
419
|
+
.implement(this.internal_compressPdfToBytes.bind(this))
|
|
420
|
+
(imageQuality);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
/**
|
|
424
|
+
* Compress the PDF and return the result as a Readable stream.
|
|
425
|
+
* Uses QPdf compression which can significantly reduce file size.
|
|
426
|
+
* Useful for piping directly to file streams or HTTP responses without buffering the entire PDF in memory.
|
|
427
|
+
* @param imageQuality Optional JPEG quality (1-100) for image compression. If omitted, default compression is applied.
|
|
428
|
+
* @returns A Promise resolving to a Readable stream of the compressed PDF bytes.
|
|
429
|
+
*/
|
|
430
|
+
public async compressPdfToStream(
|
|
431
|
+
imageQuality?: number
|
|
432
|
+
): Promise<Readable> {
|
|
433
|
+
return await z.function()
|
|
434
|
+
.args(
|
|
435
|
+
numberSchema.optional()
|
|
436
|
+
)
|
|
437
|
+
.returns(z.promise(z.any()))
|
|
438
|
+
.implement(this.internal_compressPdfToStream.bind(this))
|
|
439
|
+
(imageQuality);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Compress the PDF and save the result directly to a file.
|
|
444
|
+
* Uses QPdf compression which can significantly reduce file size.
|
|
445
|
+
* @param filePath The output file path to save the compressed PDF.
|
|
446
|
+
* @param imageQuality Optional JPEG quality (1-100) for image compression. If omitted, default compression is applied.
|
|
447
|
+
*/
|
|
448
|
+
public async compressAndSaveAs(
|
|
449
|
+
filePath: string,
|
|
450
|
+
imageQuality?: number
|
|
451
|
+
): Promise<void> {
|
|
452
|
+
return await z.function()
|
|
453
|
+
.args(
|
|
454
|
+
stringSchema,
|
|
455
|
+
numberSchema.optional()
|
|
456
|
+
)
|
|
457
|
+
.returns(z.promise(z.void()))
|
|
458
|
+
.implement(this.internal_compressAndSaveAs.bind(this))
|
|
459
|
+
(filePath, imageQuality);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
//#endregion
|
|
463
|
+
|
|
464
|
+
//#region page
|
|
465
|
+
/**
|
|
466
|
+
* Gets information of all pages in the PdfDocument
|
|
467
|
+
*/
|
|
468
|
+
public async getPagesInfo(): Promise<PageInfo[]> {
|
|
469
|
+
return this.internal_getPagesInfo()
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
/**
|
|
473
|
+
* Gets the number of pages in the PdfDocument.
|
|
474
|
+
*/
|
|
475
|
+
public async getPageCount(): Promise<number> {
|
|
476
|
+
return this.internal_getPageCount()
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/**
|
|
480
|
+
* Set the page orientation.
|
|
481
|
+
* @param pageRotation see {@link PageRotation}
|
|
482
|
+
* @param options including {@link PdfPageSelection}
|
|
483
|
+
*/
|
|
484
|
+
public async setRotation(
|
|
485
|
+
pageRotation: PageRotation,
|
|
486
|
+
options?: {
|
|
487
|
+
/**
|
|
488
|
+
* @default "all"
|
|
489
|
+
*/
|
|
490
|
+
pdfPageSelection?: PdfPageSelection | undefined;
|
|
491
|
+
} | undefined
|
|
492
|
+
) {
|
|
493
|
+
return z.function()
|
|
494
|
+
.args(
|
|
495
|
+
pageRotationSchema,
|
|
496
|
+
z.object({pdfPageSelection: pdfPageSelectionSchema.optional()}).optional()
|
|
497
|
+
)
|
|
498
|
+
.returns(z.promise(z.void()))
|
|
499
|
+
.implement(this.internal_setRotation.bind(this))
|
|
500
|
+
(pageRotation, options);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Resize a page to the specified dimensions
|
|
505
|
+
* @param newSize {@link PdfPaperSize}
|
|
506
|
+
* @param options including {@link PdfPageSelection}
|
|
507
|
+
*/
|
|
508
|
+
public async resize(
|
|
509
|
+
newSize: PdfPaperSize,
|
|
510
|
+
options?: {
|
|
511
|
+
/**
|
|
512
|
+
* @default "all"
|
|
513
|
+
*/
|
|
514
|
+
pdfPageSelection?: PdfPageSelection | undefined;
|
|
515
|
+
} | undefined
|
|
516
|
+
): Promise<void> {
|
|
517
|
+
return z.function()
|
|
518
|
+
.args(
|
|
519
|
+
pdfPaperSizeSchema,
|
|
520
|
+
z.object({pdfPageSelection: pdfPageSelectionSchema.optional()}).optional()
|
|
521
|
+
)
|
|
522
|
+
.returns(z.promise(z.void()))
|
|
523
|
+
.implement(this.internal_resize.bind(this))
|
|
524
|
+
(newSize, options);
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Adds another PDF to the beginning of the current PdfDocument
|
|
529
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
530
|
+
* @param fromPdfDocument PdfDocument to prepend
|
|
531
|
+
*/
|
|
532
|
+
public async prependAnotherPdf(
|
|
533
|
+
fromPdfDocument: PdfDocument
|
|
534
|
+
): Promise<void> {
|
|
535
|
+
return z.function()
|
|
536
|
+
.args(pdfDocumentSchema)
|
|
537
|
+
.returns(z.promise(z.void()))
|
|
538
|
+
.implement(this.internal_prependAnotherPdf.bind(this))
|
|
539
|
+
(fromPdfDocument);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
/**
|
|
543
|
+
* Appends another PDF to the end of the current <see cref="PdfDocument"/>
|
|
544
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
545
|
+
* @param fromPdfDocument PdfDocument to Append
|
|
546
|
+
*/
|
|
547
|
+
public async appendAnotherPdf(fromPdfDocument: PdfDocument): Promise<void> {
|
|
548
|
+
return z.function()
|
|
549
|
+
.args(pdfDocumentSchema)
|
|
550
|
+
.returns(z.promise(z.void()))
|
|
551
|
+
.implement(this.internal_appendAnotherPdf.bind(this))
|
|
552
|
+
(fromPdfDocument);
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
/**
|
|
556
|
+
* Inserts another PDF into the current PdfDocument, starting at a given Page Index.
|
|
557
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
558
|
+
* @param fromPdfDocument Another PdfDocument
|
|
559
|
+
* @param insertAtPageIndex Index at which to insert the new content. Note: Page 1 has index 0...
|
|
560
|
+
*/
|
|
561
|
+
public async insertPagesFromAnotherPdf(
|
|
562
|
+
fromPdfDocument: PdfDocument,
|
|
563
|
+
insertAtPageIndex: number
|
|
564
|
+
): Promise<void> {
|
|
565
|
+
return z.function()
|
|
566
|
+
.args(pdfDocumentSchema, numberSchema.describe("insertAtPageIndex: number"))
|
|
567
|
+
.returns(z.promise(z.void()))
|
|
568
|
+
.implement(this.internal_insertPagesFromAnotherPdf.bind(this))
|
|
569
|
+
(fromPdfDocument, insertAtPageIndex);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Removes a range of pages from the PDF
|
|
574
|
+
* @param pages pages to remove
|
|
575
|
+
*/
|
|
576
|
+
public async removePage(pages: PdfPageSelection): Promise<void> {
|
|
577
|
+
return z.function()
|
|
578
|
+
.args(pdfPageSelectionSchema)
|
|
579
|
+
.returns(z.promise(z.void()))
|
|
580
|
+
.implement(this.internal_removePage.bind(this))
|
|
581
|
+
(pages);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* Creates a new PDF by copying a range of pages from this {@link PdfDocument}.
|
|
586
|
+
* @param pages pages to copy (default "all")
|
|
587
|
+
*/
|
|
588
|
+
public async duplicate(
|
|
589
|
+
pages: PdfPageSelection = "all"
|
|
590
|
+
): Promise<PdfDocument> {
|
|
591
|
+
return z.function()
|
|
592
|
+
.args(pdfPageSelectionSchema)
|
|
593
|
+
.returns(z.promise(pdfDocumentSchema))
|
|
594
|
+
.implement(this.internal_duplicate.bind(this))
|
|
595
|
+
(pages);
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
//#endregion
|
|
599
|
+
|
|
600
|
+
//#region image
|
|
601
|
+
/**
|
|
602
|
+
* Finds all embedded Images from within a specified pages in the PDF and returns them as Buffer
|
|
603
|
+
* @param options including {@link PdfPageSelection}
|
|
604
|
+
*/
|
|
605
|
+
public async extractRawImages(options?: {
|
|
606
|
+
/**
|
|
607
|
+
* @default "all"
|
|
608
|
+
*/
|
|
609
|
+
fromPages?: PdfPageSelection;
|
|
610
|
+
} | undefined): Promise<Buffer[]> {
|
|
611
|
+
return z.function()
|
|
612
|
+
.args(
|
|
613
|
+
z.object({fromPages: pdfPageSelectionSchema.optional()}).optional()
|
|
614
|
+
)
|
|
615
|
+
.returns(z.promise(bufferArraySchema))
|
|
616
|
+
.implement(this.internal_extractRawImages.bind(this))
|
|
617
|
+
(options);
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
/**
|
|
621
|
+
* Renders the PDF and exports image Files in convenient formats. 1 image file is created for each
|
|
622
|
+
* page.
|
|
623
|
+
*
|
|
624
|
+
* @param options including {@link PdfPageSelection} {@link ImageType}
|
|
625
|
+
*
|
|
626
|
+
* @return array of images as Buffer[]
|
|
627
|
+
*/
|
|
628
|
+
public async rasterizeToImageBuffers(options?: {
|
|
629
|
+
/**
|
|
630
|
+
* @default "all"
|
|
631
|
+
*/
|
|
632
|
+
fromPages?: PdfPageSelection | undefined;
|
|
633
|
+
/**
|
|
634
|
+
* @default {@link ImageType.PNG}
|
|
635
|
+
*/
|
|
636
|
+
imageType?: ImageType | undefined;
|
|
637
|
+
} | undefined): Promise<Buffer[]> {
|
|
638
|
+
return z.function()
|
|
639
|
+
.args(
|
|
640
|
+
z.object({
|
|
641
|
+
fromPages: pdfPageSelectionSchema.optional(),
|
|
642
|
+
imageType: imageTypeSchema.optional()
|
|
643
|
+
}).optional()
|
|
644
|
+
)
|
|
645
|
+
.returns(z.promise(bufferArraySchema))
|
|
646
|
+
.implement(this.internal_rasterizeToImageBuffers.bind(this))
|
|
647
|
+
(options);
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* Renders the PDF and exports image Files in convenient formats. 1 image file is created for each
|
|
652
|
+
* page. Running number will append output file path.
|
|
653
|
+
*
|
|
654
|
+
* @param filePath output file path.
|
|
655
|
+
* @param options including {@link PdfPageSelection} {@link ImageType}
|
|
656
|
+
*
|
|
657
|
+
* @return array of images file name as string[]
|
|
658
|
+
*/
|
|
659
|
+
public async rasterizeToImageFiles(
|
|
660
|
+
filePath: string,
|
|
661
|
+
options?: {
|
|
662
|
+
/**
|
|
663
|
+
* @default "all"
|
|
664
|
+
*/
|
|
665
|
+
fromPages?: PdfPageSelection | undefined;
|
|
666
|
+
/**
|
|
667
|
+
* @default {@link ImageType.PNG}
|
|
668
|
+
*/
|
|
669
|
+
type?: ImageType | undefined;
|
|
670
|
+
} | undefined
|
|
671
|
+
): Promise<string[]> {
|
|
672
|
+
return z.function()
|
|
673
|
+
.args(
|
|
674
|
+
filePathSchema,
|
|
675
|
+
z.object({
|
|
676
|
+
fromPages: pdfPageSelectionSchema.optional(),
|
|
677
|
+
type: imageTypeSchema.optional()
|
|
678
|
+
}).optional()
|
|
679
|
+
)
|
|
680
|
+
.returns(z.promise(stringArraySchema))
|
|
681
|
+
.implement(this.internal_rasterizeToImageFiles.bind(this))
|
|
682
|
+
(filePath, options);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
//#endregion
|
|
686
|
+
|
|
687
|
+
//#region text
|
|
688
|
+
/**
|
|
689
|
+
* Replace the specified old text with new text on a given page
|
|
690
|
+
* @param oldText Old text to remove
|
|
691
|
+
* @param newText New text to add
|
|
692
|
+
* @param onPages Page index to search for old text to replace (default "all")
|
|
693
|
+
*/
|
|
694
|
+
public async replaceText(
|
|
695
|
+
oldText: string,
|
|
696
|
+
newText: string,
|
|
697
|
+
onPages?: PdfPageSelection | undefined
|
|
698
|
+
): Promise<void> {
|
|
699
|
+
return z.function()
|
|
700
|
+
.args(
|
|
701
|
+
z.string({description: "oldText: string"}),
|
|
702
|
+
z.string({description: "newText: string"}),
|
|
703
|
+
pdfPageSelectionSchema.optional())
|
|
704
|
+
.returns(z.promise(z.void()))
|
|
705
|
+
.implement(this.internal_replaceText.bind(this))
|
|
706
|
+
(oldText, newText, onPages);
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
public async extractText(
|
|
710
|
+
onPages?: PdfPageSelection | undefined
|
|
711
|
+
): Promise<string> {
|
|
712
|
+
return z.function()
|
|
713
|
+
.args(pdfPageSelectionSchema.optional())
|
|
714
|
+
.returns(z.promise(z.string()))
|
|
715
|
+
.implement(this.internal_extractText.bind(this))
|
|
716
|
+
(onPages);
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
//#endregion
|
|
720
|
+
|
|
721
|
+
//#region pdfA
|
|
722
|
+
/**
|
|
723
|
+
* Convert the current document into the specified PDF-A standard format
|
|
724
|
+
* @param pdfaVersion The PDF/A version to convert to (default: PdfA3b)
|
|
725
|
+
* @param customICC (Optional) Custom color profile file path
|
|
726
|
+
*/
|
|
727
|
+
public async convertToPdfA(pdfaVersion: PdfAVersions = PdfAVersions.PdfA3b, customICC?: string | undefined): Promise<void> {
|
|
728
|
+
return z.function()
|
|
729
|
+
.args(
|
|
730
|
+
z.nativeEnum(PdfAVersions, {description: "pdfaVersion: PdfAVersions"}),
|
|
731
|
+
z.string({description: "customICC: string"}).optional()
|
|
732
|
+
)
|
|
733
|
+
.returns(z.promise(z.void()))
|
|
734
|
+
.implement(this.internal_convertToPdfA.bind(this))
|
|
735
|
+
(pdfaVersion, customICC);
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
// TODO: Re-enable once IronPdfEngine handler for Pdfium_ConvertToPdfUAForScreenReader
|
|
739
|
+
// is fixed to call HtmlHelper.HtmlStructTreeDOM() and ConvertToPdfUAForScreenReader().
|
|
740
|
+
// Currently the engine handler ignores the HTML and falls back to basic ConvertToPdfUA,
|
|
741
|
+
// producing a flat tag tree instead of proper semantic structure.
|
|
742
|
+
// See: IronPdfServiceHandler.cs:97-108
|
|
743
|
+
//
|
|
744
|
+
// public static async fromHtmlAsPdfUA(
|
|
745
|
+
// html: string,
|
|
746
|
+
// naturalLanguages: NaturalLanguages = NaturalLanguages.English,
|
|
747
|
+
// options?: {
|
|
748
|
+
// renderOptions?: ChromePdfRenderOptions | undefined;
|
|
749
|
+
// } | undefined
|
|
750
|
+
// ): Promise<PdfDocument> {
|
|
751
|
+
// const pdf = await PdfDocument.fromHtml(html, options);
|
|
752
|
+
// await toPdfUAForScreenReader(await pdf.internal_getId(), html, naturalLanguages);
|
|
753
|
+
// return pdf;
|
|
754
|
+
// }
|
|
755
|
+
|
|
756
|
+
/**
|
|
757
|
+
* Convert the current document into the specified PDF/UA standard format
|
|
758
|
+
*/
|
|
759
|
+
public async convertToPdfUA(naturalLanguages: NaturalLanguages, pdfUaVersion: PdfUAVersions = PdfUAVersions.PdfUA1): Promise<void> {
|
|
760
|
+
return this.internal_convertToPdfUA(naturalLanguages, pdfUaVersion)
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
//#endregion
|
|
764
|
+
|
|
765
|
+
//#region metadata
|
|
766
|
+
/**
|
|
767
|
+
* Gets a Map<string, string> of metadata properties
|
|
768
|
+
*/
|
|
769
|
+
public async getMetadata(): Promise<Map<string, string>> {
|
|
770
|
+
return this.internal_getMetadata()
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
/**
|
|
774
|
+
* Add or Update a single metadata property
|
|
775
|
+
* @param key
|
|
776
|
+
* @param value
|
|
777
|
+
*/
|
|
778
|
+
public async addOrUpdateMetadata(
|
|
779
|
+
key: string,
|
|
780
|
+
value: string
|
|
781
|
+
): Promise<void> {
|
|
782
|
+
return z.function()
|
|
783
|
+
.args(z.string({description: "key: string"}), z.string({description: "value: string"}))
|
|
784
|
+
.returns(z.promise(z.void()))
|
|
785
|
+
.implement(this.internal_addOrUpdateMetadata.bind(this))
|
|
786
|
+
(key, value);
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
/**
|
|
790
|
+
* Remove a single metadata property
|
|
791
|
+
* @param key
|
|
792
|
+
*/
|
|
793
|
+
public async removeMetadata(key: string): Promise<void> {
|
|
794
|
+
return z.function()
|
|
795
|
+
.args(z.string({description: "key: string"}))
|
|
796
|
+
.returns(z.promise(z.void()))
|
|
797
|
+
.implement(this.internal_removeMetadata.bind(this))
|
|
798
|
+
(key);
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* Sets a whole metadata properties Map<string, string> (override all the metadata property)
|
|
803
|
+
* @param newMetadataDictionary new metadata properties Map<string, string>
|
|
804
|
+
*/
|
|
805
|
+
public async overrideMetadata(
|
|
806
|
+
newMetadataDictionary: Map<string, string>
|
|
807
|
+
): Promise<void> {
|
|
808
|
+
return z.function()
|
|
809
|
+
.args(mapStringSchema)
|
|
810
|
+
.returns(z.promise(z.void()))
|
|
811
|
+
.implement(this.internal_overrideMetadata.bind(this))
|
|
812
|
+
(newMetadataDictionary);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
//#endregion
|
|
816
|
+
|
|
817
|
+
//#region signing
|
|
818
|
+
/**
|
|
819
|
+
* Sign PDF with digital signature certificate.
|
|
820
|
+
* Note that the PDF will not be fully signed until Saved
|
|
821
|
+
* using {@link saveAs} or {@link saveAsBuffer}
|
|
822
|
+
*
|
|
823
|
+
* Multiple certificates may be used.
|
|
824
|
+
* @param signature see {@link DigitalSignature}
|
|
825
|
+
*/
|
|
826
|
+
public async signDigitalSignature(signature: DigitalSignature) {
|
|
827
|
+
return z.function()
|
|
828
|
+
.args(digitalSignatureSchema)
|
|
829
|
+
.returns(z.promise(z.void()))
|
|
830
|
+
.implement(this.internal_signDigitalSignature.bind(this))
|
|
831
|
+
(signature);
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/**
|
|
835
|
+
* Check if PdfDocument was signed or not
|
|
836
|
+
*/
|
|
837
|
+
public async isSigned(): Promise<boolean> {
|
|
838
|
+
return this.internal_isSigned()
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
/**
|
|
842
|
+
* Count the number signature that signed to this PdfDocument
|
|
843
|
+
*/
|
|
844
|
+
public async signatureCount(): Promise<number> {
|
|
845
|
+
return this.internal_signatureCount()
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
/**
|
|
849
|
+
* Get all verified digital signatures from this PdfDocument.
|
|
850
|
+
* Returns details including signature name, signer contact, reason, location, date, and validity.
|
|
851
|
+
* @returns A Promise resolving to an array of {@link VerifiedSignature} objects.
|
|
852
|
+
*/
|
|
853
|
+
public async getVerifiedSignatures(): Promise<VerifiedSignature[]> {
|
|
854
|
+
return this.internal_getVerifiedSignatures()
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
//#endregion
|
|
858
|
+
|
|
859
|
+
//#region header/footer (affix)
|
|
860
|
+
/**
|
|
861
|
+
* Apply page header on top of an existing Pdf.
|
|
862
|
+
* @param header {@link TextAffix}
|
|
863
|
+
* @param toPages {@link PdfPageSelection}
|
|
864
|
+
*/
|
|
865
|
+
public async addTextHeader(
|
|
866
|
+
header: TextAffix,
|
|
867
|
+
toPages?: PdfPageSelection | undefined
|
|
868
|
+
): Promise<void> {
|
|
869
|
+
return z.function()
|
|
870
|
+
.args(textAffixSchema, pdfPageSelectionSchema.optional())
|
|
871
|
+
.returns(z.promise(z.void()))
|
|
872
|
+
.implement(this.internal_addTextHeader.bind(this))
|
|
873
|
+
(header, toPages);
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
/**
|
|
877
|
+
* Apply page footer on top of an existing Pdf.
|
|
878
|
+
* @param footer {@link TextAffix}
|
|
879
|
+
* @param toPages {@link PdfPageSelection}
|
|
880
|
+
*/
|
|
881
|
+
public async addTextFooter(
|
|
882
|
+
footer: TextAffix,
|
|
883
|
+
toPages?: PdfPageSelection | undefined
|
|
884
|
+
): Promise<void> {
|
|
885
|
+
return z.function()
|
|
886
|
+
.args(textAffixSchema, pdfPageSelectionSchema.optional())
|
|
887
|
+
.returns(z.promise(z.void()))
|
|
888
|
+
.implement(this.internal_addTextFooter.bind(this))
|
|
889
|
+
(footer, toPages);
|
|
890
|
+
}
|
|
891
|
+
|
|
892
|
+
/**
|
|
893
|
+
* Apply HTML header on top of an existing Pdf.
|
|
894
|
+
* @param header {@link HtmlAffix}
|
|
895
|
+
* @param toPages {@link PdfPageSelection}
|
|
896
|
+
*/
|
|
897
|
+
public async addHtmlHeader(
|
|
898
|
+
header: HtmlAffix,
|
|
899
|
+
toPages?: PdfPageSelection | undefined
|
|
900
|
+
): Promise<void> {
|
|
901
|
+
return z.function()
|
|
902
|
+
.args(htmlAffixSchema, pdfPageSelectionSchema.optional())
|
|
903
|
+
.returns(z.promise(z.void()))
|
|
904
|
+
.implement(this.internal_addHtmlHeader.bind(this))
|
|
905
|
+
(header, toPages);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
/**
|
|
909
|
+
* Apply HTML footer on top of an existing Pdf.
|
|
910
|
+
* @param footer {@link HtmlAffix}
|
|
911
|
+
* @param toPages {@link PdfPageSelection}
|
|
912
|
+
*/
|
|
913
|
+
public async addHtmlFooter(
|
|
914
|
+
footer: HtmlAffix,
|
|
915
|
+
toPages?: PdfPageSelection | undefined
|
|
916
|
+
): Promise<void> {
|
|
917
|
+
return z.function()
|
|
918
|
+
.args(htmlAffixSchema, pdfPageSelectionSchema.optional())
|
|
919
|
+
.returns(z.promise(z.void()))
|
|
920
|
+
.implement(this.internal_addHtmlFooter.bind(this))
|
|
921
|
+
(footer, toPages);
|
|
922
|
+
}
|
|
923
|
+
|
|
924
|
+
//#endregion
|
|
925
|
+
|
|
926
|
+
//#region stamp
|
|
927
|
+
/**
|
|
928
|
+
* Edits the PDF by applying the HTML's rendered to only selected page(s).
|
|
929
|
+
* @param htmlStringOrHtmlFilePath
|
|
930
|
+
* @param options including {@link HtmlStampOptions} {@link PdfPageSelection}
|
|
931
|
+
*/
|
|
932
|
+
public async stampHtml(
|
|
933
|
+
htmlStringOrHtmlFilePath: HtmlFilePath | HtmlString,
|
|
934
|
+
options?: {
|
|
935
|
+
htmlStampOptions?: HtmlStampOptions | undefined;
|
|
936
|
+
toPages?: PdfPageSelection | undefined;
|
|
937
|
+
} | undefined
|
|
938
|
+
) {
|
|
939
|
+
return z.function()
|
|
940
|
+
.args(z.union([htmlFilePathSchema, htmlStringSchema]), z.object({
|
|
941
|
+
htmlStampOptions: htmlStampOptionsSchema.optional(),
|
|
942
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
943
|
+
}).optional())
|
|
944
|
+
.returns(z.promise(z.void()))
|
|
945
|
+
.implement(this.internal_stampHtml.bind(this))
|
|
946
|
+
(htmlStringOrHtmlFilePath, options);
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
/**
|
|
950
|
+
* Edits the PDF by applying the image to only selected page(s).
|
|
951
|
+
* @param image image file path or image buffer
|
|
952
|
+
* @param options including {@link ImageStampOptions} {@link PdfPageSelection}
|
|
953
|
+
*/
|
|
954
|
+
public async stampImage(
|
|
955
|
+
image: ImageFilePath | ImageBuffer,
|
|
956
|
+
options?: {
|
|
957
|
+
imageStampOptions?: ImageStampOptions | undefined;
|
|
958
|
+
toPages?: PdfPageSelection | undefined;
|
|
959
|
+
} | undefined
|
|
960
|
+
) {
|
|
961
|
+
return z.function()
|
|
962
|
+
.args(z.union([imageFilePathSchema, imageBufferSchema]), z.object({
|
|
963
|
+
imageStampOptions: imageStampOptionsSchema.optional(),
|
|
964
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
965
|
+
}).optional())
|
|
966
|
+
.returns(z.promise(z.void()))
|
|
967
|
+
.implement(this.internal_stampImage.bind(this))
|
|
968
|
+
(image, options);
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
/**
|
|
972
|
+
* Edits the PDF by applying the text to only selected page(s).
|
|
973
|
+
* @param text text to stamp
|
|
974
|
+
* @param options including {@link TextStampOptions} {@link PdfPageSelection}
|
|
975
|
+
*/
|
|
976
|
+
public async stampText(
|
|
977
|
+
text: string,
|
|
978
|
+
options?: {
|
|
979
|
+
textStampOptions?: TextStampOptions | undefined;
|
|
980
|
+
toPages?: PdfPageSelection | undefined;
|
|
981
|
+
} | undefined
|
|
982
|
+
) {
|
|
983
|
+
return z.function()
|
|
984
|
+
.args(stringSchema, z.object({
|
|
985
|
+
textStampOptions: textStampOptionsSchema.optional(),
|
|
986
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
987
|
+
}).optional())
|
|
988
|
+
.returns(z.promise(z.void()))
|
|
989
|
+
.implement(this.internal_stampText.bind(this))
|
|
990
|
+
(text, options);
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
/**
|
|
994
|
+
* Edits the PDF by applying the barcode to only selected page(s).
|
|
995
|
+
* @param barcodeValue barcode
|
|
996
|
+
* @param options including {@link BarcodeType} {@link BarcodeStampOptions} {@link PdfPageSelection}
|
|
997
|
+
*/
|
|
998
|
+
public async stampBarcode(
|
|
999
|
+
barcodeValue: string,
|
|
1000
|
+
options?: {
|
|
1001
|
+
barcodeEncoding: BarcodeType;
|
|
1002
|
+
barcodeStampOptions?: BarcodeStampOptions | undefined;
|
|
1003
|
+
toPages?: PdfPageSelection | undefined;
|
|
1004
|
+
} | undefined
|
|
1005
|
+
) {
|
|
1006
|
+
return z.function()
|
|
1007
|
+
.args(stringSchema, z.object({
|
|
1008
|
+
barcodeEncoding: barcodeTypeSchema,
|
|
1009
|
+
barcodeStampOptions: barcodeStampOptionsSchema.optional(),
|
|
1010
|
+
toPages: pdfPageSelectionSchema.optional()
|
|
1011
|
+
}).optional())
|
|
1012
|
+
.returns(z.promise(z.void()))
|
|
1013
|
+
.implement(this.internal_stampBarcode.bind(this))
|
|
1014
|
+
(barcodeValue, options);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
//#endregion
|
|
1018
|
+
|
|
1019
|
+
//#region background/foreground
|
|
1020
|
+
/**
|
|
1021
|
+
* Adds a background to each page of this PDF. The background is copied from a first page in the
|
|
1022
|
+
* backgroundPdf document.
|
|
1023
|
+
*
|
|
1024
|
+
* @param fromPdf background PDF document
|
|
1025
|
+
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
1026
|
+
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
1027
|
+
*/
|
|
1028
|
+
public async addBackgroundFromAnotherPdf(
|
|
1029
|
+
fromPdf: PdfDocument,
|
|
1030
|
+
sourcePageIndex = 0,
|
|
1031
|
+
applyToPages?: PdfPageSelection | undefined
|
|
1032
|
+
): Promise<void> {
|
|
1033
|
+
return z.function()
|
|
1034
|
+
.args(pdfDocumentSchema, numberSchema, pdfPageSelectionSchema.optional())
|
|
1035
|
+
.returns(z.promise(z.void()))
|
|
1036
|
+
.implement(this.internal_addBackgroundFromAnotherPdf.bind(this))
|
|
1037
|
+
(fromPdf, sourcePageIndex, applyToPages);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
* Adds a foreground to each page of this PDF. The background is copied from a first page in the
|
|
1042
|
+
* backgroundPdf document.
|
|
1043
|
+
*
|
|
1044
|
+
* @param fromPdf foreground PDF document
|
|
1045
|
+
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
1046
|
+
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
1047
|
+
*/
|
|
1048
|
+
public async addForegroundFromAnotherPdf(
|
|
1049
|
+
fromPdf: PdfDocument,
|
|
1050
|
+
sourcePageIndex = 0,
|
|
1051
|
+
applyToPages?: PdfPageSelection | undefined
|
|
1052
|
+
): Promise<void> {
|
|
1053
|
+
return z.function()
|
|
1054
|
+
.args(pdfDocumentSchema, numberSchema, pdfPageSelectionSchema.optional())
|
|
1055
|
+
.returns(z.promise(z.void()))
|
|
1056
|
+
.implement(this.internal_addForegroundFromAnotherPdf.bind(this))
|
|
1057
|
+
(fromPdf, sourcePageIndex, applyToPages);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
//#endregion
|
|
1061
|
+
|
|
1062
|
+
//#region security
|
|
1063
|
+
/**
|
|
1064
|
+
* Removes all user and owner password security for a PDF document. Also disables content
|
|
1065
|
+
* encryption.
|
|
1066
|
+
* If content is encrypted at 128 bit, copy and paste of content, annotations and form editing may be disabled.
|
|
1067
|
+
*/
|
|
1068
|
+
public async removePasswordsAndEncryption(): Promise<void> {
|
|
1069
|
+
return this.internal_removePasswordsAndEncryption()
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* Sets the user password and enables 128Bit encryption of PDF content.
|
|
1074
|
+
* A user password is a password that each user must enter to open or print the PDF document.
|
|
1075
|
+
*/
|
|
1076
|
+
public async setUserPassword(userPassword: string): Promise<void> {
|
|
1077
|
+
return z.function()
|
|
1078
|
+
.args(z.string({description: "userPassword: string"}))
|
|
1079
|
+
.returns(z.promise(z.void()))
|
|
1080
|
+
.implement(this.internal_setUserPassword.bind(this))
|
|
1081
|
+
(userPassword);
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* Sets the owner password and enables 128Bit encryption of PDF content. An owner password is one used to
|
|
1086
|
+
* enable and disable all other security settings. <para>OwnerPassword must be set to a non-empty string
|
|
1087
|
+
* value for {@link PdfPermission.AllowAccessibilityExtractContent} , {@link PdfPermission.AllowAnnotations} ,
|
|
1088
|
+
* {@link PdfPermission.AllowFillForms}, {@link PdfPermission.AllowPrint}, {@link PdfPermission.AllowModify} to be
|
|
1089
|
+
* restricted.
|
|
1090
|
+
*/
|
|
1091
|
+
public async setOwnerPassword(ownerPassword: string): Promise<void> {
|
|
1092
|
+
return z.function()
|
|
1093
|
+
.args(z.string({description: "ownerPassword: string"}))
|
|
1094
|
+
.returns(z.promise(z.void()))
|
|
1095
|
+
.implement(this.internal_setOwnerPassword.bind(this))
|
|
1096
|
+
(ownerPassword);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* Sets the permissions of this PdfDocument
|
|
1101
|
+
* @param permissions see {@link PdfPermission}
|
|
1102
|
+
*/
|
|
1103
|
+
public async setPermission(permissions: PdfPermission): Promise<void> {
|
|
1104
|
+
return z.function()
|
|
1105
|
+
.args(pdfPermissionSchema)
|
|
1106
|
+
.returns(z.promise(z.void()))
|
|
1107
|
+
.implement(this.internal_setPermission.bind(this))
|
|
1108
|
+
(permissions);
|
|
1109
|
+
}
|
|
1110
|
+
|
|
1111
|
+
/**
|
|
1112
|
+
* Gets the current permissions of this PdfDocument
|
|
1113
|
+
* @return {@link PdfPermission}
|
|
1114
|
+
*/
|
|
1115
|
+
public async getPermission(): Promise<PdfPermission> {
|
|
1116
|
+
return this.internal_getPermission()
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
/**
|
|
1120
|
+
* Makes this PDF document read only such that: Content is encrypted at 128 bit. Copy and paste of
|
|
1121
|
+
* content is disallowed. Annotations and form editing are disabled.
|
|
1122
|
+
* @param ownerPassword The owner password for the PDF. A string for owner password is required to enable PDF encryption and
|
|
1123
|
+
* all document security options.
|
|
1124
|
+
*/
|
|
1125
|
+
public async makePdfDocumentReadOnly(ownerPassword: string): Promise<void> {
|
|
1126
|
+
return z.function()
|
|
1127
|
+
.args(z.string({description: "ownerPassword: string"}))
|
|
1128
|
+
.returns(z.promise(z.void()))
|
|
1129
|
+
.implement(this.internal_makePdfDocumentReadOnly.bind(this))
|
|
1130
|
+
(ownerPassword);
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
//#endregion
|
|
1134
|
+
|
|
1135
|
+
//#region close
|
|
1136
|
+
/**
|
|
1137
|
+
* Dispose this PdfDocument object (clean up the resource)
|
|
1138
|
+
* This is necessary to free the memory used by PdfDocument. See {@link cleanUp}
|
|
1139
|
+
* Once this method was called this PdfDocument object no longer usable.
|
|
1140
|
+
*/
|
|
1141
|
+
public async close() {
|
|
1142
|
+
return this.internal_close()
|
|
1143
|
+
}
|
|
1144
|
+
|
|
1145
|
+
//#endregion
|
|
1146
|
+
|
|
1147
|
+
//#region ALL_INTERNAL_STUFF
|
|
1148
|
+
/**
|
|
1149
|
+
* Internal PDF document ID
|
|
1150
|
+
* @private
|
|
1151
|
+
*/
|
|
1152
|
+
private pdfDocumentId?: string | undefined;
|
|
1153
|
+
/**
|
|
1154
|
+
* @private
|
|
1155
|
+
*/
|
|
1156
|
+
private readonly promiseDocumentId?: Promise<string> | undefined;
|
|
1157
|
+
/**
|
|
1158
|
+
* @private
|
|
1159
|
+
*/
|
|
1160
|
+
private pdfPassword?: PdfPassword | undefined;
|
|
1161
|
+
|
|
1162
|
+
/**
|
|
1163
|
+
* Create a PdfDocument object from a {@link PdfInput}
|
|
1164
|
+
* For more specific way to create/open PdfDocument see {@link fromUrl} {@link fromZip} {@link fromHtml} {@link fromImage} {@link open}
|
|
1165
|
+
*
|
|
1166
|
+
* @param pdfInput see {@link PdfInput} (required) (pdfInput is {@link PdfFilePath} or {@link Buffer})
|
|
1167
|
+
* @param password a password to open the PDF required if PDF file was private.
|
|
1168
|
+
* @param trackChanges Optionally track changes to the document (for use with incremental saves)
|
|
1169
|
+
*/
|
|
1170
|
+
constructor(pdfInput?: PdfInput | undefined, password?: PdfPassword | undefined, trackChanges?: ChangeTrackingModes | undefined) {
|
|
1171
|
+
if (pdfInput) {
|
|
1172
|
+
this.pdfDocumentId = undefined;
|
|
1173
|
+
const input = separatePdfInput(pdfInput);
|
|
1174
|
+
switch (input.type) {
|
|
1175
|
+
case "htmlFile":
|
|
1176
|
+
this.promiseDocumentId = renderHtmlFileToPdf(input.htmlFile);
|
|
1177
|
+
break;
|
|
1178
|
+
case "htmlString":
|
|
1179
|
+
this.promiseDocumentId = renderHtmlToPdf(input.htmlString);
|
|
1180
|
+
break;
|
|
1181
|
+
case "zipFile":
|
|
1182
|
+
this.promiseDocumentId = renderHtmlZipToPdf(input.zipFile);
|
|
1183
|
+
break;
|
|
1184
|
+
case "buffer":
|
|
1185
|
+
this.promiseDocumentId = openPdfFileBuffer(
|
|
1186
|
+
input.buffer,
|
|
1187
|
+
{userPassword: password?.userPassword, ownerPassword: password?.ownerPassword, trackChanges: trackChanges}
|
|
1188
|
+
);
|
|
1189
|
+
break;
|
|
1190
|
+
case "pdfFile":
|
|
1191
|
+
this.pdfPassword = password;
|
|
1192
|
+
this.promiseDocumentId = openPdfFileBuffer(
|
|
1193
|
+
fs.readFileSync(input.pdfFile),
|
|
1194
|
+
{userPassword: password?.userPassword, ownerPassword: password?.ownerPassword, trackChanges: trackChanges}
|
|
1195
|
+
);
|
|
1196
|
+
break;
|
|
1197
|
+
case "url":
|
|
1198
|
+
this.promiseDocumentId = renderUrlToPdf(input.url);
|
|
1199
|
+
break;
|
|
1200
|
+
case "pdfDocument":
|
|
1201
|
+
this.pdfDocumentId = input.pdfDocument.pdfDocumentId;
|
|
1202
|
+
this.promiseDocumentId =
|
|
1203
|
+
input.pdfDocument.promiseDocumentId;
|
|
1204
|
+
break;
|
|
1205
|
+
}
|
|
1206
|
+
if (this.pdfDocumentId) {
|
|
1207
|
+
Access.usedDocumentIds.add(this.pdfDocumentId);
|
|
1208
|
+
}
|
|
1209
|
+
this.promiseDocumentId?.then((id) =>
|
|
1210
|
+
Access.usedDocumentIds.add(id)
|
|
1211
|
+
);
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
/**
|
|
1216
|
+
* Dispose this PdfDocument object (clean up the resource)
|
|
1217
|
+
* This is necessary to free the memory used by PdfDocument. See {@link cleanUp}
|
|
1218
|
+
* Once this method was called this PdfDocument object no longer usable.
|
|
1219
|
+
*/
|
|
1220
|
+
private async internal_close() {
|
|
1221
|
+
await disposePdf(await this.internal_getId());
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
/**
|
|
1225
|
+
* @private
|
|
1226
|
+
*/
|
|
1227
|
+
private async internal_getId(): Promise<string> {
|
|
1228
|
+
if (this.pdfDocumentId) {
|
|
1229
|
+
return Promise.resolve(this.pdfDocumentId) ;
|
|
1230
|
+
} else if (this.promiseDocumentId) {
|
|
1231
|
+
this.pdfDocumentId = await this.promiseDocumentId;
|
|
1232
|
+
return Promise.resolve(this.pdfDocumentId);
|
|
1233
|
+
} else {
|
|
1234
|
+
throw new Error("Cannot Get PdfDocumentId");
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
//#region io
|
|
1239
|
+
|
|
1240
|
+
/**
|
|
1241
|
+
* Open or Create a PdfDocument from a {@link PdfInput}
|
|
1242
|
+
* @param pdfInput {@link PdfInput}
|
|
1243
|
+
* @param options including {@link PdfPassword} {@link ChromePdfRenderOptions} {@link HttpLoginCredentials} mainHtmlFile
|
|
1244
|
+
*/
|
|
1245
|
+
private static async internal_open(
|
|
1246
|
+
pdfInput: PdfInput,
|
|
1247
|
+
options?: {
|
|
1248
|
+
/**
|
|
1249
|
+
* required for open a private PDF file
|
|
1250
|
+
* @default undefined
|
|
1251
|
+
*/
|
|
1252
|
+
password?: PdfPassword | undefined;
|
|
1253
|
+
/**
|
|
1254
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
1255
|
+
* @default undefined
|
|
1256
|
+
*/
|
|
1257
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
1258
|
+
/**
|
|
1259
|
+
* Apply httpLoginCredentials if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
1260
|
+
* @default undefined
|
|
1261
|
+
*/
|
|
1262
|
+
httpLoginCredentials?: HttpLoginCredentials | undefined;
|
|
1263
|
+
/**
|
|
1264
|
+
* Apply mainHtmlFile if PdfInput is {@link ZipFilePath}
|
|
1265
|
+
* @default index.html
|
|
1266
|
+
*/
|
|
1267
|
+
mainHtmlFile?: string | undefined;
|
|
1268
|
+
/**
|
|
1269
|
+
* Optionally track changes to the document (for use with incremental saves)
|
|
1270
|
+
* @default {@link ChangeTrackingModes.AutoChangeTracking}
|
|
1271
|
+
*/
|
|
1272
|
+
trackChanges?: ChangeTrackingModes | undefined;
|
|
1273
|
+
// /**
|
|
1274
|
+
// * Apply baseUrl if
|
|
1275
|
+
// * The HTML base URL for which references to external CSS, Javascript and Image files will be relative.
|
|
1276
|
+
// * @default undefined
|
|
1277
|
+
// */
|
|
1278
|
+
// baseUrl ?: string | undefined; //not supported
|
|
1279
|
+
} | undefined
|
|
1280
|
+
): Promise<PdfDocument> {
|
|
1281
|
+
if (pdfInput) {
|
|
1282
|
+
const input = separatePdfInput(pdfInput);
|
|
1283
|
+
switch (input.type) {
|
|
1284
|
+
case "htmlFile":
|
|
1285
|
+
const newHtmlFilePdf = new PdfDocument();
|
|
1286
|
+
newHtmlFilePdf.pdfDocumentId = await renderHtmlFileToPdf(
|
|
1287
|
+
input.htmlFile,
|
|
1288
|
+
options?.renderOptions
|
|
1289
|
+
);
|
|
1290
|
+
return newHtmlFilePdf;
|
|
1291
|
+
case "htmlString":
|
|
1292
|
+
const newHtmlStringPdf = new PdfDocument();
|
|
1293
|
+
newHtmlStringPdf.pdfDocumentId = await renderHtmlToPdf(
|
|
1294
|
+
input.htmlString,
|
|
1295
|
+
options?.renderOptions
|
|
1296
|
+
);
|
|
1297
|
+
return newHtmlStringPdf;
|
|
1298
|
+
case "zipFile":
|
|
1299
|
+
const newZipFilePdf = new PdfDocument();
|
|
1300
|
+
newZipFilePdf.pdfDocumentId = await renderHtmlZipToPdf(
|
|
1301
|
+
input.zipFile,
|
|
1302
|
+
options?.mainHtmlFile,
|
|
1303
|
+
options?.renderOptions
|
|
1304
|
+
);
|
|
1305
|
+
return newZipFilePdf;
|
|
1306
|
+
case "buffer":
|
|
1307
|
+
const newBufferPdf = new PdfDocument(
|
|
1308
|
+
undefined,
|
|
1309
|
+
options?.password,
|
|
1310
|
+
options?.trackChanges
|
|
1311
|
+
);
|
|
1312
|
+
newBufferPdf.pdfDocumentId = await openPdfFileBuffer(
|
|
1313
|
+
input.buffer,{
|
|
1314
|
+
userPassword: options?.password?.userPassword,
|
|
1315
|
+
ownerPassword: options?.password?.ownerPassword,
|
|
1316
|
+
trackChanges: options?.trackChanges
|
|
1317
|
+
}
|
|
1318
|
+
);
|
|
1319
|
+
return newBufferPdf;
|
|
1320
|
+
case "pdfFile":
|
|
1321
|
+
const newPdfFilePdf = new PdfDocument(
|
|
1322
|
+
undefined,
|
|
1323
|
+
options?.password
|
|
1324
|
+
);
|
|
1325
|
+
newPdfFilePdf.pdfDocumentId = await openPdfFileBuffer(
|
|
1326
|
+
fs.readFileSync(input.pdfFile),
|
|
1327
|
+
{
|
|
1328
|
+
userPassword: options?.password?.userPassword,
|
|
1329
|
+
ownerPassword: options?.password?.ownerPassword,
|
|
1330
|
+
trackChanges: options?.trackChanges
|
|
1331
|
+
}
|
|
1332
|
+
);
|
|
1333
|
+
|
|
1334
|
+
return newPdfFilePdf;
|
|
1335
|
+
case "url":
|
|
1336
|
+
const newUrlPdf = new PdfDocument();
|
|
1337
|
+
newUrlPdf.pdfDocumentId = await renderUrlToPdf(input.url, {
|
|
1338
|
+
renderOptions: options?.renderOptions,
|
|
1339
|
+
httpLoginCredentials: options?.httpLoginCredentials,
|
|
1340
|
+
});
|
|
1341
|
+
return newUrlPdf;
|
|
1342
|
+
case "pdfDocument":
|
|
1343
|
+
return Promise.resolve(input.pdfDocument);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
throw new Error(`cannot create PdfDocument object from ${pdfInput}`);
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
/**
|
|
1350
|
+
* Open a PdfDocument from .pdf file
|
|
1351
|
+
* @param pdfFilePath A path to .pdf file
|
|
1352
|
+
* @param Optionally track changes to the document (for use with incremental saves)
|
|
1353
|
+
*/
|
|
1354
|
+
private static async internal_fromFile(
|
|
1355
|
+
pdfFilePath: string,
|
|
1356
|
+
trackChanges?: ChangeTrackingModes | undefined
|
|
1357
|
+
): Promise<PdfDocument> {
|
|
1358
|
+
return this.internal_open(pdfFilePath, {trackChanges: trackChanges});
|
|
1359
|
+
}
|
|
1360
|
+
|
|
1361
|
+
/**
|
|
1362
|
+
* Create a PdfDocument from an Url
|
|
1363
|
+
* @param url A website Url
|
|
1364
|
+
* @param options including {@link ChromePdfRenderOptions}
|
|
1365
|
+
*/
|
|
1366
|
+
private static async internal_fromUrl(
|
|
1367
|
+
url: URL | string,
|
|
1368
|
+
options?: {
|
|
1369
|
+
/**
|
|
1370
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
1371
|
+
* @default undefined
|
|
1372
|
+
*/
|
|
1373
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
1374
|
+
} | undefined
|
|
1375
|
+
): Promise<PdfDocument> {
|
|
1376
|
+
return this.internal_open(url, options);
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Creates a PDF file from a local Zip file, and returns it as a {@link PdfDocument}.
|
|
1381
|
+
* IronPDF is a W3C standards compliant HTML rendering based on Google's Chromium browser.
|
|
1382
|
+
* If your output PDF does not look as expected:
|
|
1383
|
+
*
|
|
1384
|
+
* - Validate your HTML file using https://validator.w3.org/ & CSS https://jigsaw.w3.org/css-validator/
|
|
1385
|
+
*
|
|
1386
|
+
* - To debug HTML, view the file in Chrome web browser's print preview which will work almost exactly as IronPDF.
|
|
1387
|
+
*
|
|
1388
|
+
* - Read our detailed documentation on pixel perfect HTML to PDF: https://ironpdf.com/tutorials/pixel-perfect-html-to-pdf/
|
|
1389
|
+
*
|
|
1390
|
+
* @param zipFilePath Path to a Zip to be rendered as a PDF.
|
|
1391
|
+
* @param options including {@link ChromePdfRenderOptions} and `mainHtmlFile` a main .html file default: `index.html`
|
|
1392
|
+
*/
|
|
1393
|
+
private static async internal_fromZip(
|
|
1394
|
+
zipFilePath: string,
|
|
1395
|
+
options?: {
|
|
1396
|
+
/**
|
|
1397
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
1398
|
+
* @default undefined
|
|
1399
|
+
*/
|
|
1400
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
1401
|
+
/**
|
|
1402
|
+
* a main .html file default: `index.html`
|
|
1403
|
+
*/
|
|
1404
|
+
mainHtmlFile?: string | undefined;
|
|
1405
|
+
} | undefined
|
|
1406
|
+
): Promise<PdfDocument> {
|
|
1407
|
+
return this.internal_open(zipFilePath, options);
|
|
1408
|
+
}
|
|
1409
|
+
|
|
1410
|
+
/**
|
|
1411
|
+
* Creates a PDF file from a Html string, and returns it as an {@link PdfDocument} object which can be edited and saved to disk or served on a website.
|
|
1412
|
+
* @param htmlStringOrHtmlFilePath The Html to be rendered as a PDF.
|
|
1413
|
+
* @param options including {@link ChromePdfRenderOptions}
|
|
1414
|
+
*/
|
|
1415
|
+
private static async internal_fromHtml(
|
|
1416
|
+
htmlStringOrHtmlFilePath: string,
|
|
1417
|
+
options?: {
|
|
1418
|
+
/**
|
|
1419
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
1420
|
+
* @default undefined
|
|
1421
|
+
*/
|
|
1422
|
+
renderOptions?: ChromePdfRenderOptions | undefined;
|
|
1423
|
+
} | undefined
|
|
1424
|
+
): Promise<PdfDocument> {
|
|
1425
|
+
return this.internal_open(htmlStringOrHtmlFilePath, options);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
/**
|
|
1429
|
+
* Converts multiple image files to a PDF document. Each image creates 1 page which matches the image
|
|
1430
|
+
* dimensions. The default PaperSize is A4. You can set it via ImageToPdfConverter.PaperSize.
|
|
1431
|
+
* Note: Imaging.ImageBehavior.CropPage will set PaperSize equal to ImageSize.
|
|
1432
|
+
* @param images The image file path name(s) or {@link ImageBuffer} object(s)
|
|
1433
|
+
* @param options including {@link ImageToPdfOptions}
|
|
1434
|
+
*/
|
|
1435
|
+
private static async internal_fromImage(
|
|
1436
|
+
images: ImageFilePath | ImageFilePath[] | ImageBuffer | ImageBuffer[],
|
|
1437
|
+
options?: {
|
|
1438
|
+
/**
|
|
1439
|
+
* Apply renderOptions if PdfInput is a {@link HtmlString} or {@link HtmlFilePath} or {@link ZipFilePath} or {@link Url}}
|
|
1440
|
+
* @default undefined
|
|
1441
|
+
*/
|
|
1442
|
+
imageToPdfOptions?: ImageToPdfOptions | undefined;
|
|
1443
|
+
} | undefined
|
|
1444
|
+
): Promise<PdfDocument> {
|
|
1445
|
+
let temp: Promise<string>;
|
|
1446
|
+
|
|
1447
|
+
if (Array.isArray(images)) {
|
|
1448
|
+
// const imageArray = images as Array<any>;
|
|
1449
|
+
if(images[0]){
|
|
1450
|
+
const t = separateImageBufferOrImagePathInput(images[0]);
|
|
1451
|
+
|
|
1452
|
+
switch (t.type) {
|
|
1453
|
+
case "imageBuffer":
|
|
1454
|
+
temp = renderImagesBufferToPdf(
|
|
1455
|
+
images as Buffer[],
|
|
1456
|
+
options?.imageToPdfOptions
|
|
1457
|
+
);
|
|
1458
|
+
break;
|
|
1459
|
+
case "imageFilePath":
|
|
1460
|
+
temp = renderImagesFilesToPdf(
|
|
1461
|
+
images as string[],
|
|
1462
|
+
options?.imageToPdfOptions
|
|
1463
|
+
);
|
|
1464
|
+
break;
|
|
1465
|
+
}
|
|
1466
|
+
}else{
|
|
1467
|
+
throw new Error("imageToPdf input Array is Empty");
|
|
1468
|
+
}
|
|
1469
|
+
} else {
|
|
1470
|
+
const image = separateImageBufferOrImagePathInput(images);
|
|
1471
|
+
switch (image.type) {
|
|
1472
|
+
case "imageBuffer":
|
|
1473
|
+
temp = renderImagesBufferToPdf(
|
|
1474
|
+
[image.imageBuffer],
|
|
1475
|
+
options?.imageToPdfOptions
|
|
1476
|
+
);
|
|
1477
|
+
break;
|
|
1478
|
+
case "imageFilePath":
|
|
1479
|
+
temp = renderImagesFilesToPdf(
|
|
1480
|
+
[image.imageFilePath],
|
|
1481
|
+
options?.imageToPdfOptions
|
|
1482
|
+
);
|
|
1483
|
+
break;
|
|
1484
|
+
}
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
if (!temp) {
|
|
1488
|
+
throw new Error(`cannot read image: ${images}`);
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
const newUrlPdf = new PdfDocument();
|
|
1492
|
+
newUrlPdf.pdfDocumentId = await temp;
|
|
1493
|
+
return newUrlPdf;
|
|
1494
|
+
}
|
|
1495
|
+
|
|
1496
|
+
/**
|
|
1497
|
+
* Static method that joins (concatenates) multiple PDF documents together into one compiled PDF document.
|
|
1498
|
+
* If the PDF contains form fields the form field in the resulting PDF's name will be appended with '_{index}' e.g. 'Name' will be 'Name_0'
|
|
1499
|
+
* @param pdfs array of PDF
|
|
1500
|
+
*/
|
|
1501
|
+
private static async internal_mergePdf(pdfs: PdfInput[]): Promise<PdfDocument> {
|
|
1502
|
+
const ids = await Promise.all(
|
|
1503
|
+
pdfs.map(async (x) => (await PdfDocument.open(x)).internal_getId())
|
|
1504
|
+
);
|
|
1505
|
+
const newDocId = mergePdfs(ids);
|
|
1506
|
+
const newUrlPdf = new PdfDocument();
|
|
1507
|
+
newUrlPdf.pdfDocumentId = await newDocId;
|
|
1508
|
+
return newUrlPdf;
|
|
1509
|
+
}
|
|
1510
|
+
|
|
1511
|
+
/**
|
|
1512
|
+
* Saves the PdfDocument to a file.
|
|
1513
|
+
* @param filePath Target file path
|
|
1514
|
+
* @param saveOptions see {@link SaveOptions}
|
|
1515
|
+
*/
|
|
1516
|
+
private async internal_saveAs(filePath: string, saveOptions?: SaveOptions | undefined): Promise<void> {
|
|
1517
|
+
return this.internal_saveAsBuffer(saveOptions).then((pdfFileBuffer) => {
|
|
1518
|
+
fs.writeFile(filePath, pdfFileBuffer, "binary", (err) => {
|
|
1519
|
+
if (err) throw err;
|
|
1520
|
+
});
|
|
1521
|
+
});
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
/**
|
|
1525
|
+
* Saves the PdfDocument to a binary (Buffer)
|
|
1526
|
+
* @param saveOptions see {@link SaveOptions}
|
|
1527
|
+
*/
|
|
1528
|
+
private async internal_saveAsBuffer(saveOptions?: SaveOptions | undefined): Promise<Buffer> {
|
|
1529
|
+
return getBinaryData(await this.internal_getId(), saveOptions);
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
//#endregion
|
|
1533
|
+
|
|
1534
|
+
//#region compress
|
|
1535
|
+
/**
|
|
1536
|
+
* Compress existing PDF images using JPG encoding and the specified settings
|
|
1537
|
+
* @param imageQuality Quality (1 - 100) to use during compression
|
|
1538
|
+
* @param scaleToVisibleSize Scale down the image resolution according to its visible size in the PDF document
|
|
1539
|
+
*/
|
|
1540
|
+
private async internal_compressSize(
|
|
1541
|
+
imageQuality: number,
|
|
1542
|
+
scaleToVisibleSize = false
|
|
1543
|
+
): Promise<void> {
|
|
1544
|
+
if (imageQuality < 1 || imageQuality > 100)
|
|
1545
|
+
throw new Error(
|
|
1546
|
+
`Invalid quality specifier (${imageQuality}) when compressing images. Quality must be between 1 and 100.`
|
|
1547
|
+
);
|
|
1548
|
+
return await compressImage(
|
|
1549
|
+
await this.internal_getId(),
|
|
1550
|
+
imageQuality,
|
|
1551
|
+
scaleToVisibleSize
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
/**
|
|
1556
|
+
* Remove document struct tree information which describes the logical layout of the document.
|
|
1557
|
+
* Removing the "structure tree" can significantly reduce the disk space used by the document.
|
|
1558
|
+
* Removing the "structure tree" of a complicated document can negatively impact text selection.
|
|
1559
|
+
*/
|
|
1560
|
+
private async internal_compressStructTree(): Promise<void> {
|
|
1561
|
+
return await compressStructTree(await this.internal_getId());
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
/**
|
|
1565
|
+
* Compress the PDF and return the result as a Buffer (byte array).
|
|
1566
|
+
* Uses QPdf compression which can significantly reduce file size.
|
|
1567
|
+
* @param imageQuality Optional JPEG quality (1-100) for image compression. If omitted, default compression is applied.
|
|
1568
|
+
*/
|
|
1569
|
+
private async internal_compressPdfToBytes(
|
|
1570
|
+
imageQuality?: number
|
|
1571
|
+
): Promise<Buffer> {
|
|
1572
|
+
if (imageQuality !== undefined && (imageQuality < 1 || imageQuality > 100))
|
|
1573
|
+
throw new Error(
|
|
1574
|
+
`Invalid quality specifier (${imageQuality}) when compressing PDF. Quality must be between 1 and 100.`
|
|
1575
|
+
);
|
|
1576
|
+
return await compressInMemory(
|
|
1577
|
+
await this.internal_getId(),
|
|
1578
|
+
imageQuality
|
|
1579
|
+
);
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
/**
|
|
1583
|
+
* Compress the PDF and return the result as a Readable stream.
|
|
1584
|
+
* Uses QPdf compression which can significantly reduce file size.
|
|
1585
|
+
* Useful for piping directly to file streams or HTTP responses without buffering the entire PDF in memory.
|
|
1586
|
+
* @param imageQuality Optional JPEG quality (1-100) for image compression. If omitted, default compression is applied.
|
|
1587
|
+
*/
|
|
1588
|
+
private async internal_compressPdfToStream(
|
|
1589
|
+
imageQuality?: number
|
|
1590
|
+
): Promise<Readable> {
|
|
1591
|
+
if (imageQuality !== undefined && (imageQuality < 1 || imageQuality > 100))
|
|
1592
|
+
throw new Error(
|
|
1593
|
+
`Invalid quality specifier (${imageQuality}) when compressing PDF. Quality must be between 1 and 100.`
|
|
1594
|
+
);
|
|
1595
|
+
return await compressInMemoryStream(
|
|
1596
|
+
await this.internal_getId(),
|
|
1597
|
+
imageQuality
|
|
1598
|
+
);
|
|
1599
|
+
}
|
|
1600
|
+
|
|
1601
|
+
/**
|
|
1602
|
+
* Compress the PDF and save the result directly to a file.
|
|
1603
|
+
* Uses QPdf compression which can significantly reduce file size.
|
|
1604
|
+
* @param filePath The output file path to save the compressed PDF.
|
|
1605
|
+
* @param imageQuality Optional JPEG quality (1-100) for image compression. If omitted, default compression is applied.
|
|
1606
|
+
*/
|
|
1607
|
+
private async internal_compressAndSaveAs(
|
|
1608
|
+
filePath: string,
|
|
1609
|
+
imageQuality?: number
|
|
1610
|
+
): Promise<void> {
|
|
1611
|
+
if (imageQuality !== undefined && (imageQuality < 1 || imageQuality > 100))
|
|
1612
|
+
throw new Error(
|
|
1613
|
+
`Invalid quality specifier (${imageQuality}) when compressing PDF. Quality must be between 1 and 100.`
|
|
1614
|
+
);
|
|
1615
|
+
return await compressAndSaveAs(
|
|
1616
|
+
await this.internal_getId(),
|
|
1617
|
+
filePath,
|
|
1618
|
+
imageQuality
|
|
1619
|
+
);
|
|
1620
|
+
}
|
|
1621
|
+
|
|
1622
|
+
//#endregion
|
|
1623
|
+
|
|
1624
|
+
//#region page
|
|
1625
|
+
/**
|
|
1626
|
+
* Gets information of all pages in the PdfDocument
|
|
1627
|
+
*/
|
|
1628
|
+
private async internal_getPagesInfo(): Promise<PageInfo[]> {
|
|
1629
|
+
return await getPageInfo(await this.internal_getId());
|
|
1630
|
+
}
|
|
1631
|
+
|
|
1632
|
+
/**
|
|
1633
|
+
* Gets the number of pages in the PdfDocument.
|
|
1634
|
+
*/
|
|
1635
|
+
private async internal_getPageCount(): Promise<number> {
|
|
1636
|
+
return (await this.internal_getPagesInfo()).length;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
/**
|
|
1640
|
+
* Set the page orientation.
|
|
1641
|
+
* @param pageRotation see {@link PageRotation}
|
|
1642
|
+
* @param options including {@link PdfPageSelection}
|
|
1643
|
+
*/
|
|
1644
|
+
private async internal_setRotation(
|
|
1645
|
+
pageRotation: PageRotation,
|
|
1646
|
+
options?: {
|
|
1647
|
+
/**
|
|
1648
|
+
* @default "all"
|
|
1649
|
+
*/
|
|
1650
|
+
pdfPageSelection?: PdfPageSelection | undefined;
|
|
1651
|
+
} | undefined
|
|
1652
|
+
) {
|
|
1653
|
+
return await setPageRotation(await this.internal_getId(), pageRotation, options);
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
/**
|
|
1657
|
+
* Resize a page to the specified dimensions
|
|
1658
|
+
* @param newSize {@link PdfPaperSize}
|
|
1659
|
+
* @param options including {@link PdfPageSelection}
|
|
1660
|
+
*/
|
|
1661
|
+
private async internal_resize(
|
|
1662
|
+
newSize: PdfPaperSize,
|
|
1663
|
+
options?: {
|
|
1664
|
+
/**
|
|
1665
|
+
* @default "all"
|
|
1666
|
+
*/
|
|
1667
|
+
pdfPageSelection?: PdfPageSelection | undefined;
|
|
1668
|
+
} | undefined
|
|
1669
|
+
): Promise<void> {
|
|
1670
|
+
return await resizePage(await this.internal_getId(), newSize, options);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* Adds another PDF to the beginning of the current PdfDocument
|
|
1675
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
1676
|
+
* @param fromPdfDocument PdfDocument to prepend
|
|
1677
|
+
*/
|
|
1678
|
+
private async internal_prependAnotherPdf(
|
|
1679
|
+
fromPdfDocument: PdfDocument
|
|
1680
|
+
): Promise<void> {
|
|
1681
|
+
await this.internal_insertPagesFromAnotherPdf(fromPdfDocument, 0);
|
|
1682
|
+
}
|
|
1683
|
+
|
|
1684
|
+
/**
|
|
1685
|
+
* Appends another PDF to the end of the current <see cref="PdfDocument"/>
|
|
1686
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
1687
|
+
* @param fromPdfDocument PdfDocument to Append
|
|
1688
|
+
*/
|
|
1689
|
+
private async internal_appendAnotherPdf(fromPdfDocument: PdfDocument): Promise<void> {
|
|
1690
|
+
await this.internal_insertPagesFromAnotherPdf(
|
|
1691
|
+
fromPdfDocument,
|
|
1692
|
+
(await this.internal_getPageCount())
|
|
1693
|
+
);
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
/**
|
|
1697
|
+
* Inserts another PDF into the current PdfDocument, starting at a given Page Index.
|
|
1698
|
+
* If AnotherPdfFile contains form fields, those fields will be appended with '_' in the resulting PDF. e.g. 'Name' will be 'Name_'
|
|
1699
|
+
* @param fromPdfDocument Another PdfDocument
|
|
1700
|
+
* @param insertAtPageIndex Index at which to insert the new content. Note: Page 1 has index 0...
|
|
1701
|
+
*/
|
|
1702
|
+
private async internal_insertPagesFromAnotherPdf(
|
|
1703
|
+
fromPdfDocument: PdfDocument,
|
|
1704
|
+
insertAtPageIndex: number
|
|
1705
|
+
): Promise<void> {
|
|
1706
|
+
await insertPdf(
|
|
1707
|
+
await this.internal_getId(),
|
|
1708
|
+
await fromPdfDocument.internal_getId(),
|
|
1709
|
+
insertAtPageIndex
|
|
1710
|
+
);
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* Removes a range of pages from the PDF
|
|
1715
|
+
* @param pages pages to remove
|
|
1716
|
+
*/
|
|
1717
|
+
private async internal_removePage(pages: PdfPageSelection): Promise<void> {
|
|
1718
|
+
await removePage(await this.internal_getId(), {PdfPageSelection: pages});
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
/**
|
|
1722
|
+
* Creates a new PDF by copying a range of pages from this {@link PdfDocument}.
|
|
1723
|
+
* @param pages pages to copy (default "all")
|
|
1724
|
+
*/
|
|
1725
|
+
private async internal_duplicate(
|
|
1726
|
+
pages: PdfPageSelection = "all"
|
|
1727
|
+
): Promise<PdfDocument> {
|
|
1728
|
+
const newPdf = new PdfDocument();
|
|
1729
|
+
newPdf.pdfDocumentId = await duplicate(await this.internal_getId(), {
|
|
1730
|
+
PdfPageSelection: pages,
|
|
1731
|
+
});
|
|
1732
|
+
return newPdf;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
//#endregion
|
|
1736
|
+
|
|
1737
|
+
//#region image
|
|
1738
|
+
/**
|
|
1739
|
+
* Finds all embedded Images from within a specified pages in the PDF and returns them as Buffer
|
|
1740
|
+
* @param options including {@link PdfPageSelection}
|
|
1741
|
+
*/
|
|
1742
|
+
private async internal_extractRawImages(options?: {
|
|
1743
|
+
/**
|
|
1744
|
+
* @default "all"
|
|
1745
|
+
*/
|
|
1746
|
+
fromPages?: PdfPageSelection | undefined;
|
|
1747
|
+
} | undefined): Promise<Buffer[]> {
|
|
1748
|
+
return extractRawImages(
|
|
1749
|
+
await this.internal_getId(),
|
|
1750
|
+
options?.fromPages ?? "all"
|
|
1751
|
+
);
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* Renders the PDF and exports image Files in convenient formats. 1 image file is created for each
|
|
1756
|
+
* page.
|
|
1757
|
+
*
|
|
1758
|
+
* @param options including {@link PdfPageSelection} {@link ImageType}
|
|
1759
|
+
*
|
|
1760
|
+
* @return array of images as Buffer[]
|
|
1761
|
+
*/
|
|
1762
|
+
private async internal_rasterizeToImageBuffers(options?: {
|
|
1763
|
+
/**
|
|
1764
|
+
* @default "all"
|
|
1765
|
+
*/
|
|
1766
|
+
fromPages?: PdfPageSelection | undefined;
|
|
1767
|
+
/**
|
|
1768
|
+
* @default {@link ImageType.PNG}
|
|
1769
|
+
*/
|
|
1770
|
+
imageType?: ImageType | undefined;
|
|
1771
|
+
}): Promise<Buffer[]> {
|
|
1772
|
+
const images = await rasterizeToImageBuffers(
|
|
1773
|
+
await this.internal_getId(),
|
|
1774
|
+
options?.fromPages ?? "all"
|
|
1775
|
+
);
|
|
1776
|
+
const jimpImageType: "image/bmp" | "image/png" | "image/jpeg" = (() => {
|
|
1777
|
+
switch (options?.imageType) {
|
|
1778
|
+
case ImageType.BMP:
|
|
1779
|
+
return Jimp.MIME_BMP;
|
|
1780
|
+
case ImageType.PNG:
|
|
1781
|
+
return Jimp.MIME_PNG;
|
|
1782
|
+
case ImageType.JPG:
|
|
1783
|
+
return Jimp.MIME_JPEG;
|
|
1784
|
+
default:
|
|
1785
|
+
return Jimp.MIME_PNG;
|
|
1786
|
+
}
|
|
1787
|
+
})();
|
|
1788
|
+
return Promise.all(
|
|
1789
|
+
images.map(async (imageBuffer) => {
|
|
1790
|
+
//convert output type
|
|
1791
|
+
const jimp = await Jimp.read(imageBuffer);
|
|
1792
|
+
return await jimp.getBufferAsync(jimpImageType);
|
|
1793
|
+
})
|
|
1794
|
+
);
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
/**
|
|
1798
|
+
* Renders the PDF and exports image Files in convenient formats. 1 image file is created for each
|
|
1799
|
+
* page. Running number will append output file path.
|
|
1800
|
+
*
|
|
1801
|
+
* @param filePath output file path.
|
|
1802
|
+
* @param options including {@link PdfPageSelection} {@link ImageType}
|
|
1803
|
+
*
|
|
1804
|
+
* @return array of images file name as string[]
|
|
1805
|
+
*/
|
|
1806
|
+
private async internal_rasterizeToImageFiles(
|
|
1807
|
+
filePath: string,
|
|
1808
|
+
options?: {
|
|
1809
|
+
/**
|
|
1810
|
+
* @default "all"
|
|
1811
|
+
*/
|
|
1812
|
+
fromPages?: PdfPageSelection | undefined;
|
|
1813
|
+
/**
|
|
1814
|
+
* @default {@link ImageType.PNG}
|
|
1815
|
+
*/
|
|
1816
|
+
type?: ImageType | undefined;
|
|
1817
|
+
} | undefined
|
|
1818
|
+
): Promise<string[]> {
|
|
1819
|
+
const images = await rasterizeToImageBuffers(
|
|
1820
|
+
await this.internal_getId(),
|
|
1821
|
+
options?.fromPages ?? "all"
|
|
1822
|
+
);
|
|
1823
|
+
|
|
1824
|
+
const promises = images.map(async (imageBuffer, index) => {
|
|
1825
|
+
const outputFileName = getFileName(filePath,index.toString(),getImageExtType(options?.type),"image");
|
|
1826
|
+
await Jimp.read(imageBuffer).then((value) => {
|
|
1827
|
+
return value.write(outputFileName);
|
|
1828
|
+
});
|
|
1829
|
+
return outputFileName;
|
|
1830
|
+
});
|
|
1831
|
+
|
|
1832
|
+
return await Promise.all(promises);
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
//#endregion
|
|
1836
|
+
|
|
1837
|
+
//#region text
|
|
1838
|
+
/**
|
|
1839
|
+
* Replace the specified old text with new text on a given page
|
|
1840
|
+
* @param oldText Old text to remove
|
|
1841
|
+
* @param newText New text to add
|
|
1842
|
+
* @param onPages Page index to search for old text to replace (default "all")
|
|
1843
|
+
*/
|
|
1844
|
+
private async internal_replaceText(
|
|
1845
|
+
oldText: string,
|
|
1846
|
+
newText: string,
|
|
1847
|
+
onPages?: PdfPageSelection | undefined
|
|
1848
|
+
): Promise<void> {
|
|
1849
|
+
return replaceText(await this.internal_getId(), oldText, newText, onPages);
|
|
1850
|
+
}
|
|
1851
|
+
|
|
1852
|
+
private async internal_extractText(
|
|
1853
|
+
onPages?: PdfPageSelection | undefined
|
|
1854
|
+
): Promise<string> {
|
|
1855
|
+
return extractAllText(await this.internal_getId(), onPages);
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
//#endregion
|
|
1859
|
+
|
|
1860
|
+
//#region pdfA
|
|
1861
|
+
/**
|
|
1862
|
+
* Convert the current document into the specified PDF-A standard format
|
|
1863
|
+
* @param pdfaVersion The PDF/A version to convert to
|
|
1864
|
+
* @param customICC (Optional) Custom color profile file path
|
|
1865
|
+
*/
|
|
1866
|
+
private async internal_convertToPdfA(pdfaVersion: PdfAVersions, customICC?: string | undefined): Promise<void> {
|
|
1867
|
+
return await toPdfA(await this.internal_getId(), pdfaVersion, customICC);
|
|
1868
|
+
}
|
|
1869
|
+
|
|
1870
|
+
/**
|
|
1871
|
+
* Convert the current document into the specified PDF/UA standard format
|
|
1872
|
+
*/
|
|
1873
|
+
private async internal_convertToPdfUA(naturalLanguages: NaturalLanguages, pdfUaVersion: PdfUAVersions = PdfUAVersions.PdfUA1): Promise<void> {
|
|
1874
|
+
return await toPdfUA(await this.internal_getId(), naturalLanguages, pdfUaVersion);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
//#endregion
|
|
1878
|
+
|
|
1879
|
+
//#region metadata
|
|
1880
|
+
/**
|
|
1881
|
+
* Gets a Map<string, string> of metadata properties
|
|
1882
|
+
*/
|
|
1883
|
+
private async internal_getMetadata(): Promise<Map<string, string>> {
|
|
1884
|
+
return getMetadataDict(await this.internal_getId());
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
/**
|
|
1888
|
+
* Add or Update a single metadata property
|
|
1889
|
+
* @param key
|
|
1890
|
+
* @param value
|
|
1891
|
+
*/
|
|
1892
|
+
private async internal_addOrUpdateMetadata(
|
|
1893
|
+
key: string,
|
|
1894
|
+
value: string
|
|
1895
|
+
): Promise<void> {
|
|
1896
|
+
return setMetadata(await this.internal_getId(), key, value);
|
|
1897
|
+
}
|
|
1898
|
+
|
|
1899
|
+
/**
|
|
1900
|
+
* Remove a single metadata property
|
|
1901
|
+
* @param key
|
|
1902
|
+
*/
|
|
1903
|
+
private async internal_removeMetadata(key: string): Promise<void> {
|
|
1904
|
+
return removeMetadata(await this.internal_getId(), key);
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
|
|
1908
|
+
/**
|
|
1909
|
+
* Sets a whole metadata properties Map<string, string> (override all the metadata property)
|
|
1910
|
+
* @param newMetadataDictionary new metadata properties Map<string, string>
|
|
1911
|
+
*/
|
|
1912
|
+
private async internal_overrideMetadata(
|
|
1913
|
+
newMetadataDictionary: Map<string, string>
|
|
1914
|
+
): Promise<void> {
|
|
1915
|
+
return setMetadataDict(await this.internal_getId(), newMetadataDictionary);
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
//#endregion
|
|
1919
|
+
|
|
1920
|
+
//#region signing
|
|
1921
|
+
/**
|
|
1922
|
+
* Sign PDF with digital signature certificate.
|
|
1923
|
+
* Note that the PDF will not be fully signed until Saved
|
|
1924
|
+
* using {@link saveAs} or {@link saveAsBuffer}
|
|
1925
|
+
*
|
|
1926
|
+
* Multiple certificates may be used.
|
|
1927
|
+
* @param signature see {@link DigitalSignature}
|
|
1928
|
+
*/
|
|
1929
|
+
private async internal_signDigitalSignature(signature: DigitalSignature) {
|
|
1930
|
+
return await signPdf(await this.internal_getId(), signature);
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
/**
|
|
1934
|
+
* Check if PdfDocument was signed or not
|
|
1935
|
+
*/
|
|
1936
|
+
private async internal_isSigned(): Promise<boolean> {
|
|
1937
|
+
const signatureCount = await getSignatureCount(await this.internal_getId());
|
|
1938
|
+
return signatureCount > 0;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
/**
|
|
1942
|
+
* Count the number signature that signed to this PdfDocument
|
|
1943
|
+
*/
|
|
1944
|
+
private async internal_signatureCount(): Promise<number> {
|
|
1945
|
+
return await getSignatureCount(await this.internal_getId());
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
/**
|
|
1949
|
+
* Get all verified digital signatures from this PdfDocument.
|
|
1950
|
+
*/
|
|
1951
|
+
private async internal_getVerifiedSignatures(): Promise<VerifiedSignature[]> {
|
|
1952
|
+
return await getVerifiedSignatures(await this.internal_getId());
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
//#endregion
|
|
1956
|
+
|
|
1957
|
+
//#region header/footer (affix)
|
|
1958
|
+
/**
|
|
1959
|
+
* Apply page header on top of an existing Pdf.
|
|
1960
|
+
* @param header {@link TextAffix}
|
|
1961
|
+
* @param toPages {@link PdfPageSelection}
|
|
1962
|
+
*/
|
|
1963
|
+
private async internal_addTextHeader(
|
|
1964
|
+
header: TextAffix,
|
|
1965
|
+
toPages?: PdfPageSelection | undefined
|
|
1966
|
+
): Promise<void> {
|
|
1967
|
+
await addTextAffix(await this.internal_getId(), toPages, header, true);
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
/**
|
|
1971
|
+
* Apply page footer on top of an existing Pdf.
|
|
1972
|
+
* @param footer {@link TextAffix}
|
|
1973
|
+
* @param toPages {@link PdfPageSelection}
|
|
1974
|
+
*/
|
|
1975
|
+
private async internal_addTextFooter(
|
|
1976
|
+
footer: TextAffix,
|
|
1977
|
+
toPages?: PdfPageSelection | undefined
|
|
1978
|
+
): Promise<void> {
|
|
1979
|
+
await addTextAffix(await this.internal_getId(), toPages, footer, false);
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
/**
|
|
1983
|
+
* Apply HTML header on top of an existing Pdf.
|
|
1984
|
+
* @param header {@link HtmlAffix}
|
|
1985
|
+
* @param toPages {@link PdfPageSelection}
|
|
1986
|
+
*/
|
|
1987
|
+
private async internal_addHtmlHeader(
|
|
1988
|
+
header: HtmlAffix,
|
|
1989
|
+
toPages?: PdfPageSelection | undefined
|
|
1990
|
+
): Promise<void> {
|
|
1991
|
+
await addHtmlAffix(await this.internal_getId(), toPages, header, true);
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
/**
|
|
1995
|
+
* Apply HTML footer on top of an existing Pdf.
|
|
1996
|
+
* @param footer {@link HtmlAffix}
|
|
1997
|
+
* @param toPages {@link PdfPageSelection}
|
|
1998
|
+
*/
|
|
1999
|
+
private async internal_addHtmlFooter(
|
|
2000
|
+
footer: HtmlAffix,
|
|
2001
|
+
toPages?: PdfPageSelection | undefined
|
|
2002
|
+
): Promise<void> {
|
|
2003
|
+
await addHtmlAffix(await this.internal_getId(), toPages, footer, false);
|
|
2004
|
+
}
|
|
2005
|
+
|
|
2006
|
+
//#endregion
|
|
2007
|
+
|
|
2008
|
+
//#region stamp
|
|
2009
|
+
/**
|
|
2010
|
+
* Edits the PDF by applying the HTML's rendered to only selected page(s).
|
|
2011
|
+
* @param htmlStringOrHtmlFilePath
|
|
2012
|
+
* @param options including {@link HtmlStampOptions} {@link PdfPageSelection}
|
|
2013
|
+
*/
|
|
2014
|
+
private async internal_stampHtml(
|
|
2015
|
+
htmlStringOrHtmlFilePath: HtmlFilePath | HtmlString,
|
|
2016
|
+
options?: {
|
|
2017
|
+
htmlStampOptions?: HtmlStampOptions | undefined;
|
|
2018
|
+
toPages?: PdfPageSelection | undefined;
|
|
2019
|
+
} | undefined
|
|
2020
|
+
) {
|
|
2021
|
+
const html =
|
|
2022
|
+
htmlStringOrHtmlFilePath.endsWith(".html") ||
|
|
2023
|
+
htmlStringOrHtmlFilePath.endsWith(".htm")
|
|
2024
|
+
? fs.readFileSync(htmlStringOrHtmlFilePath).toString()
|
|
2025
|
+
: htmlStringOrHtmlFilePath;
|
|
2026
|
+
|
|
2027
|
+
await stampHtml(await this.internal_getId(), html, {
|
|
2028
|
+
password: this.pdfPassword,
|
|
2029
|
+
htmlStampOptions: options?.htmlStampOptions,
|
|
2030
|
+
pageSelection: options?.toPages,
|
|
2031
|
+
});
|
|
2032
|
+
}
|
|
2033
|
+
|
|
2034
|
+
/**
|
|
2035
|
+
* Edits the PDF by applying the image to only selected page(s).
|
|
2036
|
+
* @param image image file path or image buffer
|
|
2037
|
+
* @param options including {@link ImageStampOptions} {@link PdfPageSelection}
|
|
2038
|
+
*/
|
|
2039
|
+
private async internal_stampImage(
|
|
2040
|
+
image: ImageFilePath | ImageBuffer,
|
|
2041
|
+
options?: {
|
|
2042
|
+
imageStampOptions?: ImageStampOptions | undefined;
|
|
2043
|
+
toPages?: PdfPageSelection | undefined;
|
|
2044
|
+
} | undefined
|
|
2045
|
+
) {
|
|
2046
|
+
const imageBuffer =
|
|
2047
|
+
image instanceof Buffer ? image : fs.readFileSync(image);
|
|
2048
|
+
|
|
2049
|
+
await stampImage(await this.internal_getId(), imageBuffer, {
|
|
2050
|
+
password: this.pdfPassword,
|
|
2051
|
+
imageStampOptions: options?.imageStampOptions,
|
|
2052
|
+
pageSelection: options?.toPages,
|
|
2053
|
+
});
|
|
2054
|
+
}
|
|
2055
|
+
|
|
2056
|
+
/**
|
|
2057
|
+
* Edits the PDF by applying the text to only selected page(s).
|
|
2058
|
+
* @param text text to stamp
|
|
2059
|
+
* @param options including {@link TextStampOptions} {@link PdfPageSelection}
|
|
2060
|
+
*/
|
|
2061
|
+
private async internal_stampText(
|
|
2062
|
+
text: string,
|
|
2063
|
+
options?: {
|
|
2064
|
+
textStampOptions?: TextStampOptions | undefined;
|
|
2065
|
+
toPages?: PdfPageSelection | undefined;
|
|
2066
|
+
} | undefined
|
|
2067
|
+
) {
|
|
2068
|
+
await stampText(await this.internal_getId(), text, {
|
|
2069
|
+
password: this.pdfPassword,
|
|
2070
|
+
textStampOptions: options?.textStampOptions,
|
|
2071
|
+
pageSelection: options?.toPages,
|
|
2072
|
+
});
|
|
2073
|
+
}
|
|
2074
|
+
|
|
2075
|
+
/**
|
|
2076
|
+
* Edits the PDF by applying the barcode to only selected page(s).
|
|
2077
|
+
* @param barcodeValue barcode
|
|
2078
|
+
* @param options including {@link BarcodeType} {@link BarcodeStampOptions} {@link PdfPageSelection}
|
|
2079
|
+
*/
|
|
2080
|
+
private async internal_stampBarcode(
|
|
2081
|
+
barcodeValue: string,
|
|
2082
|
+
options?: {
|
|
2083
|
+
barcodeEncoding: BarcodeType;
|
|
2084
|
+
barcodeStampOptions?: BarcodeStampOptions | undefined;
|
|
2085
|
+
toPages?: PdfPageSelection | undefined;
|
|
2086
|
+
} | undefined
|
|
2087
|
+
) {
|
|
2088
|
+
await stampBarcode(
|
|
2089
|
+
await this.internal_getId(),
|
|
2090
|
+
barcodeValue,
|
|
2091
|
+
{
|
|
2092
|
+
password: this.pdfPassword,
|
|
2093
|
+
barcodeStampOptions: options?.barcodeStampOptions,
|
|
2094
|
+
pageSelection: options?.toPages,
|
|
2095
|
+
}
|
|
2096
|
+
);
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
//#endregion
|
|
2100
|
+
|
|
2101
|
+
//#region background/foreground
|
|
2102
|
+
/**
|
|
2103
|
+
* Adds a background to each page of this PDF. The background is copied from a first page in the
|
|
2104
|
+
* backgroundPdf document.
|
|
2105
|
+
*
|
|
2106
|
+
* @param fromPdf background PDF document
|
|
2107
|
+
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
2108
|
+
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
2109
|
+
*/
|
|
2110
|
+
private async internal_addBackgroundFromAnotherPdf(
|
|
2111
|
+
fromPdf: PdfDocument,
|
|
2112
|
+
sourcePageIndex = 0,
|
|
2113
|
+
applyToPages?: PdfPageSelection | undefined
|
|
2114
|
+
): Promise<void> {
|
|
2115
|
+
return await addBackgroundForeground(
|
|
2116
|
+
await this.internal_getId(),
|
|
2117
|
+
await fromPdf.internal_getId(),
|
|
2118
|
+
sourcePageIndex,
|
|
2119
|
+
true,
|
|
2120
|
+
applyToPages
|
|
2121
|
+
);
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
/**
|
|
2125
|
+
* Adds a foreground to each page of this PDF. The background is copied from a first page in the
|
|
2126
|
+
* backgroundPdf document.
|
|
2127
|
+
*
|
|
2128
|
+
* @param fromPdf foreground PDF document
|
|
2129
|
+
* @param sourcePageIndex Index (zero-based page number) of the page to copy from the Background/Foreground PDF. Default is 0.
|
|
2130
|
+
* @param applyToPages PageSelection to which the background/foreground will be added. Default is "all"
|
|
2131
|
+
*/
|
|
2132
|
+
private async internal_addForegroundFromAnotherPdf(
|
|
2133
|
+
fromPdf: PdfDocument,
|
|
2134
|
+
sourcePageIndex = 0,
|
|
2135
|
+
applyToPages?: PdfPageSelection | undefined
|
|
2136
|
+
): Promise<void> {
|
|
2137
|
+
return await addBackgroundForeground(
|
|
2138
|
+
await this.internal_getId(),
|
|
2139
|
+
await fromPdf.internal_getId(),
|
|
2140
|
+
sourcePageIndex,
|
|
2141
|
+
false,
|
|
2142
|
+
applyToPages
|
|
2143
|
+
);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
//#endregion
|
|
2147
|
+
|
|
2148
|
+
//#region security
|
|
2149
|
+
/**
|
|
2150
|
+
* Removes all user and owner password security for a PDF document. Also disables content
|
|
2151
|
+
* encryption.
|
|
2152
|
+
* If content is encrypted at 128 bit, copy and paste of content, annotations and form editing may be disabled.
|
|
2153
|
+
*/
|
|
2154
|
+
private async internal_removePasswordsAndEncryption(): Promise<void> {
|
|
2155
|
+
await removePasswordsAndEncryption(await this.internal_getId());
|
|
2156
|
+
}
|
|
2157
|
+
|
|
2158
|
+
/**
|
|
2159
|
+
* Sets the user password and enables 128Bit encryption of PDF content.
|
|
2160
|
+
* A user password is a password that each user must enter to open or print the PDF document.
|
|
2161
|
+
*/
|
|
2162
|
+
private async internal_setUserPassword(userPassword: string): Promise<void> {
|
|
2163
|
+
if (!this.pdfPassword)
|
|
2164
|
+
this.pdfPassword = {userPassword: userPassword};
|
|
2165
|
+
else this.pdfPassword.userPassword = userPassword;
|
|
2166
|
+
this.pdfDocumentId = await setUserPasswords(
|
|
2167
|
+
await this.internal_getId(),
|
|
2168
|
+
userPassword
|
|
2169
|
+
);
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
/**
|
|
2173
|
+
* Sets the owner password and enables 128Bit encryption of PDF content. An owner password is one used to
|
|
2174
|
+
* enable and disable all other security settings. <para>OwnerPassword must be set to a non-empty string
|
|
2175
|
+
* value for {@link PdfPermission.AllowAccessibilityExtractContent} , {@link PdfPermission.AllowAnnotations} ,
|
|
2176
|
+
* {@link PdfPermission.AllowFillForms}, {@link PdfPermission.AllowPrint}, {@link PdfPermission.AllowModify} to be
|
|
2177
|
+
* restricted.
|
|
2178
|
+
*/
|
|
2179
|
+
private async internal_setOwnerPassword(ownerPassword: string): Promise<void> {
|
|
2180
|
+
if (!this.pdfPassword)
|
|
2181
|
+
this.pdfPassword = {ownerPassword: ownerPassword};
|
|
2182
|
+
else this.pdfPassword.ownerPassword = ownerPassword;
|
|
2183
|
+
this.pdfDocumentId = await setOwnerPasswords(
|
|
2184
|
+
await this.internal_getId(),
|
|
2185
|
+
ownerPassword
|
|
2186
|
+
);
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* Sets the permissions of this PdfDocument
|
|
2191
|
+
* @param permissions see {@link PdfPermission}
|
|
2192
|
+
*/
|
|
2193
|
+
private async internal_setPermission(permissions: PdfPermission): Promise<void> {
|
|
2194
|
+
this.pdfDocumentId = await setSecurity(await this.internal_getId(), permissions);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
/**
|
|
2198
|
+
* Gets the current permissions of this PdfDocument
|
|
2199
|
+
* @return {@link PdfPermission}
|
|
2200
|
+
*/
|
|
2201
|
+
private async internal_getPermission(): Promise<PdfPermission> {
|
|
2202
|
+
return await getPermission(await this.internal_getId());
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
/**
|
|
2206
|
+
* Makes this PDF document read only such that: Content is encrypted at 128 bit. Copy and paste of
|
|
2207
|
+
* content is disallowed. Annotations and form editing are disabled.
|
|
2208
|
+
* @param ownerPassword The owner password for the PDF. A string for owner password is required to enable PDF encryption and
|
|
2209
|
+
* all document security options.
|
|
2210
|
+
*/
|
|
2211
|
+
private async internal_makePdfDocumentReadOnly(ownerPassword: string): Promise<void> {
|
|
2212
|
+
await this.internal_setOwnerPassword(ownerPassword);
|
|
2213
|
+
await this.internal_setPermission({
|
|
2214
|
+
AllowExtractContent: false,
|
|
2215
|
+
AllowAccessibilityExtractContent: false,
|
|
2216
|
+
AllowAnnotations: false,
|
|
2217
|
+
AllowModify: false,
|
|
2218
|
+
AllowAssembleDocument: false,
|
|
2219
|
+
AllowFillForms: false,
|
|
2220
|
+
});
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
//#endregion
|
|
2224
|
+
|
|
2225
|
+
//#endregion
|
|
2226
|
+
}
|