@pdfgeneratorapi/n8n-nodes-pdf-generator-api 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2377 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PdfGeneratorApi = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ class PdfGeneratorApi {
6
+ constructor() {
7
+ this.description = {
8
+ displayName: 'PDF Generator API',
9
+ name: 'pdfGeneratorApi',
10
+ icon: { light: 'file:pdfgeneratorapi.svg', dark: 'file:pdfgeneratorapi.svg' },
11
+ group: ['transform'],
12
+ version: 1,
13
+ subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
14
+ description: 'Generate PDFs, manage templates, convert HTML/URLs to PDF, and perform PDF operations like watermarking, encryption, and optimization',
15
+ defaults: {
16
+ name: 'PDF Generator API',
17
+ },
18
+ inputs: ["main"],
19
+ outputs: ["main"],
20
+ usableAsTool: true,
21
+ credentials: [
22
+ {
23
+ name: 'pdfGeneratorApi',
24
+ required: true,
25
+ },
26
+ ],
27
+ requestDefaults: {
28
+ headers: {
29
+ Accept: 'application/json',
30
+ 'Content-Type': 'application/json',
31
+ },
32
+ },
33
+ properties: [
34
+ {
35
+ displayName: 'Resource',
36
+ name: 'resource',
37
+ type: 'options',
38
+ noDataExpression: true,
39
+ options: [
40
+ {
41
+ name: 'Conversion',
42
+ value: 'conversion',
43
+ description: 'Convert HTML content or URLs directly to PDF without templates',
44
+ },
45
+ {
46
+ name: 'Document',
47
+ value: 'document',
48
+ description: 'Generate PDFs from templates with data, manage document storage',
49
+ },
50
+ {
51
+ name: 'PDF Service',
52
+ value: 'pdfServices',
53
+ description: 'Process existing PDFs: add watermarks, encrypt, decrypt, optimize, and manage form fields',
54
+ },
55
+ {
56
+ name: 'Template',
57
+ value: 'template',
58
+ description: 'Create, update, and manage PDF templates for document generation',
59
+ },
60
+ {
61
+ name: 'Workspace',
62
+ value: 'workspace',
63
+ description: 'Manage workspaces for organizing templates and users',
64
+ },
65
+ ],
66
+ default: 'document',
67
+ description: 'Choose the type of PDF operation: generate documents from templates, convert HTML/URLs, process existing PDFs, or manage templates and workspaces',
68
+ },
69
+ {
70
+ displayName: 'Operation',
71
+ name: 'conversionOperation',
72
+ type: 'options',
73
+ noDataExpression: true,
74
+ displayOptions: {
75
+ show: {
76
+ resource: ['conversion'],
77
+ },
78
+ },
79
+ options: [
80
+ {
81
+ name: 'HTML to PDF',
82
+ value: 'htmlToPdf',
83
+ description: 'Convert HTML content to PDF',
84
+ action: 'Convert HTML content to PDF',
85
+ },
86
+ {
87
+ name: 'URL to PDF',
88
+ value: 'urlToPdf',
89
+ description: 'Convert public URL to PDF',
90
+ action: 'Convert public URL to PDF',
91
+ },
92
+ ],
93
+ default: 'htmlToPdf',
94
+ },
95
+ {
96
+ displayName: 'Operation',
97
+ name: 'documentOperation',
98
+ type: 'options',
99
+ noDataExpression: true,
100
+ displayOptions: {
101
+ show: {
102
+ resource: ['document'],
103
+ },
104
+ },
105
+ options: [
106
+ {
107
+ name: 'Delete',
108
+ value: 'delete',
109
+ description: 'Delete a document from storage',
110
+ action: 'Delete a document from storage',
111
+ },
112
+ {
113
+ name: 'Generate',
114
+ value: 'generate',
115
+ description: 'Generate a PDF document',
116
+ action: 'Generate a PDF document',
117
+ },
118
+ {
119
+ name: 'Generate (Async)',
120
+ value: 'generateAsync',
121
+ description: 'Generate a PDF document asynchronously',
122
+ action: 'Generate a PDF document asynchronously',
123
+ },
124
+ {
125
+ name: 'Generate (Batch + Async)',
126
+ value: 'generateBatchAsync',
127
+ description: 'Generate multiple PDF documents in batch asynchronously',
128
+ action: 'Generate multiple PDF documents in batch asynchronously',
129
+ },
130
+ {
131
+ name: 'Generate (Batch)',
132
+ value: 'generateBatch',
133
+ description: 'Generate multiple PDF documents in batch',
134
+ action: 'Generate multiple PDF documents in batch',
135
+ },
136
+ {
137
+ name: 'Get',
138
+ value: 'get',
139
+ description: 'Get a document by public ID',
140
+ action: 'Get a document by public ID',
141
+ },
142
+ {
143
+ name: 'List',
144
+ value: 'list',
145
+ description: 'List generated documents',
146
+ action: 'List generated documents',
147
+ },
148
+ ],
149
+ default: 'generate',
150
+ },
151
+ {
152
+ displayName: 'Operation',
153
+ name: 'pdfServicesOperation',
154
+ type: 'options',
155
+ noDataExpression: true,
156
+ displayOptions: {
157
+ show: {
158
+ resource: ['pdfServices'],
159
+ },
160
+ },
161
+ options: [
162
+ {
163
+ name: 'Add Watermark',
164
+ value: 'addWatermark',
165
+ description: 'Add text or image watermark to PDF document',
166
+ action: 'Add watermark to PDF document',
167
+ },
168
+ {
169
+ name: 'Decrypt Document',
170
+ value: 'decrypt',
171
+ description: 'Decrypt an encrypted PDF document',
172
+ action: 'Decrypt encrypted PDF document',
173
+ },
174
+ {
175
+ name: 'Encrypt Document',
176
+ value: 'encrypt',
177
+ description: 'Encrypt a PDF document with password protection',
178
+ action: 'Encrypt PDF document with password',
179
+ },
180
+ {
181
+ name: 'Extract Form Fields',
182
+ value: 'extractFormFields',
183
+ description: 'Extract form fields and their metadata from a PDF document',
184
+ action: 'Extract form fields from PDF document',
185
+ },
186
+ {
187
+ name: 'Fill Form Fields',
188
+ value: 'fillFormFields',
189
+ description: 'Fill form fields in a PDF document with provided data',
190
+ action: 'Fill form fields in PDF document',
191
+ },
192
+ {
193
+ name: 'Optimize Document',
194
+ value: 'optimize',
195
+ description: 'Optimize PDF document size for better performance',
196
+ action: 'Optimize PDF document size',
197
+ },
198
+ ],
199
+ default: 'addWatermark',
200
+ },
201
+ {
202
+ displayName: 'PDF Source',
203
+ name: 'pdfSource',
204
+ type: 'options',
205
+ options: [
206
+ {
207
+ name: 'From URL',
208
+ value: 'url',
209
+ description: 'Use a PDF from a public URL',
210
+ },
211
+ {
212
+ name: 'From Base64',
213
+ value: 'base64',
214
+ description: 'Use a PDF from base64 encoded content',
215
+ },
216
+ ],
217
+ default: 'url',
218
+ displayOptions: {
219
+ show: {
220
+ resource: ['pdfServices'],
221
+ },
222
+ },
223
+ description: 'Source of the PDF document to process',
224
+ },
225
+ {
226
+ displayName: 'PDF URL',
227
+ name: 'fileUrl',
228
+ type: 'string',
229
+ required: true,
230
+ displayOptions: {
231
+ show: {
232
+ resource: ['pdfServices'],
233
+ pdfSource: ['url'],
234
+ },
235
+ },
236
+ default: '',
237
+ description: 'Public URL to the PDF document',
238
+ placeholder: 'https://example.com/document.pdf',
239
+ },
240
+ {
241
+ displayName: 'PDF Base64',
242
+ name: 'fileBase64',
243
+ type: 'string',
244
+ typeOptions: {
245
+ rows: 4,
246
+ },
247
+ required: true,
248
+ displayOptions: {
249
+ show: {
250
+ resource: ['pdfServices'],
251
+ pdfSource: ['base64'],
252
+ },
253
+ },
254
+ default: '',
255
+ description: 'Base64 encoded PDF content',
256
+ placeholder: 'JVBERi0xLjQKJeLjz9MKMSAwIG9iago8...',
257
+ },
258
+ {
259
+ displayName: 'Output Format',
260
+ name: 'outputFormat',
261
+ type: 'options',
262
+ options: [
263
+ {
264
+ name: 'Base64 (JSON)',
265
+ value: 'base64',
266
+ description: 'Returns JSON response with base64 string',
267
+ },
268
+ {
269
+ name: 'File (Binary)',
270
+ value: 'file',
271
+ description: 'Returns binary file data for download/attachment',
272
+ },
273
+ {
274
+ name: 'URL (JSON)',
275
+ value: 'url',
276
+ description: 'Returns JSON response with download URL',
277
+ },
278
+ ],
279
+ default: 'base64',
280
+ displayOptions: {
281
+ show: {
282
+ resource: ['pdfServices'],
283
+ },
284
+ },
285
+ description: 'Choose output format: JSON with base64 string, download URL, or binary file',
286
+ },
287
+ {
288
+ displayName: 'Watermark Type',
289
+ name: 'watermarkType',
290
+ type: 'multiOptions',
291
+ options: [
292
+ {
293
+ name: 'Text',
294
+ value: 'text',
295
+ description: 'Add text watermark',
296
+ },
297
+ {
298
+ name: 'Image',
299
+ value: 'image',
300
+ description: 'Add image watermark',
301
+ },
302
+ ],
303
+ default: ['text'],
304
+ displayOptions: {
305
+ show: {
306
+ resource: ['pdfServices'],
307
+ pdfServicesOperation: ['addWatermark'],
308
+ },
309
+ },
310
+ description: 'Type of watermark to add (can select both text and image)',
311
+ },
312
+ {
313
+ displayName: 'Watermark Text',
314
+ name: 'watermarkText',
315
+ type: 'string',
316
+ displayOptions: {
317
+ show: {
318
+ resource: ['pdfServices'],
319
+ pdfServicesOperation: ['addWatermark'],
320
+ watermarkType: ['text'],
321
+ },
322
+ },
323
+ default: 'CONFIDENTIAL',
324
+ description: 'Text to use as watermark',
325
+ placeholder: 'CONFIDENTIAL',
326
+ },
327
+ {
328
+ displayName: 'Watermark Image URL',
329
+ name: 'watermarkImageUrl',
330
+ type: 'string',
331
+ displayOptions: {
332
+ show: {
333
+ resource: ['pdfServices'],
334
+ pdfServicesOperation: ['addWatermark'],
335
+ watermarkType: ['image'],
336
+ },
337
+ },
338
+ default: '',
339
+ description: 'URL to image file to use as watermark',
340
+ placeholder: 'https://example.com/watermark.png',
341
+ },
342
+ {
343
+ displayName: 'Text Watermark Options',
344
+ name: 'textWatermarkOptions',
345
+ type: 'collection',
346
+ placeholder: 'Add Option',
347
+ default: {},
348
+ displayOptions: {
349
+ show: {
350
+ resource: ['pdfServices'],
351
+ pdfServicesOperation: ['addWatermark'],
352
+ watermarkType: ['text'],
353
+ },
354
+ },
355
+ description: 'Additional options for text watermark',
356
+ options: [
357
+ {
358
+ displayName: 'Color',
359
+ name: 'color',
360
+ type: 'color',
361
+ default: '#FF0000',
362
+ description: 'Color of the text watermark',
363
+ },
364
+ {
365
+ displayName: 'Font Size',
366
+ name: 'size',
367
+ type: 'number',
368
+ typeOptions: {
369
+ minValue: 7,
370
+ maxValue: 80,
371
+ },
372
+ default: 48,
373
+ description: 'Font size of the text watermark',
374
+ },
375
+ {
376
+ displayName: 'Opacity',
377
+ name: 'opacity',
378
+ type: 'number',
379
+ typeOptions: {
380
+ minValue: 0,
381
+ maxValue: 1,
382
+ numberPrecision: 2,
383
+ },
384
+ default: 0.5,
385
+ description: 'Opacity of the text watermark (0 = transparent, 1 = opaque)',
386
+ },
387
+ {
388
+ displayName: 'Position',
389
+ name: 'position',
390
+ type: 'options',
391
+ options: [
392
+ {
393
+ name: 'Bottom Center',
394
+ value: 'bottom-center',
395
+ },
396
+ {
397
+ name: 'Bottom Left',
398
+ value: 'bottom-left',
399
+ },
400
+ {
401
+ name: 'Bottom Right',
402
+ value: 'bottom-right',
403
+ },
404
+ {
405
+ name: 'Center',
406
+ value: 'center',
407
+ },
408
+ {
409
+ name: 'Center Left',
410
+ value: 'center-left',
411
+ },
412
+ {
413
+ name: 'Center Right',
414
+ value: 'center-right',
415
+ },
416
+ {
417
+ name: 'Top Center',
418
+ value: 'top-center',
419
+ },
420
+ {
421
+ name: 'Top Left',
422
+ value: 'top-left',
423
+ },
424
+ {
425
+ name: 'Top Right',
426
+ value: 'top-right',
427
+ },
428
+ ],
429
+ default: 'center',
430
+ description: 'Position of the text watermark on the page',
431
+ },
432
+ {
433
+ displayName: 'Rotation',
434
+ name: 'rotation',
435
+ type: 'number',
436
+ typeOptions: {
437
+ minValue: -180,
438
+ maxValue: 180,
439
+ },
440
+ default: 0,
441
+ description: 'Rotation angle in degrees (-180 to 180)',
442
+ },
443
+ ],
444
+ },
445
+ {
446
+ displayName: 'Image Watermark Options',
447
+ name: 'imageWatermarkOptions',
448
+ type: 'collection',
449
+ placeholder: 'Add Option',
450
+ default: {},
451
+ displayOptions: {
452
+ show: {
453
+ resource: ['pdfServices'],
454
+ pdfServicesOperation: ['addWatermark'],
455
+ watermarkType: ['image'],
456
+ },
457
+ },
458
+ description: 'Additional options for image watermark',
459
+ options: [
460
+ {
461
+ displayName: 'Position',
462
+ name: 'position',
463
+ type: 'options',
464
+ options: [
465
+ {
466
+ name: 'Bottom Center',
467
+ value: 'bottom-center',
468
+ },
469
+ {
470
+ name: 'Bottom Left',
471
+ value: 'bottom-left',
472
+ },
473
+ {
474
+ name: 'Bottom Right',
475
+ value: 'bottom-right',
476
+ },
477
+ {
478
+ name: 'Center',
479
+ value: 'center',
480
+ },
481
+ {
482
+ name: 'Center Left',
483
+ value: 'center-left',
484
+ },
485
+ {
486
+ name: 'Center Right',
487
+ value: 'center-right',
488
+ },
489
+ {
490
+ name: 'Top Center',
491
+ value: 'top-center',
492
+ },
493
+ {
494
+ name: 'Top Left',
495
+ value: 'top-left',
496
+ },
497
+ {
498
+ name: 'Top Right',
499
+ value: 'top-right',
500
+ },
501
+ ],
502
+ default: 'center',
503
+ description: 'Position of the image watermark on the page',
504
+ },
505
+ {
506
+ displayName: 'Rotation',
507
+ name: 'rotation',
508
+ type: 'number',
509
+ typeOptions: {
510
+ minValue: -180,
511
+ maxValue: 180,
512
+ },
513
+ default: 0,
514
+ description: 'Rotation angle in degrees (-180 to 180)',
515
+ },
516
+ {
517
+ displayName: 'Scale',
518
+ name: 'scale',
519
+ type: 'number',
520
+ typeOptions: {
521
+ minValue: 0.1,
522
+ maxValue: 5,
523
+ numberPrecision: 2,
524
+ },
525
+ default: 1,
526
+ description: 'Scale factor for the image watermark (0.1 to 5)',
527
+ },
528
+ ],
529
+ },
530
+ {
531
+ displayName: 'Owner Password',
532
+ name: 'ownerPassword',
533
+ type: 'string',
534
+ typeOptions: {
535
+ password: true,
536
+ },
537
+ displayOptions: {
538
+ show: {
539
+ resource: ['pdfServices'],
540
+ pdfServicesOperation: ['encrypt'],
541
+ },
542
+ },
543
+ default: '',
544
+ description: 'Owner password for full access to the PDF (optional but recommended)',
545
+ placeholder: 'Enter owner password',
546
+ },
547
+ {
548
+ displayName: 'User Password',
549
+ name: 'userPassword',
550
+ type: 'string',
551
+ typeOptions: {
552
+ password: true,
553
+ },
554
+ displayOptions: {
555
+ show: {
556
+ resource: ['pdfServices'],
557
+ pdfServicesOperation: ['encrypt'],
558
+ },
559
+ },
560
+ default: '',
561
+ description: 'User password for viewing the PDF (optional but recommended)',
562
+ placeholder: 'Enter user password',
563
+ },
564
+ {
565
+ displayName: 'Password',
566
+ name: 'decryptionPassword',
567
+ type: 'string',
568
+ typeOptions: {
569
+ password: true,
570
+ },
571
+ required: true,
572
+ displayOptions: {
573
+ show: {
574
+ resource: ['pdfServices'],
575
+ pdfServicesOperation: ['decrypt'],
576
+ },
577
+ },
578
+ default: '',
579
+ description: 'Password to decrypt the PDF document',
580
+ placeholder: 'Enter decryption password',
581
+ },
582
+ {
583
+ displayName: 'Form Fields Data',
584
+ name: 'formFieldsData',
585
+ type: 'json',
586
+ required: true,
587
+ displayOptions: {
588
+ show: {
589
+ resource: ['pdfServices'],
590
+ pdfServicesOperation: ['fillFormFields'],
591
+ },
592
+ },
593
+ default: '{}',
594
+ description: 'JSON object containing the form field names as keys and their values as data to fill in the PDF form',
595
+ placeholder: '{"firstName": "John", "lastName": "Doe", "email": "john.doe@example.com"}',
596
+ },
597
+ {
598
+ displayName: 'Public ID',
599
+ name: 'publicId',
600
+ type: 'string',
601
+ required: true,
602
+ displayOptions: {
603
+ show: {
604
+ resource: ['document'],
605
+ documentOperation: ['get', 'delete'],
606
+ },
607
+ },
608
+ default: '',
609
+ description: 'The public ID of the document',
610
+ },
611
+ {
612
+ displayName: 'List Options',
613
+ name: 'listOptions',
614
+ type: 'collection',
615
+ placeholder: 'Add Option',
616
+ default: {},
617
+ displayOptions: {
618
+ show: {
619
+ resource: ['document'],
620
+ documentOperation: ['list'],
621
+ },
622
+ },
623
+ options: [
624
+ {
625
+ displayName: 'End Date',
626
+ name: 'end_date',
627
+ type: 'string',
628
+ default: '',
629
+ description: 'End date filter (Format: Y-m-d H:i:s)',
630
+ },
631
+ {
632
+ displayName: 'Page',
633
+ name: 'page',
634
+ type: 'number',
635
+ typeOptions: {
636
+ minValue: 1,
637
+ },
638
+ default: 1,
639
+ description: 'Page number for pagination',
640
+ },
641
+ {
642
+ displayName: 'Per Page',
643
+ name: 'per_page',
644
+ type: 'number',
645
+ typeOptions: {
646
+ minValue: 1,
647
+ maxValue: 100,
648
+ },
649
+ default: 15,
650
+ description: 'Number of records per page',
651
+ },
652
+ {
653
+ displayName: 'Start Date',
654
+ name: 'start_date',
655
+ type: 'string',
656
+ default: '',
657
+ description: 'Start date filter (Format: Y-m-d H:i:s)',
658
+ },
659
+ {
660
+ displayName: 'Template ID',
661
+ name: 'template_id',
662
+ type: 'number',
663
+ default: '',
664
+ description: 'Filter by template ID',
665
+ },
666
+ ],
667
+ },
668
+ {
669
+ displayName: 'Templates',
670
+ name: 'templates',
671
+ type: 'fixedCollection',
672
+ required: true,
673
+ displayOptions: {
674
+ show: {
675
+ resource: ['document'],
676
+ documentOperation: ['generateBatch', 'generateBatchAsync'],
677
+ },
678
+ },
679
+ default: { templateList: [{}] },
680
+ typeOptions: {
681
+ multipleValues: true,
682
+ },
683
+ options: [
684
+ {
685
+ displayName: 'Template',
686
+ name: 'templateList',
687
+ values: [
688
+ {
689
+ displayName: 'Template',
690
+ name: 'templateId',
691
+ type: 'resourceLocator',
692
+ default: { mode: 'list', value: '' },
693
+ required: true,
694
+ modes: [
695
+ {
696
+ displayName: 'From List',
697
+ name: 'list',
698
+ type: 'list',
699
+ placeholder: 'Select a template...',
700
+ typeOptions: {
701
+ searchListMethod: 'searchTemplates',
702
+ searchable: true,
703
+ },
704
+ },
705
+ {
706
+ displayName: 'By ID',
707
+ name: 'id',
708
+ type: 'string',
709
+ validation: [
710
+ {
711
+ type: 'regex',
712
+ properties: {
713
+ regex: '^[0-9]+$',
714
+ errorMessage: 'Template ID must be a number',
715
+ },
716
+ },
717
+ ],
718
+ placeholder: 'e.g. 12345',
719
+ },
720
+ ],
721
+ },
722
+ {
723
+ displayName: 'Data',
724
+ name: 'data',
725
+ type: 'json',
726
+ required: true,
727
+ default: '{}',
728
+ description: 'JSON data to merge with the template',
729
+ },
730
+ ],
731
+ },
732
+ ],
733
+ },
734
+ {
735
+ displayName: 'Callback Options',
736
+ name: 'callbackOptions',
737
+ type: 'collection',
738
+ placeholder: 'Add Option',
739
+ default: {},
740
+ displayOptions: {
741
+ show: {
742
+ resource: ['document'],
743
+ documentOperation: ['generateAsync', 'generateBatchAsync'],
744
+ },
745
+ },
746
+ options: [
747
+ {
748
+ displayName: 'Callback URL',
749
+ name: 'url',
750
+ type: 'string',
751
+ default: '',
752
+ description: 'URL to receive the callback when generation is complete',
753
+ },
754
+ {
755
+ displayName: 'Custom Headers',
756
+ name: 'headers',
757
+ type: 'json',
758
+ default: '{}',
759
+ description: 'Custom headers to include in the callback request',
760
+ },
761
+ ],
762
+ },
763
+ {
764
+ displayName: 'Operation',
765
+ name: 'operation',
766
+ type: 'options',
767
+ noDataExpression: true,
768
+ displayOptions: {
769
+ show: {
770
+ resource: ['template'],
771
+ },
772
+ },
773
+ options: [
774
+ {
775
+ name: 'Copy',
776
+ value: 'copy',
777
+ description: 'Copy a template',
778
+ action: 'Copy a template',
779
+ },
780
+ {
781
+ name: 'Create',
782
+ value: 'create',
783
+ description: 'Create a new template',
784
+ action: 'Create a new template',
785
+ },
786
+ {
787
+ name: 'Delete',
788
+ value: 'delete',
789
+ description: 'Delete a template',
790
+ action: 'Delete a template',
791
+ },
792
+ {
793
+ name: 'Get',
794
+ value: 'get',
795
+ description: 'Get a template by ID',
796
+ action: 'Get a template by ID',
797
+ },
798
+ {
799
+ name: 'Get Data Fields',
800
+ value: 'getDataFields',
801
+ description: 'Get template data fields',
802
+ action: 'Get template data fields',
803
+ },
804
+ {
805
+ name: 'List',
806
+ value: 'list',
807
+ description: 'Get all templates',
808
+ action: 'Get all templates',
809
+ },
810
+ {
811
+ name: 'Open Editor',
812
+ value: 'openEditor',
813
+ description: 'Get template editor URL',
814
+ action: 'Get template editor URL',
815
+ },
816
+ {
817
+ name: 'Update',
818
+ value: 'update',
819
+ description: 'Update an existing template',
820
+ action: 'Update an existing template',
821
+ },
822
+ {
823
+ name: 'Validate',
824
+ value: 'validate',
825
+ description: 'Validate template configuration',
826
+ action: 'Validate template configuration',
827
+ },
828
+ ],
829
+ default: 'list',
830
+ },
831
+ {
832
+ displayName: 'Template',
833
+ name: 'templateId',
834
+ type: 'resourceLocator',
835
+ default: { mode: 'list', value: '' },
836
+ required: true,
837
+ displayOptions: {
838
+ show: {
839
+ resource: ['document'],
840
+ documentOperation: ['generate', 'generateAsync'],
841
+ },
842
+ },
843
+ modes: [
844
+ {
845
+ displayName: 'From List',
846
+ name: 'list',
847
+ type: 'list',
848
+ hint: 'Select a template from the list',
849
+ typeOptions: {
850
+ searchListMethod: 'searchTemplates',
851
+ searchable: true,
852
+ searchFilterRequired: false,
853
+ },
854
+ },
855
+ {
856
+ displayName: 'By ID',
857
+ name: 'id',
858
+ type: 'string',
859
+ hint: 'Enter the template ID directly',
860
+ validation: [
861
+ {
862
+ type: 'regex',
863
+ properties: {
864
+ regex: '^[0-9]+$',
865
+ errorMessage: 'Template ID must be a number',
866
+ },
867
+ },
868
+ ],
869
+ },
870
+ ],
871
+ description: 'Select the template to use for PDF generation',
872
+ },
873
+ {
874
+ displayName: 'Template',
875
+ name: 'templateId',
876
+ type: 'resourceLocator',
877
+ default: { mode: 'list', value: '' },
878
+ required: true,
879
+ displayOptions: {
880
+ show: {
881
+ resource: ['template'],
882
+ operation: ['get', 'update', 'delete', 'getDataFields', 'copy', 'openEditor'],
883
+ },
884
+ },
885
+ modes: [
886
+ {
887
+ displayName: 'From List',
888
+ name: 'list',
889
+ type: 'list',
890
+ hint: 'Select a template from the list',
891
+ typeOptions: {
892
+ searchListMethod: 'searchTemplates',
893
+ searchable: true,
894
+ searchFilterRequired: false,
895
+ },
896
+ },
897
+ {
898
+ displayName: 'By ID',
899
+ name: 'id',
900
+ type: 'string',
901
+ hint: 'Enter the template ID directly',
902
+ validation: [
903
+ {
904
+ type: 'regex',
905
+ properties: {
906
+ regex: '^[0-9]+$',
907
+ errorMessage: 'Template ID must be a number',
908
+ },
909
+ },
910
+ ],
911
+ },
912
+ ],
913
+ description: 'Select the template to work with',
914
+ },
915
+ {
916
+ displayName: 'Output ID',
917
+ name: 'outputId',
918
+ type: 'string',
919
+ required: true,
920
+ displayOptions: {
921
+ show: {
922
+ resource: ['document'],
923
+ documentOperation: ['getOutput'],
924
+ },
925
+ },
926
+ default: '',
927
+ description: 'The ID of the async generation output',
928
+ },
929
+ {
930
+ displayName: 'Data',
931
+ name: 'data',
932
+ type: 'json',
933
+ required: true,
934
+ displayOptions: {
935
+ show: {
936
+ resource: ['document'],
937
+ documentOperation: ['generate', 'generateAsync'],
938
+ },
939
+ },
940
+ default: '{}',
941
+ description: 'JSON data to merge with the template',
942
+ },
943
+ {
944
+ displayName: 'Format',
945
+ name: 'format',
946
+ type: 'options',
947
+ displayOptions: {
948
+ show: {
949
+ resource: ['document'],
950
+ documentOperation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
951
+ },
952
+ },
953
+ options: [
954
+ {
955
+ name: 'PDF',
956
+ value: 'pdf',
957
+ },
958
+ {
959
+ name: 'HTML',
960
+ value: 'html',
961
+ },
962
+ {
963
+ name: 'ZIP',
964
+ value: 'zip',
965
+ },
966
+ {
967
+ name: 'XLSX',
968
+ value: 'xlsx',
969
+ },
970
+ ],
971
+ default: 'pdf',
972
+ description: 'Document format. ZIP option returns a ZIP file with PDF files.',
973
+ },
974
+ {
975
+ displayName: 'Output',
976
+ name: 'output',
977
+ type: 'options',
978
+ displayOptions: {
979
+ show: {
980
+ resource: ['document'],
981
+ documentOperation: ['generate', 'generateBatch'],
982
+ },
983
+ },
984
+ options: [
985
+ {
986
+ name: 'Base64',
987
+ value: 'base64',
988
+ },
989
+ {
990
+ name: 'File',
991
+ value: 'file',
992
+ },
993
+ {
994
+ name: 'URL',
995
+ value: 'url',
996
+ },
997
+ ],
998
+ default: 'base64',
999
+ description: 'Response format. File option returns the file inline. URL option stores document for 30 days.',
1000
+ },
1001
+ {
1002
+ displayName: 'Output',
1003
+ name: 'output',
1004
+ type: 'options',
1005
+ displayOptions: {
1006
+ show: {
1007
+ resource: ['document'],
1008
+ documentOperation: ['generateAsync', 'generateBatchAsync'],
1009
+ },
1010
+ },
1011
+ options: [
1012
+ {
1013
+ name: 'Base64',
1014
+ value: 'base64',
1015
+ },
1016
+ {
1017
+ name: 'URL',
1018
+ value: 'url',
1019
+ },
1020
+ ],
1021
+ default: 'base64',
1022
+ description: 'Response format. URL option stores document for 30 days.',
1023
+ },
1024
+ {
1025
+ displayName: 'Additional Fields',
1026
+ name: 'additionalFields',
1027
+ type: 'collection',
1028
+ placeholder: 'Add Field',
1029
+ default: {},
1030
+ displayOptions: {
1031
+ show: {
1032
+ resource: ['document'],
1033
+ documentOperation: ['generate', 'generateAsync', 'generateBatch', 'generateBatchAsync'],
1034
+ },
1035
+ },
1036
+ options: [
1037
+ {
1038
+ displayName: 'Output Name',
1039
+ name: 'outputName',
1040
+ type: 'string',
1041
+ default: '',
1042
+ description: 'Generated document name (optional)',
1043
+ },
1044
+ {
1045
+ displayName: 'Testing',
1046
+ name: 'testing',
1047
+ type: 'boolean',
1048
+ default: false,
1049
+ description: 'Whether to use testing mode (generation is not counted but a large PREVIEW stamp is added)',
1050
+ },
1051
+ ],
1052
+ },
1053
+ {
1054
+ displayName: 'Template Configuration JSON',
1055
+ name: 'templateConfiguration',
1056
+ type: 'json',
1057
+ required: true,
1058
+ displayOptions: {
1059
+ show: {
1060
+ resource: ['template'],
1061
+ operation: ['create', 'update'],
1062
+ },
1063
+ },
1064
+ default: '{\n "name": "My Template",\n "tags": [],\n "isDraft": true,\n "layout": {\n "format": "A4",\n "unit": "cm",\n "orientation": "portrait",\n "rotation": 0,\n "margins": {\n "top": 0,\n "left": 0,\n "right": 0,\n "bottom": 0\n },\n "emptyLabels": 0,\n "width": 21,\n "height": 29.7,\n "repeatLayout": null\n },\n "pages": [\n {\n "width": 21,\n "height": 29.7,\n "conditionalFormats": [],\n "backgroundImage": null,\n "layout": [],\n "components": [],\n "margins": {\n "right": 0,\n "bottom": 0\n },\n "border": false\n }\n ],\n "dataSettings": {\n "sortBy": [],\n "filterBy": [],\n "transform": []\n },\n "editor": {\n "heightMultiplier": 1\n },\n "fontSubsetting": false,\n "barcodeAsImage": false\n}',
1065
+ description: 'The complete template configuration JSON object - provide the template object directly, NOT wrapped in another object. Must include: name, layout, pages array, dataSettings, editor objects. Example: {"name": "My Template", "layout": {...}, "pages": [...], "dataSettings": {...}, "editor": {...}}',
1066
+ },
1067
+ {
1068
+ displayName: 'Template Configuration JSON',
1069
+ name: 'templateConfig',
1070
+ type: 'json',
1071
+ required: true,
1072
+ displayOptions: {
1073
+ show: {
1074
+ resource: ['template'],
1075
+ operation: ['validate'],
1076
+ },
1077
+ },
1078
+ default: '{\n "name": "My Template",\n "tags": [],\n "isDraft": true,\n "layout": {\n "format": "A4",\n "unit": "cm",\n "orientation": "portrait",\n "rotation": 0,\n "margins": {\n "top": 0,\n "left": 0,\n "right": 0,\n "bottom": 0\n },\n "emptyLabels": 0,\n "width": 21,\n "height": 29.7,\n "repeatLayout": null\n },\n "pages": [\n {\n "width": 21,\n "height": 29.7,\n "conditionalFormats": [],\n "backgroundImage": null,\n "layout": [],\n "components": [],\n "margins": {\n "right": 0,\n "bottom": 0\n },\n "border": false\n }\n ],\n "dataSettings": {\n "sortBy": [],\n "filterBy": [],\n "transform": []\n },\n "editor": {\n "heightMultiplier": 1\n },\n "fontSubsetting": false,\n "barcodeAsImage": false\n}',
1079
+ description: 'Template configuration JSON to validate - provide the template object directly, NOT wrapped in another object. Must include: name, layout, pages array, dataSettings, editor objects. Example: {"name": "My Template", "layout": {...}, "pages": [...], "dataSettings": {...}, "editor": {...}}',
1080
+ },
1081
+ {
1082
+ displayName: 'New Template Name',
1083
+ name: 'newTemplateName',
1084
+ type: 'string',
1085
+ displayOptions: {
1086
+ show: {
1087
+ resource: ['template'],
1088
+ operation: ['copy'],
1089
+ },
1090
+ },
1091
+ default: '',
1092
+ description: 'Name for the copied template. If not provided, original name is used.',
1093
+ },
1094
+ {
1095
+ displayName: 'Editor Options',
1096
+ name: 'editorOptions',
1097
+ type: 'collection',
1098
+ placeholder: 'Add Option',
1099
+ default: {},
1100
+ displayOptions: {
1101
+ show: {
1102
+ resource: ['template'],
1103
+ operation: ['openEditor'],
1104
+ },
1105
+ },
1106
+ options: [
1107
+ {
1108
+ displayName: 'Data',
1109
+ name: 'data',
1110
+ type: 'json',
1111
+ default: '{}',
1112
+ description: 'Data used to preview the template in the editor',
1113
+ },
1114
+ {
1115
+ displayName: 'Language',
1116
+ name: 'language',
1117
+ type: 'options',
1118
+ options: [
1119
+ { name: 'Czech', value: 'cs' },
1120
+ { name: 'English', value: 'en' },
1121
+ { name: 'Estonian', value: 'et' },
1122
+ { name: 'German', value: 'de' },
1123
+ { name: 'Russian', value: 'ru' },
1124
+ { name: 'Slovak', value: 'sk' },
1125
+ ],
1126
+ default: 'en',
1127
+ description: 'Editor UI language',
1128
+ },
1129
+ ],
1130
+ },
1131
+ {
1132
+ displayName: 'List Options',
1133
+ name: 'listOptions',
1134
+ type: 'collection',
1135
+ placeholder: 'Add Option',
1136
+ default: {},
1137
+ displayOptions: {
1138
+ show: {
1139
+ resource: ['template'],
1140
+ operation: ['list'],
1141
+ },
1142
+ },
1143
+ options: [
1144
+ {
1145
+ displayName: 'Access Type',
1146
+ name: 'access',
1147
+ type: 'options',
1148
+ options: [
1149
+ { name: 'All', value: '' },
1150
+ { name: 'Organization', value: 'organization' },
1151
+ { name: 'Private', value: 'private' },
1152
+ ],
1153
+ default: '',
1154
+ description: 'Filter templates by access type',
1155
+ },
1156
+ {
1157
+ displayName: 'Name Filter',
1158
+ name: 'name',
1159
+ type: 'string',
1160
+ default: '',
1161
+ description: 'Filter templates by name',
1162
+ },
1163
+ {
1164
+ displayName: 'Page',
1165
+ name: 'page',
1166
+ type: 'number',
1167
+ default: 1,
1168
+ description: 'Page number to return',
1169
+ },
1170
+ {
1171
+ displayName: 'Per Page',
1172
+ name: 'per_page',
1173
+ type: 'number',
1174
+ default: 15,
1175
+ description: 'Number of records to return per page (max 100)',
1176
+ },
1177
+ {
1178
+ displayName: 'Tags Filter',
1179
+ name: 'tags',
1180
+ type: 'string',
1181
+ default: '',
1182
+ description: 'Filter templates by tags',
1183
+ },
1184
+ ],
1185
+ },
1186
+ {
1187
+ displayName: 'Operation',
1188
+ name: 'operation',
1189
+ type: 'options',
1190
+ noDataExpression: true,
1191
+ displayOptions: {
1192
+ show: {
1193
+ resource: ['workspace'],
1194
+ },
1195
+ },
1196
+ options: [
1197
+ {
1198
+ name: 'Create',
1199
+ value: 'create',
1200
+ description: 'Create a new workspace',
1201
+ action: 'Create a new workspace',
1202
+ },
1203
+ {
1204
+ name: 'Delete',
1205
+ value: 'delete',
1206
+ description: 'Delete a workspace',
1207
+ action: 'Delete a workspace',
1208
+ },
1209
+ {
1210
+ name: 'Get',
1211
+ value: 'get',
1212
+ description: 'Get workspace by identifier',
1213
+ action: 'Get workspace by identifier',
1214
+ },
1215
+ {
1216
+ name: 'List',
1217
+ value: 'list',
1218
+ description: 'Get all workspaces',
1219
+ action: 'Get all workspaces',
1220
+ },
1221
+ ],
1222
+ default: 'list',
1223
+ },
1224
+ {
1225
+ displayName: 'List Options',
1226
+ name: 'listOptions',
1227
+ type: 'collection',
1228
+ placeholder: 'Add Option',
1229
+ default: {},
1230
+ displayOptions: {
1231
+ show: {
1232
+ resource: ['workspace'],
1233
+ operation: ['list'],
1234
+ },
1235
+ },
1236
+ options: [
1237
+ {
1238
+ displayName: 'Page',
1239
+ name: 'page',
1240
+ type: 'number',
1241
+ typeOptions: {
1242
+ minValue: 1,
1243
+ },
1244
+ default: 1,
1245
+ description: 'Page number for pagination',
1246
+ },
1247
+ {
1248
+ displayName: 'Per Page',
1249
+ name: 'per_page',
1250
+ type: 'number',
1251
+ typeOptions: {
1252
+ minValue: 1,
1253
+ maxValue: 100,
1254
+ },
1255
+ default: 15,
1256
+ description: 'Number of records per page',
1257
+ },
1258
+ ],
1259
+ },
1260
+ {
1261
+ displayName: 'Workspace Identifier',
1262
+ name: 'workspaceIdentifier',
1263
+ type: 'string',
1264
+ required: true,
1265
+ displayOptions: {
1266
+ show: {
1267
+ resource: ['workspace'],
1268
+ operation: ['get', 'delete'],
1269
+ },
1270
+ },
1271
+ default: '',
1272
+ description: 'The workspace identifier (e.g., user.example@domain.com)',
1273
+ },
1274
+ {
1275
+ displayName: 'Identifier',
1276
+ name: 'identifier',
1277
+ type: 'string',
1278
+ required: true,
1279
+ displayOptions: {
1280
+ show: {
1281
+ resource: ['workspace'],
1282
+ operation: ['create'],
1283
+ },
1284
+ },
1285
+ default: '',
1286
+ description: 'A unique identifier for the new workspace',
1287
+ },
1288
+ {
1289
+ displayName: 'HTML Content',
1290
+ name: 'htmlContent',
1291
+ type: 'string',
1292
+ typeOptions: {
1293
+ rows: 10,
1294
+ validation: [
1295
+ {
1296
+ type: 'minLength',
1297
+ properties: {
1298
+ minLength: 10,
1299
+ errorMessage: 'HTML content must be at least 10 characters long',
1300
+ },
1301
+ },
1302
+ ],
1303
+ },
1304
+ required: true,
1305
+ displayOptions: {
1306
+ show: {
1307
+ resource: ['conversion'],
1308
+ conversionOperation: ['htmlToPdf'],
1309
+ },
1310
+ },
1311
+ default: `<!DOCTYPE html>
1312
+ <html lang="en">
1313
+ <head>
1314
+ <meta charset="UTF-8">
1315
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
1316
+ <title>Sample PDF Document</title>
1317
+ <style>
1318
+ body {
1319
+ font-family: Arial, sans-serif;
1320
+ margin: 40px;
1321
+ line-height: 1.6;
1322
+ }
1323
+ h1 {
1324
+ color: #333;
1325
+ border-bottom: 2px solid #007acc;
1326
+ padding-bottom: 10px;
1327
+ }
1328
+ h2 {
1329
+ color: #555;
1330
+ margin-top: 30px;
1331
+ }
1332
+ .highlight {
1333
+ background-color: #f0f8ff;
1334
+ padding: 15px;
1335
+ border-left: 4px solid #007acc;
1336
+ margin: 20px 0;
1337
+ }
1338
+ table {
1339
+ width: 100%;
1340
+ border-collapse: collapse;
1341
+ margin: 20px 0;
1342
+ }
1343
+ th, td {
1344
+ border: 1px solid #ddd;
1345
+ padding: 12px;
1346
+ text-align: left;
1347
+ }
1348
+ th {
1349
+ background-color: #f2f2f2;
1350
+ }
1351
+ </style>
1352
+ </head>
1353
+ <body>
1354
+ <h1>Sample PDF Document</h1>
1355
+
1356
+ <p>This is a sample HTML document that will be converted to PDF. You can customize this content with your own HTML, CSS, and data.</p>
1357
+
1358
+ <div class="highlight">
1359
+ <strong>Tip:</strong> You can use CSS styles to format your PDF output with fonts, colors, layouts, and more.
1360
+ </div>
1361
+
1362
+ <h2>Features</h2>
1363
+ <ul>
1364
+ <li>Custom fonts and styling</li>
1365
+ <li>Tables and layouts</li>
1366
+ <li>Images and graphics</li>
1367
+ <li>Professional formatting</li>
1368
+ </ul>
1369
+
1370
+ <h2>Sample Table</h2>
1371
+ <table>
1372
+ <thead>
1373
+ <tr>
1374
+ <th>Item</th>
1375
+ <th>Description</th>
1376
+ <th>Price</th>
1377
+ </tr>
1378
+ </thead>
1379
+ <tbody>
1380
+ <tr>
1381
+ <td>Product A</td>
1382
+ <td>High-quality product</td>
1383
+ <td>$29.99</td>
1384
+ </tr>
1385
+ <tr>
1386
+ <td>Product B</td>
1387
+ <td>Premium service</td>
1388
+ <td>$49.99</td>
1389
+ </tr>
1390
+ </tbody>
1391
+ </table>
1392
+
1393
+ <p><em>Replace this content with your own HTML to generate custom PDFs.</em></p>
1394
+ </body>
1395
+ </html>`,
1396
+ description: 'HTML content to convert to PDF. You can replace this sample with your own HTML.',
1397
+ },
1398
+ {
1399
+ displayName: 'URL',
1400
+ name: 'url',
1401
+ type: 'string',
1402
+ typeOptions: {
1403
+ validation: [
1404
+ {
1405
+ type: 'regex',
1406
+ properties: {
1407
+ regex: '^https?:\\/\\/.+',
1408
+ errorMessage: 'Please enter a valid URL starting with http:// or https://',
1409
+ },
1410
+ },
1411
+ ],
1412
+ },
1413
+ required: true,
1414
+ displayOptions: {
1415
+ show: {
1416
+ resource: ['conversion'],
1417
+ conversionOperation: ['urlToPdf'],
1418
+ },
1419
+ },
1420
+ default: '',
1421
+ description: 'Public URL to convert to PDF',
1422
+ placeholder: 'https://example.com',
1423
+ },
1424
+ {
1425
+ displayName: 'Filename',
1426
+ name: 'filename',
1427
+ type: 'string',
1428
+ typeOptions: {
1429
+ validation: [
1430
+ {
1431
+ type: 'minLength',
1432
+ properties: {
1433
+ minLength: 1,
1434
+ errorMessage: 'Filename cannot be empty',
1435
+ },
1436
+ },
1437
+ {
1438
+ type: 'regex',
1439
+ properties: {
1440
+ regex: '^[a-zA-Z0-9._-]+$',
1441
+ errorMessage: 'Filename can only contain letters, numbers, dots, hyphens, and underscores',
1442
+ },
1443
+ },
1444
+ ],
1445
+ },
1446
+ required: true,
1447
+ displayOptions: {
1448
+ show: {
1449
+ resource: ['conversion'],
1450
+ },
1451
+ },
1452
+ default: 'document',
1453
+ description: 'Filename for the generated PDF (without .pdf extension)',
1454
+ placeholder: 'my-document',
1455
+ },
1456
+ {
1457
+ displayName: 'Additional Options',
1458
+ name: 'conversionOptions',
1459
+ type: 'collection',
1460
+ placeholder: 'Add Option',
1461
+ default: {},
1462
+ displayOptions: {
1463
+ show: {
1464
+ resource: ['conversion'],
1465
+ },
1466
+ },
1467
+ options: [
1468
+ {
1469
+ displayName: 'Paper Size',
1470
+ name: 'paper_size',
1471
+ type: 'options',
1472
+ options: [
1473
+ {
1474
+ name: 'A0',
1475
+ value: 'a0',
1476
+ },
1477
+ {
1478
+ name: 'A1',
1479
+ value: 'a1',
1480
+ },
1481
+ {
1482
+ name: 'A2',
1483
+ value: 'a2',
1484
+ },
1485
+ {
1486
+ name: 'A3',
1487
+ value: 'a3',
1488
+ },
1489
+ {
1490
+ name: 'A4',
1491
+ value: 'a4',
1492
+ },
1493
+ {
1494
+ name: 'Legal',
1495
+ value: 'legal',
1496
+ },
1497
+ {
1498
+ name: 'Letter',
1499
+ value: 'letter',
1500
+ },
1501
+ {
1502
+ name: 'Tabloid',
1503
+ value: 'tabloid',
1504
+ },
1505
+ ],
1506
+ default: 'a4',
1507
+ description: 'PDF page size',
1508
+ },
1509
+ {
1510
+ displayName: 'Orientation',
1511
+ name: 'orientation',
1512
+ type: 'options',
1513
+ options: [
1514
+ {
1515
+ name: 'Portrait',
1516
+ value: 'portrait',
1517
+ },
1518
+ {
1519
+ name: 'Landscape',
1520
+ value: 'landscape',
1521
+ },
1522
+ ],
1523
+ default: 'portrait',
1524
+ description: 'Page orientation',
1525
+ },
1526
+ {
1527
+ displayName: 'Output Format',
1528
+ name: 'output',
1529
+ type: 'options',
1530
+ options: [
1531
+ {
1532
+ name: 'Base64 (JSON)',
1533
+ value: 'base64',
1534
+ description: 'Returns JSON response with base64 string',
1535
+ },
1536
+ {
1537
+ name: 'File (Binary)',
1538
+ value: 'file',
1539
+ description: 'Returns binary file data for download/attachment',
1540
+ },
1541
+ ],
1542
+ default: 'base64',
1543
+ description: 'Choose output format: JSON with base64 string or binary file',
1544
+ },
1545
+ ],
1546
+ },
1547
+ ],
1548
+ };
1549
+ this.methods = {
1550
+ listSearch: {
1551
+ async searchTemplates(filter) {
1552
+ const returnData = [];
1553
+ try {
1554
+ const credentials = await this.getCredentials('pdfGeneratorApi');
1555
+ const baseURL = credentials.baseUrl || 'https://us1.pdfgeneratorapi.com/api/v4';
1556
+ const options = {
1557
+ method: 'GET',
1558
+ baseURL,
1559
+ url: '/templates',
1560
+ qs: {
1561
+ per_page: 100,
1562
+ ...(filter && { name: filter }),
1563
+ },
1564
+ json: true,
1565
+ };
1566
+ const response = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1567
+ if (response && response.response) {
1568
+ for (const template of response.response) {
1569
+ const displayName = `${template.name} (ID: ${template.id})`;
1570
+ if (!filter || displayName.toLowerCase().includes(filter.toLowerCase())) {
1571
+ returnData.push({
1572
+ name: displayName,
1573
+ value: template.id.toString(),
1574
+ });
1575
+ }
1576
+ }
1577
+ }
1578
+ }
1579
+ catch (error) {
1580
+ console.error('Failed to load templates:', error);
1581
+ }
1582
+ const sortedResults = returnData.sort((a, b) => a.name.localeCompare(b.name));
1583
+ return {
1584
+ results: sortedResults,
1585
+ };
1586
+ },
1587
+ },
1588
+ };
1589
+ }
1590
+ async execute() {
1591
+ const items = this.getInputData();
1592
+ const returnData = [];
1593
+ const resource = this.getNodeParameter('resource', 0);
1594
+ let operation;
1595
+ switch (resource) {
1596
+ case 'conversion':
1597
+ operation = this.getNodeParameter('conversionOperation', 0);
1598
+ break;
1599
+ case 'document':
1600
+ operation = this.getNodeParameter('documentOperation', 0);
1601
+ break;
1602
+ case 'pdfServices':
1603
+ operation = this.getNodeParameter('pdfServicesOperation', 0);
1604
+ break;
1605
+ case 'template':
1606
+ case 'workspace':
1607
+ default:
1608
+ operation = this.getNodeParameter('operation', 0);
1609
+ }
1610
+ const credentials = await this.getCredentials('pdfGeneratorApi');
1611
+ const baseURL = credentials.baseUrl || 'https://us1.pdfgeneratorapi.com/api/v4';
1612
+ for (let i = 0; i < items.length; i++) {
1613
+ try {
1614
+ let responseData;
1615
+ if (resource === 'conversion') {
1616
+ const conversionOptions = this.getNodeParameter('conversionOptions', i, {});
1617
+ const filename = this.getNodeParameter('filename', i);
1618
+ if (!filename || filename.trim() === '') {
1619
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Filename is required for conversion operations', { itemIndex: i });
1620
+ }
1621
+ if (operation === 'htmlToPdf') {
1622
+ const htmlContent = this.getNodeParameter('htmlContent', i);
1623
+ if (!htmlContent || htmlContent.trim() === '') {
1624
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'HTML Content is required for HTML to PDF conversion', { itemIndex: i });
1625
+ }
1626
+ if (htmlContent.length < 10) {
1627
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'HTML Content must be at least 10 characters long', { itemIndex: i });
1628
+ }
1629
+ }
1630
+ if (operation === 'urlToPdf') {
1631
+ const url = this.getNodeParameter('url', i);
1632
+ if (!url || url.trim() === '') {
1633
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'URL is required for URL to PDF conversion', { itemIndex: i });
1634
+ }
1635
+ if (!url.match(/^https?:\/\/.+/)) {
1636
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Please enter a valid URL starting with http:// or https://', { itemIndex: i });
1637
+ }
1638
+ }
1639
+ const body = {
1640
+ paper_size: conversionOptions.paper_size || 'a4',
1641
+ orientation: conversionOptions.orientation || 'portrait',
1642
+ output: conversionOptions.output || 'base64',
1643
+ filename: filename || 'document',
1644
+ };
1645
+ if (operation === 'htmlToPdf') {
1646
+ const htmlContent = this.getNodeParameter('htmlContent', i);
1647
+ body.content = htmlContent;
1648
+ const options = {
1649
+ method: 'POST',
1650
+ baseURL,
1651
+ url: '/conversion/html2pdf',
1652
+ body,
1653
+ json: body.output !== 'file',
1654
+ encoding: body.output === 'file' ? null : 'utf8',
1655
+ };
1656
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1657
+ }
1658
+ else if (operation === 'urlToPdf') {
1659
+ const url = this.getNodeParameter('url', i);
1660
+ body.url = url;
1661
+ const options = {
1662
+ method: 'POST',
1663
+ baseURL,
1664
+ url: '/conversion/url2pdf',
1665
+ body,
1666
+ json: body.output !== 'file',
1667
+ encoding: body.output === 'file' ? null : 'utf8',
1668
+ };
1669
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1670
+ }
1671
+ if (responseData) {
1672
+ const outputFormat = body.output || 'base64';
1673
+ if (outputFormat === 'file') {
1674
+ const binaryData = {};
1675
+ const fileName = `${filename}.pdf`;
1676
+ const binaryBuffer = Buffer.isBuffer(responseData) ? responseData : Buffer.from(responseData);
1677
+ console.log(`Raw PDF buffer size: ${binaryBuffer.length} bytes`);
1678
+ binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
1679
+ returnData.push({
1680
+ json: {
1681
+ success: true,
1682
+ filename: `${filename}.pdf`,
1683
+ format: outputFormat,
1684
+ fileSize: binaryBuffer.length,
1685
+ },
1686
+ binary: binaryData,
1687
+ });
1688
+ }
1689
+ else {
1690
+ returnData.push({
1691
+ json: {
1692
+ success: true,
1693
+ filename: `${filename}.pdf`,
1694
+ format: outputFormat,
1695
+ ...responseData,
1696
+ },
1697
+ });
1698
+ }
1699
+ continue;
1700
+ }
1701
+ }
1702
+ else if (resource === 'document') {
1703
+ if (operation === 'list') {
1704
+ const listOptions = this.getNodeParameter('listOptions', i, {});
1705
+ const qs = {};
1706
+ if (listOptions.template_id)
1707
+ qs.template_id = listOptions.template_id;
1708
+ if (listOptions.start_date)
1709
+ qs.start_date = listOptions.start_date;
1710
+ if (listOptions.end_date)
1711
+ qs.end_date = listOptions.end_date;
1712
+ if (listOptions.page)
1713
+ qs.page = listOptions.page;
1714
+ if (listOptions.per_page)
1715
+ qs.per_page = listOptions.per_page;
1716
+ const options = {
1717
+ method: 'GET',
1718
+ baseURL,
1719
+ url: '/documents',
1720
+ qs,
1721
+ json: true,
1722
+ };
1723
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1724
+ }
1725
+ else if (operation === 'get') {
1726
+ const publicId = this.getNodeParameter('publicId', i);
1727
+ const options = {
1728
+ method: 'GET',
1729
+ baseURL,
1730
+ url: `/documents/${publicId}`,
1731
+ json: true,
1732
+ };
1733
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1734
+ }
1735
+ else if (operation === 'delete') {
1736
+ const publicId = this.getNodeParameter('publicId', i);
1737
+ const options = {
1738
+ method: 'DELETE',
1739
+ baseURL,
1740
+ url: `/documents/${publicId}`,
1741
+ json: true,
1742
+ };
1743
+ await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1744
+ responseData = {
1745
+ success: true,
1746
+ message: 'Document deleted successfully',
1747
+ publicId: publicId,
1748
+ };
1749
+ }
1750
+ else if (operation === 'generate') {
1751
+ const templateIdParam = this.getNodeParameter('templateId', i);
1752
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
1753
+ const data = this.getNodeParameter('data', i);
1754
+ const format = this.getNodeParameter('format', i, 'pdf');
1755
+ const output = this.getNodeParameter('output', i, 'base64');
1756
+ const additionalFields = this.getNodeParameter('additionalFields', i, {});
1757
+ const body = {
1758
+ template: {
1759
+ id: templateId,
1760
+ data: JSON.parse(data),
1761
+ },
1762
+ format,
1763
+ output,
1764
+ };
1765
+ if (additionalFields.outputName)
1766
+ body.name = additionalFields.outputName;
1767
+ if (additionalFields.testing !== undefined)
1768
+ body.testing = additionalFields.testing;
1769
+ const options = {
1770
+ method: 'POST',
1771
+ baseURL,
1772
+ url: '/documents/generate',
1773
+ body,
1774
+ json: output !== 'file',
1775
+ encoding: output === 'file' ? null : 'utf8',
1776
+ };
1777
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1778
+ if (responseData && output !== 'url') {
1779
+ if (output === 'file') {
1780
+ const binaryData = {};
1781
+ const fileName = `${additionalFields.outputName || 'document'}.${format}`;
1782
+ const binaryBuffer = Buffer.isBuffer(responseData) ? responseData : Buffer.from(responseData);
1783
+ binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, format === 'pdf' ? 'application/pdf' : `application/${format}`);
1784
+ returnData.push({
1785
+ json: {
1786
+ success: true,
1787
+ filename: fileName,
1788
+ format: output,
1789
+ fileSize: binaryBuffer.length,
1790
+ },
1791
+ binary: binaryData,
1792
+ });
1793
+ continue;
1794
+ }
1795
+ else {
1796
+ returnData.push({
1797
+ json: {
1798
+ success: true,
1799
+ filename: `${additionalFields.outputName || 'document'}.${format}`,
1800
+ format: output,
1801
+ ...responseData,
1802
+ },
1803
+ });
1804
+ continue;
1805
+ }
1806
+ }
1807
+ }
1808
+ else if (operation === 'generateAsync') {
1809
+ const templateIdParam = this.getNodeParameter('templateId', i);
1810
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
1811
+ const data = this.getNodeParameter('data', i);
1812
+ const format = this.getNodeParameter('format', i, 'pdf');
1813
+ const output = this.getNodeParameter('output', i, 'base64');
1814
+ const additionalFields = this.getNodeParameter('additionalFields', i, {});
1815
+ const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
1816
+ const body = {
1817
+ template: {
1818
+ id: templateId,
1819
+ data: JSON.parse(data),
1820
+ },
1821
+ format,
1822
+ output,
1823
+ };
1824
+ if (callbackOptions.url) {
1825
+ body.callback = {
1826
+ url: callbackOptions.url,
1827
+ };
1828
+ if (callbackOptions.headers) {
1829
+ body.callback.headers = JSON.parse(callbackOptions.headers);
1830
+ }
1831
+ }
1832
+ if (additionalFields.outputName)
1833
+ body.name = additionalFields.outputName;
1834
+ if (additionalFields.testing !== undefined)
1835
+ body.testing = additionalFields.testing;
1836
+ const options = {
1837
+ method: 'POST',
1838
+ baseURL,
1839
+ url: '/documents/generate/async',
1840
+ body,
1841
+ json: true,
1842
+ };
1843
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1844
+ }
1845
+ else if (operation === 'generateBatch') {
1846
+ const templates = this.getNodeParameter('templates', i);
1847
+ const format = this.getNodeParameter('format', i, 'pdf');
1848
+ const output = this.getNodeParameter('output', i, 'base64');
1849
+ const additionalFields = this.getNodeParameter('additionalFields', i, {});
1850
+ const templateArray = templates.templateList.map((template) => {
1851
+ const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
1852
+ return {
1853
+ id: templateId,
1854
+ data: JSON.parse(template.data),
1855
+ };
1856
+ });
1857
+ const body = {
1858
+ template: templateArray,
1859
+ format,
1860
+ output,
1861
+ };
1862
+ if (additionalFields.outputName)
1863
+ body.name = additionalFields.outputName;
1864
+ if (additionalFields.testing !== undefined)
1865
+ body.testing = additionalFields.testing;
1866
+ const options = {
1867
+ method: 'POST',
1868
+ baseURL,
1869
+ url: '/documents/generate/batch',
1870
+ body,
1871
+ json: true,
1872
+ };
1873
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1874
+ if (responseData && output !== 'url') {
1875
+ if (output === 'file') {
1876
+ let fileData = responseData.response || responseData.data || responseData;
1877
+ if (!fileData) {
1878
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No file data received from API. Response structure: ${JSON.stringify(Object.keys(responseData))}`, { itemIndex: i });
1879
+ }
1880
+ const binaryData = {};
1881
+ const fileName = `${additionalFields.outputName || 'batch-documents'}.${format}`;
1882
+ let binaryBuffer;
1883
+ if (typeof fileData === 'string') {
1884
+ if (fileData.startsWith('data:')) {
1885
+ const base64Data = fileData.split(',')[1];
1886
+ binaryBuffer = Buffer.from(base64Data, 'base64');
1887
+ }
1888
+ else {
1889
+ binaryBuffer = Buffer.from(fileData, 'base64');
1890
+ }
1891
+ }
1892
+ else if (Buffer.isBuffer(fileData)) {
1893
+ binaryBuffer = fileData;
1894
+ }
1895
+ else {
1896
+ binaryBuffer = Buffer.from(fileData);
1897
+ }
1898
+ binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, format === 'pdf' ? 'application/pdf' : `application/${format}`);
1899
+ returnData.push({
1900
+ json: {
1901
+ success: true,
1902
+ filename: fileName,
1903
+ format: output,
1904
+ ...responseData.meta,
1905
+ },
1906
+ binary: binaryData,
1907
+ });
1908
+ continue;
1909
+ }
1910
+ else {
1911
+ returnData.push({
1912
+ json: {
1913
+ success: true,
1914
+ filename: `${additionalFields.outputName || 'batch-documents'}.${format}`,
1915
+ format: output,
1916
+ ...responseData,
1917
+ },
1918
+ });
1919
+ continue;
1920
+ }
1921
+ }
1922
+ }
1923
+ else if (operation === 'generateBatchAsync') {
1924
+ const templates = this.getNodeParameter('templates', i);
1925
+ const format = this.getNodeParameter('format', i, 'pdf');
1926
+ const output = this.getNodeParameter('output', i, 'base64');
1927
+ const additionalFields = this.getNodeParameter('additionalFields', i, {});
1928
+ const callbackOptions = this.getNodeParameter('callbackOptions', i, {});
1929
+ const templateArray = templates.templateList.map((template) => {
1930
+ const templateId = typeof template.templateId === 'string' ? template.templateId : template.templateId.value;
1931
+ return {
1932
+ id: templateId,
1933
+ data: JSON.parse(template.data),
1934
+ };
1935
+ });
1936
+ const body = {
1937
+ template: templateArray,
1938
+ format,
1939
+ output,
1940
+ };
1941
+ if (callbackOptions.url) {
1942
+ body.callback = {
1943
+ url: callbackOptions.url,
1944
+ };
1945
+ if (callbackOptions.headers) {
1946
+ body.callback.headers = JSON.parse(callbackOptions.headers);
1947
+ }
1948
+ }
1949
+ if (additionalFields.outputName)
1950
+ body.name = additionalFields.outputName;
1951
+ if (additionalFields.testing !== undefined)
1952
+ body.testing = additionalFields.testing;
1953
+ const options = {
1954
+ method: 'POST',
1955
+ baseURL,
1956
+ url: '/documents/generate/batch/async',
1957
+ body,
1958
+ json: true,
1959
+ };
1960
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1961
+ }
1962
+ }
1963
+ else if (resource === 'template') {
1964
+ if (operation === 'list') {
1965
+ const listOptions = this.getNodeParameter('listOptions', i, {});
1966
+ const qs = {};
1967
+ if (listOptions.name)
1968
+ qs.name = listOptions.name;
1969
+ if (listOptions.tags)
1970
+ qs.tags = listOptions.tags;
1971
+ if (listOptions.access)
1972
+ qs.access = listOptions.access;
1973
+ if (listOptions.page)
1974
+ qs.page = listOptions.page;
1975
+ if (listOptions.per_page)
1976
+ qs.per_page = listOptions.per_page;
1977
+ const options = {
1978
+ method: 'GET',
1979
+ baseURL,
1980
+ url: '/templates',
1981
+ qs,
1982
+ json: true,
1983
+ };
1984
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1985
+ }
1986
+ else if (operation === 'get') {
1987
+ const templateIdParam = this.getNodeParameter('templateId', i);
1988
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
1989
+ const options = {
1990
+ method: 'GET',
1991
+ baseURL,
1992
+ url: `/templates/${templateId}`,
1993
+ json: true,
1994
+ };
1995
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
1996
+ }
1997
+ else if (operation === 'create') {
1998
+ const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
1999
+ const body = JSON.parse(templateConfiguration);
2000
+ const options = {
2001
+ method: 'POST',
2002
+ baseURL,
2003
+ url: '/templates',
2004
+ body,
2005
+ json: true,
2006
+ };
2007
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2008
+ }
2009
+ else if (operation === 'update') {
2010
+ const templateIdParam = this.getNodeParameter('templateId', i);
2011
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
2012
+ const templateConfiguration = this.getNodeParameter('templateConfiguration', i);
2013
+ const body = JSON.parse(templateConfiguration);
2014
+ const options = {
2015
+ method: 'PUT',
2016
+ baseURL,
2017
+ url: `/templates/${templateId}`,
2018
+ body,
2019
+ json: true,
2020
+ };
2021
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2022
+ }
2023
+ else if (operation === 'delete') {
2024
+ const templateIdParam = this.getNodeParameter('templateId', i);
2025
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
2026
+ const options = {
2027
+ method: 'DELETE',
2028
+ baseURL,
2029
+ url: `/templates/${templateId}`,
2030
+ json: true,
2031
+ };
2032
+ await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2033
+ responseData = {
2034
+ success: true,
2035
+ message: 'Template deleted successfully',
2036
+ templateId: templateId,
2037
+ };
2038
+ }
2039
+ else if (operation === 'validate') {
2040
+ const templateConfig = this.getNodeParameter('templateConfig', i);
2041
+ const body = typeof templateConfig === 'string' ? JSON.parse(templateConfig) : templateConfig;
2042
+ if (!body || typeof body !== 'object') {
2043
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Template configuration must be a valid JSON object', { itemIndex: i });
2044
+ }
2045
+ const options = {
2046
+ method: 'POST',
2047
+ baseURL,
2048
+ url: '/templates/validate',
2049
+ body,
2050
+ json: true,
2051
+ };
2052
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2053
+ }
2054
+ else if (operation === 'getDataFields') {
2055
+ const templateIdParam = this.getNodeParameter('templateId', i);
2056
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
2057
+ const options = {
2058
+ method: 'GET',
2059
+ baseURL,
2060
+ url: `/templates/${templateId}/data`,
2061
+ json: true,
2062
+ };
2063
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2064
+ }
2065
+ else if (operation === 'copy') {
2066
+ const templateIdParam = this.getNodeParameter('templateId', i);
2067
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
2068
+ const newTemplateName = this.getNodeParameter('newTemplateName', i, '');
2069
+ const body = {};
2070
+ if (newTemplateName)
2071
+ body.name = newTemplateName;
2072
+ const options = {
2073
+ method: 'POST',
2074
+ baseURL,
2075
+ url: `/templates/${templateId}/copy`,
2076
+ body,
2077
+ json: true,
2078
+ };
2079
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2080
+ }
2081
+ else if (operation === 'openEditor') {
2082
+ const templateIdParam = this.getNodeParameter('templateId', i);
2083
+ const templateId = typeof templateIdParam === 'string' ? templateIdParam : templateIdParam.value;
2084
+ const editorOptions = this.getNodeParameter('editorOptions', i, {});
2085
+ const body = {};
2086
+ if (editorOptions.data)
2087
+ body.data = JSON.parse(editorOptions.data);
2088
+ if (editorOptions.language)
2089
+ body.language = editorOptions.language;
2090
+ const options = {
2091
+ method: 'POST',
2092
+ baseURL,
2093
+ url: `/templates/${templateId}/editor`,
2094
+ body,
2095
+ json: true,
2096
+ };
2097
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2098
+ }
2099
+ }
2100
+ else if (resource === 'pdfServices') {
2101
+ const pdfSource = this.getNodeParameter('pdfSource', i);
2102
+ const outputFormat = this.getNodeParameter('outputFormat', i, 'base64');
2103
+ const body = {};
2104
+ if (pdfSource === 'url') {
2105
+ body.file_url = this.getNodeParameter('fileUrl', i);
2106
+ }
2107
+ else {
2108
+ body.file_base64 = this.getNodeParameter('fileBase64', i);
2109
+ }
2110
+ body.output = outputFormat;
2111
+ if (operation === 'addWatermark') {
2112
+ const watermarkTypes = this.getNodeParameter('watermarkType', i);
2113
+ const textOptions = this.getNodeParameter('textWatermarkOptions', i, {});
2114
+ const imageOptions = this.getNodeParameter('imageWatermarkOptions', i, {});
2115
+ const watermark = {};
2116
+ if (watermarkTypes.includes('text')) {
2117
+ const textContent = this.getNodeParameter('watermarkText', i);
2118
+ if (!textContent) {
2119
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Watermark text is required when Text watermark type is selected');
2120
+ }
2121
+ watermark.text = {
2122
+ content: textContent
2123
+ };
2124
+ if (textOptions.color)
2125
+ watermark.text.color = textOptions.color;
2126
+ if (textOptions.size !== undefined)
2127
+ watermark.text.size = textOptions.size;
2128
+ if (textOptions.opacity !== undefined)
2129
+ watermark.text.opacity = textOptions.opacity;
2130
+ if (textOptions.position)
2131
+ watermark.text.position = textOptions.position;
2132
+ if (textOptions.rotation !== undefined)
2133
+ watermark.text.rotation = textOptions.rotation;
2134
+ }
2135
+ if (watermarkTypes.includes('image')) {
2136
+ const imageUrl = this.getNodeParameter('watermarkImageUrl', i);
2137
+ if (!imageUrl) {
2138
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Watermark image URL is required when Image watermark type is selected');
2139
+ }
2140
+ watermark.image = {
2141
+ content_url: imageUrl
2142
+ };
2143
+ if (imageOptions.position)
2144
+ watermark.image.position = imageOptions.position;
2145
+ if (imageOptions.rotation !== undefined)
2146
+ watermark.image.rotation = imageOptions.rotation;
2147
+ if (imageOptions.scale !== undefined)
2148
+ watermark.image.scale = imageOptions.scale;
2149
+ }
2150
+ if (!watermarkTypes.length || (!watermark.text && !watermark.image)) {
2151
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'At least one watermark type (text or image) must be selected and configured');
2152
+ }
2153
+ body.watermark = watermark;
2154
+ const options = {
2155
+ method: 'POST',
2156
+ baseURL,
2157
+ url: '/pdfservices/watermark',
2158
+ body,
2159
+ json: outputFormat !== 'file',
2160
+ encoding: outputFormat === 'file' ? null : 'utf8',
2161
+ };
2162
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2163
+ }
2164
+ else if (operation === 'encrypt') {
2165
+ const ownerPassword = this.getNodeParameter('ownerPassword', i);
2166
+ const userPassword = this.getNodeParameter('userPassword', i);
2167
+ if (ownerPassword)
2168
+ body.owner_password = ownerPassword;
2169
+ if (userPassword)
2170
+ body.user_password = userPassword;
2171
+ const options = {
2172
+ method: 'POST',
2173
+ baseURL,
2174
+ url: '/pdfservices/encrypt',
2175
+ body,
2176
+ json: outputFormat !== 'file',
2177
+ encoding: outputFormat === 'file' ? null : 'utf8',
2178
+ };
2179
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2180
+ }
2181
+ else if (operation === 'decrypt') {
2182
+ const decryptionPassword = this.getNodeParameter('decryptionPassword', i);
2183
+ if (decryptionPassword)
2184
+ body.owner_password = decryptionPassword;
2185
+ const options = {
2186
+ method: 'POST',
2187
+ baseURL,
2188
+ url: '/pdfservices/decrypt',
2189
+ body,
2190
+ json: outputFormat !== 'file',
2191
+ encoding: outputFormat === 'file' ? null : 'utf8',
2192
+ };
2193
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2194
+ }
2195
+ else if (operation === 'extractFormFields') {
2196
+ const options = {
2197
+ method: 'POST',
2198
+ baseURL,
2199
+ url: '/pdfservices/form/fields',
2200
+ body,
2201
+ json: true,
2202
+ };
2203
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2204
+ }
2205
+ else if (operation === 'fillFormFields') {
2206
+ const formFieldsData = this.getNodeParameter('formFieldsData', i);
2207
+ let parsedData;
2208
+ try {
2209
+ parsedData = typeof formFieldsData === 'string' ? JSON.parse(formFieldsData) : formFieldsData;
2210
+ }
2211
+ catch (error) {
2212
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Form Fields Data must be valid JSON');
2213
+ }
2214
+ body.data = parsedData;
2215
+ const options = {
2216
+ method: 'POST',
2217
+ baseURL,
2218
+ url: '/pdfservices/form/fill',
2219
+ body,
2220
+ json: outputFormat !== 'file',
2221
+ encoding: outputFormat === 'file' ? null : 'utf8',
2222
+ };
2223
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2224
+ }
2225
+ else if (operation === 'optimize') {
2226
+ const options = {
2227
+ method: 'POST',
2228
+ baseURL,
2229
+ url: '/pdfservices/optimize',
2230
+ body,
2231
+ json: outputFormat !== 'file',
2232
+ encoding: outputFormat === 'file' ? null : 'utf8',
2233
+ resolveWithFullResponse: true,
2234
+ };
2235
+ const fullResponse = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2236
+ responseData = fullResponse.body;
2237
+ const headers = fullResponse.headers || {};
2238
+ const originalSize = headers['x-original-size'] ? parseInt(headers['x-original-size'], 10) : null;
2239
+ const optimizedSize = headers['x-optimized-size'] ? parseInt(headers['x-optimized-size'], 10) : null;
2240
+ responseData.__optimizationStats = {
2241
+ originalSize,
2242
+ optimizedSize,
2243
+ compressionRatio: originalSize && optimizedSize ? ((originalSize - optimizedSize) / originalSize * 100) : null
2244
+ };
2245
+ }
2246
+ if (responseData) {
2247
+ if (operation === 'extractFormFields') {
2248
+ returnData.push({
2249
+ json: {
2250
+ success: true,
2251
+ operation,
2252
+ ...responseData,
2253
+ },
2254
+ });
2255
+ }
2256
+ else if (outputFormat === 'file') {
2257
+ const binaryData = {};
2258
+ const fileName = `processed-document.pdf`;
2259
+ const binaryBuffer = Buffer.isBuffer(responseData) ? responseData : Buffer.from(responseData);
2260
+ binaryData[fileName] = await this.helpers.prepareBinaryData(binaryBuffer, fileName, 'application/pdf');
2261
+ const jsonResponse = {
2262
+ success: true,
2263
+ operation,
2264
+ filename: fileName,
2265
+ format: outputFormat,
2266
+ fileSize: binaryBuffer.length,
2267
+ };
2268
+ if (operation === 'optimize' && responseData.__optimizationStats) {
2269
+ const stats = responseData.__optimizationStats;
2270
+ jsonResponse.optimizationStats = {
2271
+ originalSize: stats.originalSize,
2272
+ optimizedSize: stats.optimizedSize,
2273
+ savedBytes: stats.originalSize && stats.optimizedSize ? stats.originalSize - stats.optimizedSize : null,
2274
+ compressionRatio: stats.compressionRatio ? `${stats.compressionRatio.toFixed(2)}%` : null
2275
+ };
2276
+ }
2277
+ returnData.push({
2278
+ json: jsonResponse,
2279
+ binary: binaryData,
2280
+ });
2281
+ }
2282
+ else {
2283
+ const jsonResponse = {
2284
+ success: true,
2285
+ operation,
2286
+ format: outputFormat,
2287
+ ...responseData,
2288
+ };
2289
+ if (operation === 'optimize' && responseData.__optimizationStats) {
2290
+ const stats = responseData.__optimizationStats;
2291
+ jsonResponse.optimizationStats = {
2292
+ originalSize: stats.originalSize,
2293
+ optimizedSize: stats.optimizedSize,
2294
+ savedBytes: stats.originalSize && stats.optimizedSize ? stats.originalSize - stats.optimizedSize : null,
2295
+ compressionRatio: stats.compressionRatio ? `${stats.compressionRatio.toFixed(2)}%` : null
2296
+ };
2297
+ delete jsonResponse.__optimizationStats;
2298
+ }
2299
+ returnData.push({
2300
+ json: jsonResponse,
2301
+ });
2302
+ }
2303
+ continue;
2304
+ }
2305
+ }
2306
+ else if (resource === 'workspace') {
2307
+ if (operation === 'list') {
2308
+ const listOptions = this.getNodeParameter('listOptions', i, {});
2309
+ const qs = {};
2310
+ if (listOptions.page)
2311
+ qs.page = listOptions.page;
2312
+ if (listOptions.per_page)
2313
+ qs.per_page = listOptions.per_page;
2314
+ const options = {
2315
+ method: 'GET',
2316
+ baseURL,
2317
+ url: '/workspaces',
2318
+ qs,
2319
+ json: true,
2320
+ };
2321
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2322
+ }
2323
+ else if (operation === 'create') {
2324
+ const identifier = this.getNodeParameter('identifier', i);
2325
+ const body = {
2326
+ identifier,
2327
+ };
2328
+ const options = {
2329
+ method: 'POST',
2330
+ baseURL,
2331
+ url: '/workspaces',
2332
+ body,
2333
+ json: true,
2334
+ };
2335
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2336
+ }
2337
+ else if (operation === 'get') {
2338
+ const workspaceIdentifier = this.getNodeParameter('workspaceIdentifier', i);
2339
+ const options = {
2340
+ method: 'GET',
2341
+ baseURL,
2342
+ url: `/workspaces/${encodeURIComponent(workspaceIdentifier)}`,
2343
+ json: true,
2344
+ };
2345
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2346
+ }
2347
+ else if (operation === 'delete') {
2348
+ const workspaceIdentifier = this.getNodeParameter('workspaceIdentifier', i);
2349
+ const options = {
2350
+ method: 'DELETE',
2351
+ baseURL,
2352
+ url: `/workspaces/${encodeURIComponent(workspaceIdentifier)}`,
2353
+ json: true,
2354
+ };
2355
+ responseData = await this.helpers.requestWithAuthentication.call(this, 'pdfGeneratorApi', options);
2356
+ }
2357
+ }
2358
+ if (responseData === undefined) {
2359
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `The operation "${operation}" is not supported for resource "${resource}"`);
2360
+ }
2361
+ const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: i } });
2362
+ returnData.push(...executionData);
2363
+ }
2364
+ catch (error) {
2365
+ if (this.continueOnFail()) {
2366
+ const executionErrorData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ error: error.message }), { itemData: { item: i } });
2367
+ returnData.push(...executionErrorData);
2368
+ continue;
2369
+ }
2370
+ throw error;
2371
+ }
2372
+ }
2373
+ return [returnData];
2374
+ }
2375
+ }
2376
+ exports.PdfGeneratorApi = PdfGeneratorApi;
2377
+ //# sourceMappingURL=PdfGeneratorApi.node.js.map