n8n-nodes-pdfops 0.4.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,10 @@ exports.Pdfops = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
5
  const decodeApiError_1 = require("./decodeApiError");
6
6
  const BASE_URL = 'https://pdfops.dev';
7
- const NODE_PACKAGE_VERSION = '0.4.0';
7
+ const NODE_PACKAGE_VERSION = '0.6.0';
8
+ function headerTrue(value) {
9
+ return typeof value === 'string' && value.split(',')[0].trim().toLowerCase() === 'true';
10
+ }
8
11
  function withApiMessage(wrapped, apiError, itemIndex) {
9
12
  var _a;
10
13
  if (itemIndex !== undefined)
@@ -26,7 +29,14 @@ const DOC_OPS = {
26
29
  protect: { path: 'protect', output: 'pdf', defaultFile: 'protected.pdf' },
27
30
  metadata: { path: 'metadata', output: 'json', defaultFile: '' },
28
31
  setMetadata: { path: 'set-metadata', output: 'pdf', defaultFile: 'metadata-updated.pdf' },
32
+ addFields: { path: 'add-fields', output: 'pdf', defaultFile: 'fields-added.pdf' },
33
+ attach: { path: 'attach', output: 'pdf', defaultFile: 'attached.pdf' },
34
+ edit: { path: 'edit', output: 'pdf', defaultFile: 'edited.pdf' },
35
+ extractText: { path: 'extract-text', output: 'extract', defaultFile: 'tables.xlsx' },
36
+ findText: { path: 'find-text', output: 'json', defaultFile: '' },
37
+ detectFields: { path: 'detect-fields', output: 'json', defaultFile: '' },
29
38
  };
39
+ const XLSX_MIME_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
30
40
  const OPERATION_PROPERTIES = [
31
41
  {
32
42
  displayName: 'Operation',
@@ -76,12 +86,15 @@ const OPERATION_PROPERTIES = [
76
86
  displayOptions: { show: { '@version': [2] } },
77
87
  options: [
78
88
  { name: 'Account', value: 'account' },
89
+ { name: 'Attachment', value: 'attachment' },
90
+ { name: 'Convert', value: 'convert' },
79
91
  { name: 'Document', value: 'document' },
80
92
  { name: 'Form', value: 'form' },
81
93
  { name: 'Invoice', value: 'invoice' },
82
94
  { name: 'Metadata', value: 'metadata' },
83
95
  { name: 'Security', value: 'security' },
84
96
  { name: 'Stamp', value: 'stamp' },
97
+ { name: 'Text', value: 'text' },
85
98
  ],
86
99
  default: 'form',
87
100
  },
@@ -101,6 +114,50 @@ const OPERATION_PROPERTIES = [
101
114
  ],
102
115
  default: 'usage',
103
116
  },
117
+ {
118
+ displayName: 'Operation',
119
+ name: 'operation',
120
+ type: 'options',
121
+ noDataExpression: true,
122
+ displayOptions: { show: { '@version': [2], resource: ['attachment'] } },
123
+ options: [
124
+ {
125
+ name: 'Attach',
126
+ value: 'attach',
127
+ action: 'Attach files to a PDF',
128
+ description: 'Embed files (an XML invoice, a spreadsheet, a source file) inside a PDF and output the updated PDF',
129
+ },
130
+ ],
131
+ default: 'attach',
132
+ },
133
+ {
134
+ displayName: 'Operation',
135
+ name: 'operation',
136
+ type: 'options',
137
+ noDataExpression: true,
138
+ displayOptions: { show: { '@version': [2], resource: ['convert'] } },
139
+ options: [
140
+ {
141
+ name: 'HTML to PDF',
142
+ value: 'htmlToPdf',
143
+ action: 'Convert HTML to a PDF',
144
+ description: 'Render an HTML string to a PDF with a headless browser, so CSS, images and web fonts come out as in a browser print. Each call counts as 5 requests against your quota.',
145
+ },
146
+ {
147
+ name: 'Images to PDF',
148
+ value: 'imageToPdf',
149
+ action: 'Convert images to a PDF',
150
+ description: 'Turn the JPG or PNG images from all incoming items (in item order) into one PDF, one image per page',
151
+ },
152
+ {
153
+ name: 'Text to PDF',
154
+ value: 'textToPdf',
155
+ action: 'Convert text to a PDF',
156
+ description: 'Turn Markdown, plain text or CSV into a PDF on A4 or Letter pages, without a template',
157
+ },
158
+ ],
159
+ default: 'htmlToPdf',
160
+ },
104
161
  {
105
162
  displayName: 'Operation',
106
163
  name: 'operation',
@@ -148,6 +205,18 @@ const OPERATION_PROPERTIES = [
148
205
  noDataExpression: true,
149
206
  displayOptions: { show: { '@version': [2], resource: ['form'] } },
150
207
  options: [
208
+ {
209
+ name: 'Add Fields',
210
+ value: 'addFields',
211
+ action: 'Add form fields to a PDF',
212
+ description: 'Create fillable form fields (text, checkbox, radio group, dropdown, signature box) at exact positions in a PDF',
213
+ },
214
+ {
215
+ name: 'Detect Fields',
216
+ value: 'detectFields',
217
+ action: 'Detect fields on a flat PDF',
218
+ description: 'Suggest text and checkbox fields for a flat PDF as JSON: detects fields drawn as lines, boxes, underscores and checkboxes; review the result. Nothing is added to the PDF.',
219
+ },
151
220
  {
152
221
  name: 'Fill',
153
222
  value: 'fill',
@@ -160,6 +229,12 @@ const OPERATION_PROPERTIES = [
160
229
  action: 'List the form fields of a PDF',
161
230
  description: 'List a PDF’s AcroForm fields — names, types, options, current values — plus a paste-ready fill template',
162
231
  },
232
+ {
233
+ name: 'Make Fillable (Detect Fields)',
234
+ value: 'makeFillable',
235
+ action: 'Make a flat PDF fillable',
236
+ description: 'Detect fields on a flat PDF and add them: outputs the fillable PDF plus the field count and names. Long documents are handled in several calls (up to 25). Detects fields drawn as lines, boxes, underscores and checkboxes; review the result.',
237
+ },
163
238
  ],
164
239
  default: 'fill',
165
240
  },
@@ -242,9 +317,37 @@ const OPERATION_PROPERTIES = [
242
317
  action: 'Add a text watermark to a PDF',
243
318
  description: 'Stamp diagonal or horizontal text (DRAFT, CONFIDENTIAL, a name) over the pages of a PDF and output the watermarked PDF',
244
319
  },
320
+ {
321
+ name: 'Edit',
322
+ value: 'edit',
323
+ action: 'Add text images or barcodes to a PDF',
324
+ description: 'Draw text, images (a logo, a signature), QR codes and barcodes at exact positions on the pages of a PDF and output the edited PDF',
325
+ },
245
326
  ],
246
327
  default: 'watermark',
247
328
  },
329
+ {
330
+ displayName: 'Operation',
331
+ name: 'operation',
332
+ type: 'options',
333
+ noDataExpression: true,
334
+ displayOptions: { show: { '@version': [2], resource: ['text'] } },
335
+ options: [
336
+ {
337
+ name: 'Extract',
338
+ value: 'extractText',
339
+ action: 'Extract text and tables from a PDF',
340
+ description: 'Read the text of a PDF with a text layer, page by page, plus the tables found on the pages, as JSON, plain text or an Excel workbook. Scanned pages are not read (no OCR).',
341
+ },
342
+ {
343
+ name: 'Find',
344
+ value: 'findText',
345
+ action: 'Find text in a PDF',
346
+ description: 'Search a PDF with a text layer for a word, phrase or pattern and return every hit with its page and its box in PDF points',
347
+ },
348
+ ],
349
+ default: 'extractText',
350
+ },
248
351
  ];
249
352
  class Pdfops {
250
353
  constructor() {
@@ -256,7 +359,7 @@ class Pdfops {
256
359
  version: [1, 2],
257
360
  defaultVersion: 2,
258
361
  subtitle: '={{ ($parameter["resource"] ? $parameter["resource"] + ": " : "") + $parameter["operation"] }}',
259
- description: 'Fill, merge, split, rotate, watermark, number, protect, unlock and read PDFs and generate invoices. Works without an API key (100 calls/month).',
362
+ description: 'Fill, merge, split, rotate, watermark, number, protect, unlock, edit, read and search PDFs, add form fields and attachments, convert HTML, text and images to PDF, and generate invoices. Works without an API key (100 calls/month).',
260
363
  defaults: {
261
364
  name: 'PDFops',
262
365
  },
@@ -280,10 +383,19 @@ class Pdfops {
280
383
  hint: 'The name of the input item’s binary field containing the PDF',
281
384
  displayOptions: {
282
385
  show: {
283
- operation: ['fill', 'inspect', 'merge', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'metadata', 'setMetadata'],
386
+ operation: ['fill', 'inspect', 'merge', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'metadata', 'setMetadata', 'addFields', 'attach', 'edit', 'extractText', 'findText', 'detectFields', 'makeFillable'],
284
387
  },
285
388
  },
286
389
  },
390
+ {
391
+ displayName: 'Input Binary Field',
392
+ name: 'binaryPropertyName',
393
+ type: 'string',
394
+ default: 'data',
395
+ required: true,
396
+ hint: 'The name of the input item’s binary field containing the image (JPG or PNG)',
397
+ displayOptions: { show: { operation: ['imageToPdf'] } },
398
+ },
287
399
  {
288
400
  displayName: 'Fields',
289
401
  name: 'fields',
@@ -320,6 +432,13 @@ class Pdfops {
320
432
  'protect',
321
433
  'metadata',
322
434
  'setMetadata',
435
+ 'addFields',
436
+ 'attach',
437
+ 'edit',
438
+ 'extractText',
439
+ 'findText',
440
+ 'detectFields',
441
+ 'makeFillable',
323
442
  ],
324
443
  },
325
444
  },
@@ -351,7 +470,42 @@ class Pdfops {
351
470
  default: '',
352
471
  placeholder: 'e.g. 1-3,5 (empty = all pages)',
353
472
  description: '1-based page spec such as "1-3,5". Leave empty to apply to every page.',
354
- displayOptions: { show: { operation: ['rotate', 'watermark', 'pageNumbers'] } },
473
+ displayOptions: { show: { operation: ['rotate', 'watermark', 'pageNumbers', 'extractText', 'findText'] } },
474
+ },
475
+ {
476
+ displayName: 'Pages',
477
+ name: 'pages',
478
+ type: 'string',
479
+ default: '',
480
+ placeholder: 'e.g. 1-3,5 (empty = all pages)',
481
+ description: '1-based page spec such as "1-3,5,8-". Leave empty to analyse every page (up to Max Pages). For Detect Fields, when the result says truncated, add the fields found, then run again on that PDF with Pages set to the next pages it lists. Make Fillable continues by itself.',
482
+ displayOptions: { show: { operation: ['detectFields', 'makeFillable'] } },
483
+ },
484
+ {
485
+ displayName: 'Detection Options',
486
+ name: 'detectOptions',
487
+ type: 'collection',
488
+ placeholder: 'Add Option',
489
+ default: {},
490
+ displayOptions: { show: { operation: ['detectFields', 'makeFillable'] } },
491
+ options: [
492
+ {
493
+ displayName: 'Max Pages',
494
+ name: 'max_pages',
495
+ type: 'number',
496
+ typeOptions: { minValue: 1, maxValue: 100 },
497
+ default: 40,
498
+ description: 'Analyse at most this many pages per call (1 to 100)',
499
+ },
500
+ {
501
+ displayName: 'Min Confidence',
502
+ name: 'min_confidence',
503
+ type: 'number',
504
+ typeOptions: { minValue: 0, maxValue: 1, numberPrecision: 2 },
505
+ default: 0.4,
506
+ description: 'Drop suggestions below this confidence (0 to 1). Higher gives fewer, surer fields.',
507
+ },
508
+ ],
355
509
  },
356
510
  {
357
511
  displayName: 'Degrees',
@@ -527,7 +681,7 @@ class Pdfops {
527
681
  type: 'string',
528
682
  typeOptions: { password: true },
529
683
  default: '',
530
- description: 'Password required to open the output PDF (at most 128 characters). Set this and/or the Owner Password; at least one is required.',
684
+ description: 'Password required to open the output PDF (1-32 characters, Latin-1 only). Set this and/or the Owner Password; at least one is required.',
531
685
  displayOptions: { show: { operation: ['protect'] } },
532
686
  },
533
687
  {
@@ -536,7 +690,7 @@ class Pdfops {
536
690
  type: 'string',
537
691
  typeOptions: { password: true },
538
692
  default: '',
539
- description: 'Password that lifts the permission restrictions (at most 128 characters). Restrictions only bind a viewer when an owner password is set.',
693
+ description: 'Password that lifts the permission restrictions (1-32 characters, Latin-1 only). Restrictions only bind a viewer when an owner password is set.',
540
694
  displayOptions: { show: { operation: ['protect'] } },
541
695
  },
542
696
  {
@@ -585,19 +739,471 @@ class Pdfops {
585
739
  { displayName: 'Title', name: 'title', type: 'string', default: '' },
586
740
  ],
587
741
  },
742
+ {
743
+ displayName: 'Fields to Add',
744
+ name: 'formFields',
745
+ type: 'json',
746
+ default: '[\n { "type": "text", "name": "customer_name", "page": 1, "x": 72, "y": 700, "width": 200, "height": 20 }\n]',
747
+ required: true,
748
+ description: 'JSON array (up to 200 entries) of fields to create. Every entry needs type (text, checkbox, radio, dropdown or signature), name (1-200 characters, no dot, unique, also against fields already in the PDF) and page (1-based). Every type except radio also needs x, y, width and height in PDF points from the bottom-left of the page as displayed; the box must lie inside the page. Optional on all types: required, read_only, border, background. text takes multiline, max_length, default, font_size (1-200 or "auto"); checkbox takes checked; radio takes options[] of { value, x, y, width, height } and default; dropdown takes options[] of strings, default, font_size.',
749
+ displayOptions: { show: { operation: ['addFields'] } },
750
+ },
751
+ {
752
+ displayName: 'Files to Attach',
753
+ name: 'attachments',
754
+ type: 'fixedCollection',
755
+ typeOptions: { multipleValues: true },
756
+ placeholder: 'Add File',
757
+ default: {},
758
+ required: true,
759
+ description: 'Files to embed, in order (1 to 10, up to 3 MB combined). Each one is read from a binary field of the input item.',
760
+ displayOptions: { show: { operation: ['attach'] } },
761
+ options: [
762
+ {
763
+ displayName: 'File',
764
+ name: 'file',
765
+ values: [
766
+ {
767
+ displayName: 'Binary Field',
768
+ name: 'binaryPropertyName',
769
+ type: 'string',
770
+ default: 'attachment',
771
+ required: true,
772
+ description: 'The name of the input item’s binary field holding the file to embed',
773
+ },
774
+ {
775
+ displayName: 'Description',
776
+ name: 'description',
777
+ type: 'string',
778
+ default: '',
779
+ description: 'Free text description stored with the file (optional)',
780
+ },
781
+ {
782
+ displayName: 'MIME Type',
783
+ name: 'mimeType',
784
+ type: 'string',
785
+ default: '',
786
+ placeholder: 'e.g. text/xml',
787
+ description: 'Defaults to the MIME type of the binary data',
788
+ },
789
+ {
790
+ displayName: 'Name',
791
+ name: 'name',
792
+ type: 'string',
793
+ default: '',
794
+ placeholder: 'e.g. factur-x.xml',
795
+ description: 'File name inside the PDF (1-255 characters, no / or \\). Defaults to the binary data’s file name. Must be unique within the PDF.',
796
+ },
797
+ {
798
+ displayName: 'Relationship',
799
+ name: 'relationship',
800
+ type: 'options',
801
+ options: [
802
+ { name: 'Alternative', value: 'Alternative' },
803
+ { name: 'Data', value: 'Data' },
804
+ { name: 'Source', value: 'Source' },
805
+ { name: 'Supplement', value: 'Supplement' },
806
+ { name: 'Unspecified', value: 'Unspecified' },
807
+ ],
808
+ default: 'Unspecified',
809
+ description: 'PDF/A-3 relationship of the file to the document',
810
+ },
811
+ ],
812
+ },
813
+ ],
814
+ },
815
+ {
816
+ displayName: 'Items',
817
+ name: 'editItems',
818
+ type: 'json',
819
+ default: '[\n { "type": "text", "page": 1, "x": 72, "y": 720, "text": "Approved", "size": 14 }\n]',
820
+ required: true,
821
+ description: 'JSON array (up to 100 entries) of things to draw, in order (later ones draw on top). x and y are PDF points from the bottom-left of the page as displayed. type "text": page, x, y, text (WinAnsi characters only), optional size, color, font, opacity, rotation, maxWidth, lineHeight. type "image": page, x, y, image (the Field Name of one of the Image Files below), optional width, height, opacity. type "barcode": page, x, y, format (qrcode, datamatrix, pdf417, azteccode, code128, code39, ean13, ean8, upca, itf14, interleaved2of5, gs1-128), value, optional width, height, color, background, includeText, errorCorrection, opacity.',
822
+ displayOptions: { show: { operation: ['edit'] } },
823
+ },
824
+ {
825
+ displayName: 'Image Files',
826
+ name: 'imageFiles',
827
+ type: 'fixedCollection',
828
+ typeOptions: { multipleValues: true },
829
+ placeholder: 'Add Image',
830
+ default: {},
831
+ description: 'PNG or JPEG images that "image" items refer to (up to 10, 2 MB each). Only needed when Items contains image entries.',
832
+ displayOptions: { show: { operation: ['edit'] } },
833
+ options: [
834
+ {
835
+ displayName: 'Image',
836
+ name: 'image',
837
+ values: [
838
+ {
839
+ displayName: 'Binary Field',
840
+ name: 'binaryPropertyName',
841
+ type: 'string',
842
+ default: 'logo',
843
+ required: true,
844
+ description: 'The name of the input item’s binary field holding the PNG or JPEG',
845
+ },
846
+ {
847
+ displayName: 'Field Name',
848
+ name: 'fieldName',
849
+ type: 'string',
850
+ default: 'logo',
851
+ required: true,
852
+ description: 'The name an Items entry uses in its "image" property to refer to this file. Must not be pdf, password or items.',
853
+ },
854
+ ],
855
+ },
856
+ ],
857
+ },
858
+ {
859
+ displayName: 'Query',
860
+ name: 'query',
861
+ type: 'string',
862
+ default: '',
863
+ required: true,
864
+ description: 'Text to find, or a regular expression when the Regex option is on. A match never spans two lines. Regex uses a safe subset of JavaScript syntax: backreferences, lookahead, lookbehind, named groups and inline flags are rejected.',
865
+ displayOptions: { show: { operation: ['findText'] } },
866
+ },
867
+ {
868
+ displayName: 'Find Options',
869
+ name: 'findOptions',
870
+ type: 'collection',
871
+ placeholder: 'Add Option',
872
+ default: {},
873
+ displayOptions: { show: { operation: ['findText'] } },
874
+ options: [
875
+ {
876
+ displayName: 'Case Sensitive',
877
+ name: 'case_sensitive',
878
+ type: 'boolean',
879
+ default: false,
880
+ description: 'Whether upper and lower case must match (off by default)',
881
+ },
882
+ {
883
+ displayName: 'Max Hits',
884
+ name: 'max_hits',
885
+ type: 'number',
886
+ typeOptions: { minValue: 1, maxValue: 1000 },
887
+ default: 100,
888
+ description: 'Most hits to return (1-1000). When the result has truncated true and nextPage is not null, the search stopped early: run it again with the same Query and options and Pages set to nextPage followed by a dash (for example 4-), keeping any page filter you used before and dropping pages below nextPage. No hit is repeated. Check pagesSkipped on every response: a page listed there held more hits than Max Hits (or was too large), only its first hits were returned, and no later request returns the rest, so raise Max Hits or narrow the Query for that page.',
889
+ },
890
+ {
891
+ displayName: 'Regex',
892
+ name: 'regex',
893
+ type: 'boolean',
894
+ default: false,
895
+ description: 'Whether the Query is a regular expression instead of literal text',
896
+ },
897
+ {
898
+ displayName: 'Whole Word',
899
+ name: 'whole_word',
900
+ type: 'boolean',
901
+ default: false,
902
+ description: 'Whether a hit must not touch a letter, digit or underscore on either side',
903
+ },
904
+ ],
905
+ },
906
+ {
907
+ displayName: 'Result Format',
908
+ name: 'textFormat',
909
+ type: 'options',
910
+ options: [
911
+ {
912
+ name: 'JSON (Pages, Lines and Tables)',
913
+ value: 'json',
914
+ description: 'Returns pageCount, pages[] (text, lines with positions, tables as rows), pagesWithoutText and truncated',
915
+ },
916
+ {
917
+ name: 'Plain Text',
918
+ value: 'text',
919
+ description: 'The text of all pages in the item JSON field "text", pages separated by a form feed',
920
+ },
921
+ ],
922
+ default: 'json',
923
+ displayOptions: { show: { operation: ['extractText'] } },
924
+ },
925
+ {
926
+ displayName: 'Tables As',
927
+ name: 'tablesFormat',
928
+ type: 'options',
929
+ options: [
930
+ {
931
+ name: 'CSV (Added to Each Table in the JSON)',
932
+ value: 'csv',
933
+ description: 'Each table also carries a "csv" string (RFC 4180); rows is unchanged',
934
+ },
935
+ {
936
+ name: 'Excel Workbook (Binary Output)',
937
+ value: 'xlsx',
938
+ description: 'Returns one .xlsx workbook as binary data instead of JSON: one sheet per table, every cell text. Fails with no_tables when the selected pages hold no table.',
939
+ },
940
+ {
941
+ name: 'JSON Rows',
942
+ value: 'json',
943
+ description: 'Tables as rows of cells in the JSON',
944
+ },
945
+ ],
946
+ default: 'json',
947
+ displayOptions: { show: { operation: ['extractText'], textFormat: ['json'] } },
948
+ },
949
+ {
950
+ displayName: 'HTML',
951
+ name: 'html',
952
+ type: 'string',
953
+ typeOptions: { rows: 8 },
954
+ default: '<h1>Hello</h1>\n<p>Rendered by PDFops.</p>',
955
+ required: true,
956
+ description: 'The HTML document to render, up to 1 MB. Text only: there is no URL input and JavaScript is switched off. External images, stylesheets and fonts load over https from public hosts only; data: URIs are the safest way to include images.',
957
+ displayOptions: { show: { operation: ['htmlToPdf'] } },
958
+ },
959
+ {
960
+ displayName: 'HTML Options',
961
+ name: 'htmlOptions',
962
+ type: 'collection',
963
+ placeholder: 'Add Option',
964
+ default: {},
965
+ displayOptions: { show: { operation: ['htmlToPdf'] } },
966
+ options: [
967
+ {
968
+ displayName: 'Landscape',
969
+ name: 'landscape',
970
+ type: 'boolean',
971
+ default: false,
972
+ description: 'Whether to lay the pages out in landscape',
973
+ },
974
+ {
975
+ displayName: 'Margin',
976
+ name: 'margin',
977
+ type: 'number',
978
+ typeOptions: { minValue: 0, maxValue: 144 },
979
+ default: 36,
980
+ description: 'Page margin in points on all four sides (0-144)',
981
+ },
982
+ {
983
+ displayName: 'Page Size',
984
+ name: 'page_size',
985
+ type: 'options',
986
+ options: [
987
+ { name: 'A4', value: 'a4' },
988
+ { name: 'Letter', value: 'letter' },
989
+ ],
990
+ default: 'letter',
991
+ },
992
+ {
993
+ displayName: 'Print Background',
994
+ name: 'print_background',
995
+ type: 'boolean',
996
+ default: true,
997
+ description: 'Whether to print CSS backgrounds and background images',
998
+ },
999
+ {
1000
+ displayName: 'Scale',
1001
+ name: 'scale',
1002
+ type: 'number',
1003
+ typeOptions: { minValue: 0.1, maxValue: 2, numberPrecision: 2 },
1004
+ default: 1,
1005
+ description: 'Rendering scale from 0.1 to 2',
1006
+ },
1007
+ ],
1008
+ },
1009
+ {
1010
+ displayName: 'Content',
1011
+ name: 'content',
1012
+ type: 'string',
1013
+ typeOptions: { rows: 8 },
1014
+ default: '',
1015
+ required: true,
1016
+ description: 'The document, up to 512 KiB of UTF-8. Latin (WinAnsi) characters only; other scripts are rejected with the character and its line and column named. Not HTML: use HTML to PDF for that.',
1017
+ displayOptions: { show: { operation: ['textToPdf'] } },
1018
+ },
1019
+ {
1020
+ displayName: 'Text Options',
1021
+ name: 'textOptions',
1022
+ type: 'collection',
1023
+ placeholder: 'Add Option',
1024
+ default: {},
1025
+ displayOptions: { show: { operation: ['textToPdf'] } },
1026
+ options: [
1027
+ {
1028
+ displayName: 'Font Size',
1029
+ name: 'font_size',
1030
+ type: 'number',
1031
+ typeOptions: { minValue: 6, maxValue: 36 },
1032
+ default: 11,
1033
+ description: 'Body text size in points (6-36)',
1034
+ },
1035
+ {
1036
+ displayName: 'Format',
1037
+ name: 'format',
1038
+ type: 'options',
1039
+ options: [
1040
+ {
1041
+ name: 'CSV',
1042
+ value: 'csv',
1043
+ description: 'A table whose first row is the header',
1044
+ },
1045
+ {
1046
+ name: 'Markdown',
1047
+ value: 'markdown',
1048
+ description: 'Headings, lists, tables, code blocks and links',
1049
+ },
1050
+ {
1051
+ name: 'Plain Text',
1052
+ value: 'text',
1053
+ description: 'Spaces and line breaks kept exactly',
1054
+ },
1055
+ ],
1056
+ default: 'markdown',
1057
+ },
1058
+ {
1059
+ displayName: 'Margin',
1060
+ name: 'margin',
1061
+ type: 'number',
1062
+ typeOptions: { minValue: 18, maxValue: 144 },
1063
+ default: 54,
1064
+ description: 'Page margin in points on all four sides (18-144)',
1065
+ },
1066
+ {
1067
+ displayName: 'Monospace',
1068
+ name: 'monospace',
1069
+ type: 'boolean',
1070
+ default: false,
1071
+ description: 'Whether to set plain text in Courier (Plain Text format only)',
1072
+ },
1073
+ {
1074
+ displayName: 'Page Numbers',
1075
+ name: 'page_numbers',
1076
+ type: 'boolean',
1077
+ default: false,
1078
+ description: 'Whether to print "Page n of N" in the bottom margin',
1079
+ },
1080
+ {
1081
+ displayName: 'Page Size',
1082
+ name: 'page_size',
1083
+ type: 'options',
1084
+ options: [
1085
+ { name: 'A4', value: 'a4' },
1086
+ { name: 'Letter', value: 'letter' },
1087
+ ],
1088
+ default: 'letter',
1089
+ },
1090
+ {
1091
+ displayName: 'Title',
1092
+ name: 'title',
1093
+ type: 'string',
1094
+ default: '',
1095
+ description: 'PDF title metadata, up to 200 characters. Not printed on the page.',
1096
+ },
1097
+ ],
1098
+ },
1099
+ {
1100
+ displayName: 'Image Options',
1101
+ name: 'imageOptions',
1102
+ type: 'collection',
1103
+ placeholder: 'Add Option',
1104
+ default: {},
1105
+ displayOptions: { show: { operation: ['imageToPdf'] } },
1106
+ options: [
1107
+ {
1108
+ displayName: 'Margin',
1109
+ name: 'margin',
1110
+ type: 'number',
1111
+ typeOptions: { minValue: 0, maxValue: 200 },
1112
+ default: 0,
1113
+ description: 'Margin in points (0-200). The API default is 0 for Fit to Image and 36 for A4 and Letter; for Fit to Image the page grows by the margin on each side.',
1114
+ },
1115
+ {
1116
+ displayName: 'Orientation',
1117
+ name: 'orientation',
1118
+ type: 'options',
1119
+ options: [
1120
+ { name: 'Auto (Per Image)', value: 'auto' },
1121
+ { name: 'Landscape', value: 'landscape' },
1122
+ { name: 'Portrait', value: 'portrait' },
1123
+ ],
1124
+ default: 'auto',
1125
+ description: 'Ignored for Fit to Image',
1126
+ },
1127
+ {
1128
+ displayName: 'Page Size',
1129
+ name: 'page_size',
1130
+ type: 'options',
1131
+ options: [
1132
+ { name: 'A4', value: 'a4' },
1133
+ { name: 'Fit to Image', value: 'fit' },
1134
+ { name: 'Letter', value: 'letter' },
1135
+ ],
1136
+ default: 'fit',
1137
+ description: 'Fit to Image makes each page the size of its image; A4 and Letter scale images down to fit, never up',
1138
+ },
1139
+ ],
1140
+ },
588
1141
  {
589
1142
  displayName: 'Invoice',
590
1143
  name: 'invoice',
591
1144
  type: 'json',
592
1145
  default: '{\n "from": "Acme Inc",\n "to": "Customer LLC",\n "items": [\n { "description": "Consulting", "quantity": 2, "unit_price": 100 }\n ]\n}',
593
1146
  required: true,
594
- description: 'Invoice data: from, to, items[] (description, quantity?, unit_price), and optionally invoice_number, date, due, currency, tax_rate, notes. Deterministic: the same input produces a byte-identical PDF.',
1147
+ description: 'Invoice data: from, to, items[] (description, quantity?, unit_price), and optionally invoice_number, date, due, currency, tax_rate, notes. Deterministic: the same input produces a byte-identical PDF. For a Factur-X e-invoice (node version 2), from and to also take country, street, postcode, city, vat_id (and from.tax_id with registration_id), and every item needs a unit.',
595
1148
  displayOptions: {
596
1149
  show: {
597
1150
  operation: ['invoice'],
598
1151
  },
599
1152
  },
600
1153
  },
1154
+ {
1155
+ displayName: 'Factur-X E-Invoice',
1156
+ name: 'eInvoice',
1157
+ type: 'boolean',
1158
+ default: false,
1159
+ description: 'Whether to produce a Factur-X (ZUGFeRD) e-invoice: a PDF/A-3 with the invoice data embedded as factur-x.xml, profile EN 16931. Required in the Invoice JSON then: invoice_number, date (YYYY-MM-DD), currency, due or payment_terms, from.country and to.country (ISO 3166-1 alpha-2), from.vat_id (or from.tax_id with from.registration_id; with tax category O, no VAT ID at all and from.registration_id instead), a buyer to.vat_id or to.registration_id for tax category AE, a UN/ECE Recommendation 20 unit on every item (C62 one, HUR hour, KGM kilogram), and tax_category when tax_rate is 0. Text is limited to Latin letters, Latin Extended-A, the euro sign and common punctuation. Tested with the Mustang validator; this is not a statement of legal compliance, and XRechnung and Peppol output are not produced.',
1160
+ displayOptions: { show: { '@version': [2], operation: ['invoice'] } },
1161
+ },
1162
+ {
1163
+ displayName: 'E-Invoice Options',
1164
+ name: 'eInvoiceOptions',
1165
+ type: 'collection',
1166
+ placeholder: 'Add Option',
1167
+ default: {},
1168
+ displayOptions: { show: { '@version': [2], operation: ['invoice'], eInvoice: [true] } },
1169
+ options: [
1170
+ {
1171
+ displayName: 'IBAN',
1172
+ name: 'iban',
1173
+ type: 'string',
1174
+ default: '',
1175
+ description: 'Seller bank account for the payment instructions (spaces are ignored)',
1176
+ },
1177
+ {
1178
+ displayName: 'Payment Terms',
1179
+ name: 'payment_terms',
1180
+ type: 'string',
1181
+ default: '',
1182
+ description: 'Payment terms text. Either this or a due date in the Invoice JSON is required.',
1183
+ },
1184
+ {
1185
+ displayName: 'Tax Category',
1186
+ name: 'tax_category',
1187
+ type: 'options',
1188
+ options: [
1189
+ { name: 'Exempt (E)', value: 'E' },
1190
+ { name: 'Not Subject to VAT (O)', value: 'O' },
1191
+ { name: 'Reverse Charge (AE)', value: 'AE' },
1192
+ { name: 'Standard Rate (S)', value: 'S' },
1193
+ { name: 'Zero Rate (Z)', value: 'Z' },
1194
+ ],
1195
+ default: 'S',
1196
+ description: 'EN 16931 VAT category for the whole invoice. S is the default when tax_rate is above 0; required when tax_rate is 0 or missing.',
1197
+ },
1198
+ {
1199
+ displayName: 'Tax Exemption Reason',
1200
+ name: 'tax_exemption_reason',
1201
+ type: 'string',
1202
+ default: '',
1203
+ description: 'Reason text, required for the Exempt, Reverse Charge and Not Subject to VAT categories',
1204
+ },
1205
+ ],
1206
+ },
601
1207
  {
602
1208
  displayName: 'Flatten',
603
1209
  name: 'flatten',
@@ -618,7 +1224,7 @@ class Pdfops {
618
1224
  hint: 'The name of the output item’s binary field to write the resulting PDF to',
619
1225
  displayOptions: {
620
1226
  show: {
621
- operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata'],
1227
+ operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata', 'addFields', 'makeFillable', 'attach', 'edit', 'htmlToPdf', 'imageToPdf', 'textToPdf'],
622
1228
  },
623
1229
  },
624
1230
  },
@@ -631,15 +1237,36 @@ class Pdfops {
631
1237
  description: 'File name for the output PDF. Defaults per operation. For Split PDF it is the prefix: parts are named prefix-1.pdf, prefix-2.pdf and so on',
632
1238
  displayOptions: {
633
1239
  show: {
634
- operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata'],
1240
+ operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata', 'addFields', 'makeFillable', 'attach', 'edit', 'htmlToPdf', 'imageToPdf', 'textToPdf'],
635
1241
  },
636
1242
  },
637
1243
  },
1244
+ {
1245
+ displayName: 'Output Binary Field',
1246
+ name: 'outputBinaryPropertyName',
1247
+ type: 'string',
1248
+ default: 'data',
1249
+ hint: 'The name of the output item’s binary field to write the Excel workbook to',
1250
+ displayOptions: {
1251
+ show: { operation: ['extractText'], textFormat: ['json'], tablesFormat: ['xlsx'] },
1252
+ },
1253
+ },
1254
+ {
1255
+ displayName: 'Output File Name',
1256
+ name: 'fileName',
1257
+ type: 'string',
1258
+ default: 'tables.xlsx',
1259
+ placeholder: 'e.g. tables.xlsx',
1260
+ description: 'File name for the output Excel workbook',
1261
+ displayOptions: {
1262
+ show: { operation: ['extractText'], textFormat: ['json'], tablesFormat: ['xlsx'] },
1263
+ },
1264
+ },
638
1265
  ],
639
1266
  };
640
1267
  }
641
1268
  async execute() {
642
- var _a, _b, _c, _d, _e, _f;
1269
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
643
1270
  const items = this.getInputData();
644
1271
  const returnData = [];
645
1272
  const operation = this.getNodeParameter('operation', 0);
@@ -650,6 +1277,7 @@ class Pdfops {
650
1277
  'X-Pdfops-Client': 'n8n',
651
1278
  'X-Pdfops-Client-Version': NODE_PACKAGE_VERSION,
652
1279
  };
1280
+ options.disableFollowRedirect = true;
653
1281
  if (hasCredential) {
654
1282
  return await this.helpers.httpRequestWithAuthentication.call(this, 'pdfopsApi', options);
655
1283
  }
@@ -673,11 +1301,41 @@ class Pdfops {
673
1301
  }
674
1302
  return value;
675
1303
  };
1304
+ const jsonArrayParam = (name, itemIndex) => {
1305
+ const raw = this.getNodeParameter(name, itemIndex);
1306
+ let value = raw;
1307
+ if (typeof raw === 'string') {
1308
+ try {
1309
+ value = JSON.parse(raw);
1310
+ }
1311
+ catch {
1312
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Parameter "${name}" is not valid JSON`, {
1313
+ itemIndex,
1314
+ });
1315
+ }
1316
+ }
1317
+ if (!Array.isArray(value)) {
1318
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Parameter "${name}" must be a JSON array`, {
1319
+ itemIndex,
1320
+ });
1321
+ }
1322
+ return value;
1323
+ };
676
1324
  const pdfBlob = async (itemIndex, binaryPropertyName) => {
677
1325
  this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
678
1326
  const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);
679
1327
  return new Blob([new Uint8Array(buffer)], { type: 'application/pdf' });
680
1328
  };
1329
+ const fileBlob = async (itemIndex, binaryPropertyName, mimeType) => {
1330
+ const meta = this.helpers.assertBinaryData(itemIndex, binaryPropertyName);
1331
+ const buffer = await this.helpers.getBinaryDataBuffer(itemIndex, binaryPropertyName);
1332
+ return {
1333
+ blob: new Blob([new Uint8Array(buffer)], {
1334
+ type: mimeType || meta.mimeType || 'application/octet-stream',
1335
+ }),
1336
+ fileName: meta.fileName || binaryPropertyName,
1337
+ };
1338
+ };
681
1339
  if (operation === 'merge') {
682
1340
  const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
683
1341
  const fileName = this.getNodeParameter('fileName', 0) || 'merged.pdf';
@@ -721,13 +1379,252 @@ class Pdfops {
721
1379
  }
722
1380
  return [returnData];
723
1381
  }
1382
+ if (operation === 'imageToPdf') {
1383
+ const formData = new FormData();
1384
+ try {
1385
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
1386
+ const fileName = this.getNodeParameter('fileName', 0) || 'images.pdf';
1387
+ const outputBinaryPropertyName = this.getNodeParameter('outputBinaryPropertyName', 0);
1388
+ for (let i = 0; i < items.length; i++) {
1389
+ const image = await fileBlob(i, binaryPropertyName);
1390
+ formData.append('pdf', image.blob, image.fileName);
1391
+ }
1392
+ const imageOptions = this.getNodeParameter('imageOptions', 0, {});
1393
+ for (const [k, v] of Object.entries(imageOptions)) {
1394
+ if (v !== undefined && v !== null && v !== '')
1395
+ formData.append(k, String(v));
1396
+ }
1397
+ const response = (await request({
1398
+ method: 'POST',
1399
+ url: `${BASE_URL}/api/image-to-pdf`,
1400
+ body: formData,
1401
+ encoding: 'arraybuffer',
1402
+ }));
1403
+ returnData.push({
1404
+ json: { fileName, imageCount: items.length },
1405
+ binary: {
1406
+ [outputBinaryPropertyName]: await this.helpers.prepareBinaryData(response, fileName, 'application/pdf'),
1407
+ },
1408
+ pairedItem: items.map((_, i) => ({ item: i })),
1409
+ });
1410
+ }
1411
+ catch (error) {
1412
+ const apiError = (0, decodeApiError_1.decodeApiError)(error);
1413
+ if (this.continueOnFail()) {
1414
+ returnData.push({
1415
+ json: {
1416
+ error: (_d = apiError === null || apiError === void 0 ? void 0 : apiError.message) !== null && _d !== void 0 ? _d : error.message,
1417
+ ...((apiError === null || apiError === void 0 ? void 0 : apiError.details) ? { message: apiError.details } : {}),
1418
+ },
1419
+ pairedItem: items.map((_, i) => ({ item: i })),
1420
+ });
1421
+ }
1422
+ else {
1423
+ throw withApiMessage(new n8n_workflow_1.NodeApiError(this.getNode(), error), apiError);
1424
+ }
1425
+ }
1426
+ return [returnData];
1427
+ }
724
1428
  if (operation === 'usage' && !hasCredential) {
725
1429
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'The Get Usage operation requires a PDFops API credential (free key at https://pdfops.dev/pricing)');
726
1430
  }
1431
+ if (operation === 'makeFillable') {
1432
+ const MAX_ROUNDS = 25;
1433
+ for (let i = 0; i < items.length; i++) {
1434
+ let apiMessage;
1435
+ try {
1436
+ const binaryName = this.getNodeParameter('binaryPropertyName', i);
1437
+ this.helpers.assertBinaryData(i, binaryName);
1438
+ let current = Buffer.from(await this.helpers.getBinaryDataBuffer(i, binaryName));
1439
+ const outProp = this.getNodeParameter('outputBinaryPropertyName', i);
1440
+ const fileName = this.getNodeParameter('fileName', i) || 'fillable.pdf';
1441
+ const password = this.getNodeParameter('password', i);
1442
+ const detectOptions = this.getNodeParameter('detectOptions', i, {});
1443
+ const firstPages = this.getNodeParameter('pages', i);
1444
+ let sendPages = firstPages;
1445
+ let count = 0;
1446
+ const names = [];
1447
+ const skipped = new Set();
1448
+ let warning = '';
1449
+ let truncated = false;
1450
+ let truncatedBy = '';
1451
+ let nextPages = '';
1452
+ let rounds = 0;
1453
+ let stoppedBy;
1454
+ let stopError;
1455
+ let lastNoFields;
1456
+ let finished = false;
1457
+ for (let round = 0; round < MAX_ROUNDS; round++) {
1458
+ const formData = new FormData();
1459
+ formData.append('pdf', new Blob([new Uint8Array(current)], { type: 'application/pdf' }), 'input.pdf');
1460
+ formData.append('format', 'pdf');
1461
+ if (password)
1462
+ formData.append('password', password);
1463
+ if (sendPages)
1464
+ formData.append('pages', sendPages);
1465
+ for (const [k, v] of Object.entries(detectOptions)) {
1466
+ if (v !== undefined && v !== null && v !== '')
1467
+ formData.append(k, String(v));
1468
+ }
1469
+ let full;
1470
+ try {
1471
+ rounds++;
1472
+ full = (await request({
1473
+ method: 'POST',
1474
+ url: `${BASE_URL}/api/detect-fields`,
1475
+ body: formData,
1476
+ encoding: 'arraybuffer',
1477
+ returnFullResponse: true,
1478
+ }));
1479
+ }
1480
+ catch (error) {
1481
+ const body = (0, decodeApiError_1.decodeApiBody)(error);
1482
+ if ((body === null || body === void 0 ? void 0 : body.error) === 'no_fields') {
1483
+ lastNoFields = error;
1484
+ const sk = body.pagesSkipped;
1485
+ if (Array.isArray(sk)) {
1486
+ for (const x of sk) {
1487
+ const y = x;
1488
+ if (typeof (y === null || y === void 0 ? void 0 : y.page) === 'number' && y.reason === 'too_complex')
1489
+ skipped.add(y.page);
1490
+ }
1491
+ }
1492
+ nextPages = typeof body.nextPages === 'string' ? body.nextPages : '';
1493
+ truncated = body.truncated === true && nextPages !== '';
1494
+ if (truncated && nextPages !== sendPages) {
1495
+ sendPages = nextPages;
1496
+ continue;
1497
+ }
1498
+ if (truncated) {
1499
+ stoppedBy = { code: 'stalled', message: `pages ${nextPages} were offered again and nothing was found on them` };
1500
+ }
1501
+ finished = true;
1502
+ break;
1503
+ }
1504
+ if (round === 0) {
1505
+ throw withApiMessage(new n8n_workflow_1.NodeApiError(this.getNode(), error, { itemIndex: i }), (0, decodeApiError_1.decodeApiError)(error), i);
1506
+ }
1507
+ const api = (0, decodeApiError_1.decodeApiError)(error);
1508
+ stopError = error;
1509
+ stoppedBy = {
1510
+ code: typeof (body === null || body === void 0 ? void 0 : body.error) === 'string' ? body.error : 'network_error',
1511
+ message: (_f = (_e = api === null || api === void 0 ? void 0 : api.details) !== null && _e !== void 0 ? _e : api === null || api === void 0 ? void 0 : api.message) !== null && _f !== void 0 ? _f : error.message,
1512
+ };
1513
+ truncated = true;
1514
+ nextPages = sendPages;
1515
+ finished = true;
1516
+ break;
1517
+ }
1518
+ lastNoFields = undefined;
1519
+ const h = (_g = full.headers) !== null && _g !== void 0 ? _g : {};
1520
+ const n = h['x-pdfops-fields'];
1521
+ const added = typeof n === 'string' && /^\d+$/.test(n) ? Number(n) : 0;
1522
+ count += added;
1523
+ try {
1524
+ const parsed = JSON.parse(String(h['x-pdfops-field-names']));
1525
+ if (Array.isArray(parsed))
1526
+ names.push(...parsed.filter((x) => typeof x === 'string'));
1527
+ }
1528
+ catch {
1529
+ }
1530
+ const skippedHeader = h['x-pdfops-pages-skipped'];
1531
+ if (typeof skippedHeader === 'string') {
1532
+ for (const p of skippedHeader.split(','))
1533
+ if (/^\d+$/.test(p))
1534
+ skipped.add(Number(p));
1535
+ }
1536
+ const w = h['x-pdfops-warning'];
1537
+ if (!warning && typeof w === 'string' && w)
1538
+ warning = w;
1539
+ truncatedBy = typeof h['x-pdfops-truncated-by'] === 'string' ? h['x-pdfops-truncated-by'] : '';
1540
+ current = Buffer.from(full.body);
1541
+ truncated = headerTrue(h['x-pdfops-truncated']);
1542
+ nextPages = typeof h['x-pdfops-next-pages'] === 'string' ? h['x-pdfops-next-pages'] : '';
1543
+ if (!truncated || !nextPages) {
1544
+ finished = true;
1545
+ break;
1546
+ }
1547
+ if (nextPages === sendPages && added === 0) {
1548
+ stoppedBy = { code: 'stalled', message: `pages ${nextPages} were offered again and nothing new was found on them` };
1549
+ finished = true;
1550
+ break;
1551
+ }
1552
+ sendPages = nextPages;
1553
+ }
1554
+ if (!finished) {
1555
+ truncated = true;
1556
+ stoppedBy = { code: 'max_rounds', message: `stopped at the limit of ${MAX_ROUNDS} calls` };
1557
+ }
1558
+ if (!truncated) {
1559
+ truncatedBy = '';
1560
+ nextPages = '';
1561
+ }
1562
+ if (count === 0) {
1563
+ const notAnalysed = skipped.size ? ` Pages not analysed: ${[...skipped].sort((a, b) => a - b).join(', ')} (too_complex).` : '';
1564
+ if (stopError) {
1565
+ const api = (0, decodeApiError_1.decodeApiError)(stopError);
1566
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${(_h = api === null || api === void 0 ? void 0 : api.message) !== null && _h !== void 0 ? _h : stopError.message}${(api === null || api === void 0 ? void 0 : api.details) ? `: ${api.details}` : ''}${nextPages ? `; pages ${nextPages} remain` : ''}.${notAnalysed}`, { itemIndex: i });
1567
+ }
1568
+ if (stoppedBy) {
1569
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No fields found in the pages analysed so far${nextPages ? `; pages ${nextPages} remain` : ''} (stopped: ${stoppedBy.code}). Run again with Pages set to ${nextPages || 'the pages not done'}.${notAnalysed}`, { itemIndex: i });
1570
+ }
1571
+ if (lastNoFields) {
1572
+ if (skipped.size) {
1573
+ const api = (0, decodeApiError_1.decodeApiError)(lastNoFields);
1574
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `${(_j = api === null || api === void 0 ? void 0 : api.message) !== null && _j !== void 0 ? _j : 'no_fields'}${(api === null || api === void 0 ? void 0 : api.details) ? `: ${api.details}` : ''} Pages not analysed: ${[...skipped].sort((a, b) => a - b).join(', ')} (too_complex).`, { itemIndex: i });
1575
+ }
1576
+ throw withApiMessage(new n8n_workflow_1.NodeApiError(this.getNode(), lastNoFields, { itemIndex: i }), (0, decodeApiError_1.decodeApiError)(lastNoFields), i);
1577
+ }
1578
+ }
1579
+ const json = {
1580
+ fileName,
1581
+ fields_count: count,
1582
+ field_names: names,
1583
+ truncated,
1584
+ rounds,
1585
+ };
1586
+ if (truncatedBy)
1587
+ json.truncated_by = truncatedBy.split(',');
1588
+ if (nextPages && truncated)
1589
+ json.next_pages = nextPages;
1590
+ if (skipped.size)
1591
+ json.pages_skipped = [...skipped].sort((a, b) => a - b);
1592
+ if (warning)
1593
+ json.warning = warning;
1594
+ if (stoppedBy) {
1595
+ json.stopped_by = stoppedBy;
1596
+ json.message = `Stopped (${stoppedBy.code}) after ${rounds} call(s): ${stoppedBy.message}. The PDF holds the ${count} fields added so far; run again on it with Pages set to ${nextPages || 'the pages not done'} to finish.`;
1597
+ }
1598
+ returnData.push({
1599
+ json,
1600
+ binary: { [outProp]: await this.helpers.prepareBinaryData(current, fileName, 'application/pdf') },
1601
+ pairedItem: { item: i },
1602
+ });
1603
+ }
1604
+ catch (error) {
1605
+ apiMessage = (0, decodeApiError_1.decodeApiError)(error);
1606
+ if (this.continueOnFail()) {
1607
+ returnData.push({
1608
+ json: {
1609
+ error: (_k = apiMessage === null || apiMessage === void 0 ? void 0 : apiMessage.message) !== null && _k !== void 0 ? _k : error.message,
1610
+ ...((apiMessage === null || apiMessage === void 0 ? void 0 : apiMessage.details) ? { message: apiMessage.details } : {}),
1611
+ },
1612
+ pairedItem: { item: i },
1613
+ });
1614
+ continue;
1615
+ }
1616
+ if (error instanceof n8n_workflow_1.NodeOperationError)
1617
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error.message, { itemIndex: i });
1618
+ throw withApiMessage(new n8n_workflow_1.NodeApiError(this.getNode(), error, { itemIndex: i }), apiMessage, i);
1619
+ }
1620
+ }
1621
+ return [returnData];
1622
+ }
727
1623
  for (let i = 0; i < items.length; i++) {
728
1624
  let options;
729
1625
  let binaryOut;
730
1626
  let splitOut = false;
1627
+ let textOut = false;
731
1628
  try {
732
1629
  if (operation === 'inspect') {
733
1630
  const formData = new FormData();
@@ -759,10 +1656,19 @@ class Pdfops {
759
1656
  };
760
1657
  }
761
1658
  else if (operation === 'invoice') {
1659
+ const invoiceBody = { ...jsonParam('invoice', i) };
1660
+ if (this.getNodeParameter('eInvoice', i, false)) {
1661
+ invoiceBody.e_invoice = 'factur-x';
1662
+ const eInvoiceOptions = this.getNodeParameter('eInvoiceOptions', i, {});
1663
+ for (const [k, v] of Object.entries(eInvoiceOptions)) {
1664
+ if (v !== undefined && v !== null && v !== '')
1665
+ invoiceBody[k] = v;
1666
+ }
1667
+ }
762
1668
  options = {
763
1669
  method: 'POST',
764
1670
  url: `${BASE_URL}/api/invoice`,
765
- body: jsonParam('invoice', i),
1671
+ body: invoiceBody,
766
1672
  json: true,
767
1673
  encoding: 'arraybuffer',
768
1674
  };
@@ -771,6 +1677,28 @@ class Pdfops {
771
1677
  property: this.getNodeParameter('outputBinaryPropertyName', i),
772
1678
  };
773
1679
  }
1680
+ else if (operation === 'htmlToPdf' || operation === 'textToPdf') {
1681
+ const isHtml = operation === 'htmlToPdf';
1682
+ const body = isHtml
1683
+ ? { html: this.getNodeParameter('html', i) }
1684
+ : { content: this.getNodeParameter('content', i) };
1685
+ const extra = this.getNodeParameter(isHtml ? 'htmlOptions' : 'textOptions', i, {});
1686
+ for (const [k, v] of Object.entries(extra)) {
1687
+ if (v !== undefined && v !== null && v !== '')
1688
+ body[k] = v;
1689
+ }
1690
+ options = {
1691
+ method: 'POST',
1692
+ url: `${BASE_URL}/api/${isHtml ? 'html-to-pdf' : 'text-to-pdf'}`,
1693
+ body,
1694
+ json: true,
1695
+ encoding: 'arraybuffer',
1696
+ };
1697
+ binaryOut = {
1698
+ fileName: this.getNodeParameter('fileName', i) || 'document.pdf',
1699
+ property: this.getNodeParameter('outputBinaryPropertyName', i),
1700
+ };
1701
+ }
774
1702
  else if (DOC_OPS[operation]) {
775
1703
  const spec = DOC_OPS[operation];
776
1704
  const formData = new FormData();
@@ -816,7 +1744,104 @@ class Pdfops {
816
1744
  formData.append(k, String(v !== null && v !== void 0 ? v : ''));
817
1745
  }
818
1746
  }
819
- if (spec.output === 'pdf') {
1747
+ else if (operation === 'addFields') {
1748
+ formData.append('fields', JSON.stringify(jsonArrayParam('formFields', i)));
1749
+ }
1750
+ else if (operation === 'edit') {
1751
+ formData.append('items', JSON.stringify(jsonArrayParam('editItems', i)));
1752
+ const images = this.getNodeParameter('imageFiles', i, {}).image;
1753
+ const seenImageNames = new Set();
1754
+ for (const image of images !== null && images !== void 0 ? images : []) {
1755
+ if (!/^[A-Za-z0-9_.-]{1,64}$/.test((_l = image.fieldName) !== null && _l !== void 0 ? _l : '')) {
1756
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Image field name "${(_m = image.fieldName) !== null && _m !== void 0 ? _m : ''}" is not allowed: use 1-64 letters, digits, "_", "." or "-"`, { itemIndex: i });
1757
+ }
1758
+ if (['pdf', 'password', 'items'].includes(image.fieldName)) {
1759
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Image field name "${image.fieldName}" is reserved; use another name`, { itemIndex: i });
1760
+ }
1761
+ if (seenImageNames.has(image.fieldName)) {
1762
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Image field name "${image.fieldName}" is used twice; each image needs its own name`, { itemIndex: i });
1763
+ }
1764
+ seenImageNames.add(image.fieldName);
1765
+ const file = await fileBlob(i, image.binaryPropertyName);
1766
+ formData.append(image.fieldName, file.blob, file.fileName);
1767
+ }
1768
+ }
1769
+ else if (operation === 'attach') {
1770
+ const files = this.getNodeParameter('attachments', i, {}).file;
1771
+ if (!(files === null || files === void 0 ? void 0 : files.length)) {
1772
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Add at least one file to attach', {
1773
+ itemIndex: i,
1774
+ });
1775
+ }
1776
+ const perFile = [];
1777
+ for (const f of files) {
1778
+ const file = await fileBlob(i, f.binaryPropertyName, f.mimeType);
1779
+ const name = f.name || file.fileName;
1780
+ formData.append('file', file.blob, name);
1781
+ const entry = { name };
1782
+ if (f.mimeType)
1783
+ entry.mime_type = f.mimeType;
1784
+ if (f.description)
1785
+ entry.description = f.description;
1786
+ if (f.relationship)
1787
+ entry.relationship = f.relationship;
1788
+ perFile.push(entry);
1789
+ }
1790
+ formData.append('options', JSON.stringify(perFile));
1791
+ }
1792
+ else if (operation === 'findText') {
1793
+ add('query', this.getNodeParameter('query', i));
1794
+ add('pages', this.getNodeParameter('pages', i));
1795
+ for (const [k, v] of Object.entries(collection('findOptions')))
1796
+ add(k, v);
1797
+ }
1798
+ else if (operation === 'extractText') {
1799
+ add('pages', this.getNodeParameter('pages', i));
1800
+ }
1801
+ else if (operation === 'detectFields') {
1802
+ add('pages', this.getNodeParameter('pages', i));
1803
+ for (const [k, v] of Object.entries(collection('detectOptions')))
1804
+ add(k, v);
1805
+ }
1806
+ if (spec.output === 'extract') {
1807
+ const format = this.getNodeParameter('textFormat', i);
1808
+ const tablesFormat = format === 'json' ? this.getNodeParameter('tablesFormat', i) : 'json';
1809
+ if (format === 'text')
1810
+ formData.append('format', 'text');
1811
+ if (tablesFormat !== 'json')
1812
+ formData.append('tables_format', tablesFormat);
1813
+ if (tablesFormat === 'xlsx') {
1814
+ options = {
1815
+ method: 'POST',
1816
+ url: `${BASE_URL}/api/${spec.path}`,
1817
+ body: formData,
1818
+ encoding: 'arraybuffer',
1819
+ };
1820
+ binaryOut = {
1821
+ fileName: this.getNodeParameter('fileName', i) || spec.defaultFile,
1822
+ property: this.getNodeParameter('outputBinaryPropertyName', i),
1823
+ mimeType: XLSX_MIME_TYPE,
1824
+ };
1825
+ }
1826
+ else if (format === 'text') {
1827
+ textOut = true;
1828
+ options = {
1829
+ method: 'POST',
1830
+ url: `${BASE_URL}/api/${spec.path}`,
1831
+ body: formData,
1832
+ encoding: 'text',
1833
+ };
1834
+ }
1835
+ else {
1836
+ options = {
1837
+ method: 'POST',
1838
+ url: `${BASE_URL}/api/${spec.path}`,
1839
+ body: formData,
1840
+ json: true,
1841
+ };
1842
+ }
1843
+ }
1844
+ else if (spec.output === 'pdf') {
820
1845
  options = {
821
1846
  method: 'POST',
822
1847
  url: `${BASE_URL}/api/${spec.path}`,
@@ -861,7 +1886,7 @@ class Pdfops {
861
1886
  throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
862
1887
  }
863
1888
  try {
864
- if (binaryOut && !splitOut)
1889
+ if ((binaryOut && !splitOut) || textOut)
865
1890
  options.returnFullResponse = true;
866
1891
  const response = await request(options);
867
1892
  if (splitOut && binaryOut) {
@@ -882,10 +1907,20 @@ class Pdfops {
882
1907
  });
883
1908
  }
884
1909
  }
1910
+ else if (textOut) {
1911
+ const full = response;
1912
+ returnData.push({
1913
+ json: {
1914
+ text: full.body,
1915
+ truncated: headerTrue((_o = full.headers) === null || _o === void 0 ? void 0 : _o['x-pdfops-truncated']),
1916
+ },
1917
+ pairedItem: { item: i },
1918
+ });
1919
+ }
885
1920
  else if (binaryOut) {
886
1921
  const full = response;
887
1922
  const json = { fileName: binaryOut.fileName };
888
- const fieldMap = (_d = full.headers) === null || _d === void 0 ? void 0 : _d['x-pdfops-field-map'];
1923
+ const fieldMap = (_p = full.headers) === null || _p === void 0 ? void 0 : _p['x-pdfops-field-map'];
889
1924
  if (fieldMap) {
890
1925
  try {
891
1926
  json.field_map = JSON.parse(fieldMap);
@@ -894,13 +1929,58 @@ class Pdfops {
894
1929
  json.field_map = fieldMap;
895
1930
  }
896
1931
  }
897
- const note = (_e = full.headers) === null || _e === void 0 ? void 0 : _e['x-pdfops-note'];
1932
+ const note = (_q = full.headers) === null || _q === void 0 ? void 0 : _q['x-pdfops-note'];
898
1933
  if (note)
899
1934
  json.note = note;
1935
+ if (operation === 'attach') {
1936
+ let keys = [];
1937
+ try {
1938
+ const parsed = JSON.parse(String((_r = full.headers) === null || _r === void 0 ? void 0 : _r['x-pdfops-attachment-keys']));
1939
+ if (Array.isArray(parsed)) {
1940
+ keys = parsed
1941
+ .filter((e) => typeof (e === null || e === void 0 ? void 0 : e.name) === 'string' && typeof (e === null || e === void 0 ? void 0 : e.key) === 'string')
1942
+ .map((e) => ({ name: e.name, key: e.key }));
1943
+ }
1944
+ }
1945
+ catch {
1946
+ keys = [];
1947
+ }
1948
+ json.attachment_keys = keys;
1949
+ }
1950
+ if (operation === 'extractText') {
1951
+ if (headerTrue((_s = full.headers) === null || _s === void 0 ? void 0 : _s['x-pdfops-truncated'])) {
1952
+ json.truncated = true;
1953
+ const truncatedBy = (_t = full.headers) === null || _t === void 0 ? void 0 : _t['x-pdfops-truncated-by'];
1954
+ if (typeof truncatedBy === 'string' && truncatedBy) {
1955
+ json.truncated_by = truncatedBy.split(',');
1956
+ }
1957
+ }
1958
+ if (headerTrue((_u = full.headers) === null || _u === void 0 ? void 0 : _u['x-pdfops-cells-truncated']))
1959
+ json.cells_truncated = true;
1960
+ const body = Buffer.from(full.body);
1961
+ if (body.length < 4 || body.readUInt32BE(0) !== 0x504b0304) {
1962
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'The API did not return an Excel workbook (the response is not a zip file)', { itemIndex: i });
1963
+ }
1964
+ }
1965
+ if (operation === 'addFields') {
1966
+ const warning = (_v = full.headers) === null || _v === void 0 ? void 0 : _v['x-pdfops-warning'];
1967
+ if (typeof warning === 'string' && warning)
1968
+ json.warning = warning;
1969
+ }
1970
+ if (operation === 'htmlToPdf') {
1971
+ for (const [header, key] of [
1972
+ ['x-pdfops-pages', 'pages'],
1973
+ ['x-pdfops-blocked-requests', 'blocked_requests'],
1974
+ ]) {
1975
+ const value = (_w = full.headers) === null || _w === void 0 ? void 0 : _w[header];
1976
+ if (typeof value === 'string' && /^\d+$/.test(value))
1977
+ json[key] = Number(value);
1978
+ }
1979
+ }
900
1980
  returnData.push({
901
1981
  json,
902
1982
  binary: {
903
- [binaryOut.property]: await this.helpers.prepareBinaryData(full.body, binaryOut.fileName, 'application/pdf'),
1983
+ [binaryOut.property]: await this.helpers.prepareBinaryData(full.body, binaryOut.fileName, (_x = binaryOut.mimeType) !== null && _x !== void 0 ? _x : 'application/pdf'),
904
1984
  },
905
1985
  pairedItem: { item: i },
906
1986
  });
@@ -914,7 +1994,7 @@ class Pdfops {
914
1994
  if (this.continueOnFail()) {
915
1995
  returnData.push({
916
1996
  json: {
917
- error: (_f = apiError === null || apiError === void 0 ? void 0 : apiError.message) !== null && _f !== void 0 ? _f : error.message,
1997
+ error: (_y = apiError === null || apiError === void 0 ? void 0 : apiError.message) !== null && _y !== void 0 ? _y : error.message,
918
1998
  ...((apiError === null || apiError === void 0 ? void 0 : apiError.details) ? { message: apiError.details } : {}),
919
1999
  },
920
2000
  pairedItem: { item: i },