n8n-nodes-pdfops 0.2.2 → 0.3.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.
- package/README.md +47 -28
- package/dist/nodes/Pdfops/Pdfops.node.js +477 -12
- package/dist/nodes/Pdfops/Pdfops.node.js.map +1 -1
- package/dist/nodes/Pdfops/Pdfops.node.json +33 -0
- package/dist/nodes/Pdfops/pdfops.dark.svg +7 -2
- package/dist/nodes/Pdfops/pdfops.svg +7 -2
- package/dist/package.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -4,7 +4,7 @@ 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.
|
|
7
|
+
const NODE_PACKAGE_VERSION = '0.3.0';
|
|
8
8
|
function withApiMessage(wrapped, apiError, itemIndex) {
|
|
9
9
|
var _a;
|
|
10
10
|
if (itemIndex !== undefined)
|
|
@@ -15,16 +15,28 @@ function withApiMessage(wrapped, apiError, itemIndex) {
|
|
|
15
15
|
}
|
|
16
16
|
return wrapped;
|
|
17
17
|
}
|
|
18
|
+
const DOC_OPS = {
|
|
19
|
+
extractPages: { path: 'extract-pages', output: 'pdf', defaultFile: 'extracted.pdf' },
|
|
20
|
+
deletePages: { path: 'delete-pages', output: 'pdf', defaultFile: 'pages-deleted.pdf' },
|
|
21
|
+
rotate: { path: 'rotate', output: 'pdf', defaultFile: 'rotated.pdf' },
|
|
22
|
+
split: { path: 'split', output: 'parts', defaultFile: 'split' },
|
|
23
|
+
watermark: { path: 'watermark', output: 'pdf', defaultFile: 'watermarked.pdf' },
|
|
24
|
+
pageNumbers: { path: 'page-numbers', output: 'pdf', defaultFile: 'numbered.pdf' },
|
|
25
|
+
unlock: { path: 'unlock', output: 'pdf', defaultFile: 'unlocked.pdf' },
|
|
26
|
+
protect: { path: 'protect', output: 'pdf', defaultFile: 'protected.pdf' },
|
|
27
|
+
metadata: { path: 'metadata', output: 'json', defaultFile: '' },
|
|
28
|
+
setMetadata: { path: 'set-metadata', output: 'pdf', defaultFile: 'metadata-updated.pdf' },
|
|
29
|
+
};
|
|
18
30
|
class Pdfops {
|
|
19
31
|
constructor() {
|
|
20
32
|
this.description = {
|
|
21
|
-
displayName: 'PDFops',
|
|
33
|
+
displayName: 'PDFops: Fill PDF Forms, Merge, Invoice',
|
|
22
34
|
name: 'pdfops',
|
|
23
35
|
icon: { light: 'file:pdfops.svg', dark: 'file:pdfops.dark.svg' },
|
|
24
36
|
group: ['transform'],
|
|
25
37
|
version: 1,
|
|
26
38
|
subtitle: '={{$parameter["operation"]}}',
|
|
27
|
-
description: '
|
|
39
|
+
description: 'Fill, merge, split, rotate, watermark, number, protect, unlock and read PDFs and generate invoices. Works without an API key (100 calls/month).',
|
|
28
40
|
defaults: {
|
|
29
41
|
name: 'PDFops',
|
|
30
42
|
},
|
|
@@ -44,6 +56,30 @@ class Pdfops {
|
|
|
44
56
|
type: 'options',
|
|
45
57
|
noDataExpression: true,
|
|
46
58
|
options: [
|
|
59
|
+
{
|
|
60
|
+
name: 'Add Page Numbers',
|
|
61
|
+
value: 'pageNumbers',
|
|
62
|
+
action: 'Add page numbers to a PDF',
|
|
63
|
+
description: 'Stamp page numbers (for example "3 / 12") onto the pages of a PDF and output the numbered PDF',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'Add Watermark',
|
|
67
|
+
value: 'watermark',
|
|
68
|
+
action: 'Add a text watermark to a PDF',
|
|
69
|
+
description: 'Stamp diagonal or horizontal text (DRAFT, CONFIDENTIAL, a name) over the pages of a PDF and output the watermarked PDF',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'Delete Pages',
|
|
73
|
+
value: 'deletePages',
|
|
74
|
+
action: 'Delete pages from a PDF',
|
|
75
|
+
description: 'Remove the listed pages from a PDF and output the remaining pages in original order',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'Extract Pages',
|
|
79
|
+
value: 'extractPages',
|
|
80
|
+
action: 'Extract pages from a PDF',
|
|
81
|
+
description: 'Keep only the listed pages of a PDF, in the order given, and output them as a new PDF (also reorders and duplicates pages)',
|
|
82
|
+
},
|
|
47
83
|
{
|
|
48
84
|
name: 'Fill Form',
|
|
49
85
|
value: 'fill',
|
|
@@ -56,6 +92,12 @@ class Pdfops {
|
|
|
56
92
|
action: 'Generate an invoice PDF',
|
|
57
93
|
description: 'Generate a complete invoice PDF from structured JSON — no template needed',
|
|
58
94
|
},
|
|
95
|
+
{
|
|
96
|
+
name: 'Get Metadata',
|
|
97
|
+
value: 'metadata',
|
|
98
|
+
action: 'Get PDF metadata',
|
|
99
|
+
description: 'Read page count, page sizes, title, author, dates, encryption and form-field count of a PDF as JSON',
|
|
100
|
+
},
|
|
59
101
|
{
|
|
60
102
|
name: 'Get Usage',
|
|
61
103
|
value: 'usage',
|
|
@@ -74,6 +116,36 @@ class Pdfops {
|
|
|
74
116
|
action: 'Merge many PDF files into one',
|
|
75
117
|
description: 'Merge the PDFs from all incoming items (in item order) into a single PDF',
|
|
76
118
|
},
|
|
119
|
+
{
|
|
120
|
+
name: 'Protect PDF',
|
|
121
|
+
value: 'protect',
|
|
122
|
+
action: 'Password protect a PDF',
|
|
123
|
+
description: 'Encrypt a PDF with an open password and/or an owner password that restricts printing, copying and editing',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
name: 'Rotate Pages',
|
|
127
|
+
value: 'rotate',
|
|
128
|
+
action: 'Rotate pages of a PDF',
|
|
129
|
+
description: 'Rotate all or selected pages of a PDF by 90, 180 or 270 degrees',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'Set Metadata',
|
|
133
|
+
value: 'setMetadata',
|
|
134
|
+
action: 'Set PDF metadata',
|
|
135
|
+
description: 'Set the title, author, subject, keywords or creator of a PDF and output the updated PDF',
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
name: 'Split PDF',
|
|
139
|
+
value: 'split',
|
|
140
|
+
action: 'Split a PDF into several pdfs',
|
|
141
|
+
description: 'Split a PDF by page ranges or fixed chunk size; outputs one item per part, each with its own PDF binary',
|
|
142
|
+
},
|
|
143
|
+
{
|
|
144
|
+
name: 'Unlock PDF',
|
|
145
|
+
value: 'unlock',
|
|
146
|
+
action: 'Remove password protection from a PDF',
|
|
147
|
+
description: 'Remove encryption and print/copy/edit restrictions from a PDF you can already open (give the password if it needs one to open)',
|
|
148
|
+
},
|
|
77
149
|
],
|
|
78
150
|
default: 'fill',
|
|
79
151
|
},
|
|
@@ -86,7 +158,7 @@ class Pdfops {
|
|
|
86
158
|
hint: 'The name of the input item’s binary field containing the PDF',
|
|
87
159
|
displayOptions: {
|
|
88
160
|
show: {
|
|
89
|
-
operation: ['fill', 'inspect', 'merge'],
|
|
161
|
+
operation: ['fill', 'inspect', 'merge', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'metadata', 'setMetadata'],
|
|
90
162
|
},
|
|
91
163
|
},
|
|
92
164
|
},
|
|
@@ -103,6 +175,291 @@ class Pdfops {
|
|
|
103
175
|
},
|
|
104
176
|
},
|
|
105
177
|
},
|
|
178
|
+
{
|
|
179
|
+
displayName: 'Input PDF Password',
|
|
180
|
+
name: 'password',
|
|
181
|
+
type: 'string',
|
|
182
|
+
typeOptions: { password: true },
|
|
183
|
+
default: '',
|
|
184
|
+
description: 'Password needed to open the input PDF. Leave empty unless the input is encrypted with an open password.',
|
|
185
|
+
displayOptions: {
|
|
186
|
+
show: {
|
|
187
|
+
operation: [
|
|
188
|
+
'extractPages',
|
|
189
|
+
'deletePages',
|
|
190
|
+
'rotate',
|
|
191
|
+
'split',
|
|
192
|
+
'watermark',
|
|
193
|
+
'pageNumbers',
|
|
194
|
+
'unlock',
|
|
195
|
+
'protect',
|
|
196
|
+
'metadata',
|
|
197
|
+
'setMetadata',
|
|
198
|
+
],
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
displayName: 'Pages',
|
|
204
|
+
name: 'pages',
|
|
205
|
+
type: 'string',
|
|
206
|
+
default: '',
|
|
207
|
+
required: true,
|
|
208
|
+
placeholder: 'e.g. 1-3,5,8-',
|
|
209
|
+
description: '1-based page spec: comma-separated pages and ranges, e.g. "1-3,5,8-" (8- means page 8 to the end). Keeps exactly these pages in the order given, so "3,1" reorders and "1,1" duplicates.',
|
|
210
|
+
displayOptions: { show: { operation: ['extractPages'] } },
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
displayName: 'Pages to Delete',
|
|
214
|
+
name: 'pages',
|
|
215
|
+
type: 'string',
|
|
216
|
+
default: '',
|
|
217
|
+
required: true,
|
|
218
|
+
placeholder: 'e.g. 2,4-6,9-',
|
|
219
|
+
description: '1-based page spec of the pages to remove, e.g. "2,4-6,9-" (9- means page 9 to the end). Deleting every page is an error.',
|
|
220
|
+
displayOptions: { show: { operation: ['deletePages'] } },
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
displayName: 'Pages',
|
|
224
|
+
name: 'pages',
|
|
225
|
+
type: 'string',
|
|
226
|
+
default: '',
|
|
227
|
+
placeholder: 'e.g. 1-3,5 (empty = all pages)',
|
|
228
|
+
description: '1-based page spec such as "1-3,5". Leave empty to apply to every page.',
|
|
229
|
+
displayOptions: { show: { operation: ['rotate', 'watermark', 'pageNumbers'] } },
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
displayName: 'Degrees',
|
|
233
|
+
name: 'degrees',
|
|
234
|
+
type: 'options',
|
|
235
|
+
options: [
|
|
236
|
+
{ name: '90 (Clockwise)', value: 90 },
|
|
237
|
+
{ name: '180', value: 180 },
|
|
238
|
+
{ name: '270 (Clockwise)', value: 270 },
|
|
239
|
+
{ name: '-90 (Counter-Clockwise)', value: -90 },
|
|
240
|
+
],
|
|
241
|
+
default: 90,
|
|
242
|
+
description: 'How far to turn the pages clockwise. Added to each page’s existing rotation, so rotating a page already at 90 by 270 ends at 0.',
|
|
243
|
+
displayOptions: { show: { operation: ['rotate'] } },
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
displayName: 'Split By',
|
|
247
|
+
name: 'splitMode',
|
|
248
|
+
type: 'options',
|
|
249
|
+
options: [
|
|
250
|
+
{
|
|
251
|
+
name: 'Page Ranges',
|
|
252
|
+
value: 'ranges',
|
|
253
|
+
description: 'Each comma-separated group becomes one part, e.g. "1-2,3-5" gives two parts',
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
name: 'Chunk Size',
|
|
257
|
+
value: 'every',
|
|
258
|
+
description: 'Cut into parts of N pages each (the last part may be shorter)',
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
default: 'ranges',
|
|
262
|
+
displayOptions: { show: { operation: ['split'] } },
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
displayName: 'Ranges',
|
|
266
|
+
name: 'ranges',
|
|
267
|
+
type: 'string',
|
|
268
|
+
default: '',
|
|
269
|
+
required: true,
|
|
270
|
+
placeholder: 'e.g. 1-2,3-5',
|
|
271
|
+
description: '1-based page ranges; every comma-separated group becomes its own part, e.g. "1-2,3-5" gives two PDFs and "1,2,3" gives three single-page PDFs',
|
|
272
|
+
displayOptions: { show: { operation: ['split'], splitMode: ['ranges'] } },
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
displayName: 'Pages per Part',
|
|
276
|
+
name: 'every',
|
|
277
|
+
type: 'number',
|
|
278
|
+
typeOptions: { minValue: 1 },
|
|
279
|
+
default: 1,
|
|
280
|
+
required: true,
|
|
281
|
+
description: 'Number of pages in each part; for example 2 on a 5-page PDF gives parts 1-2, 3-4 and 5',
|
|
282
|
+
displayOptions: { show: { operation: ['split'], splitMode: ['every'] } },
|
|
283
|
+
},
|
|
284
|
+
{
|
|
285
|
+
displayName: 'Watermark Text',
|
|
286
|
+
name: 'text',
|
|
287
|
+
type: 'string',
|
|
288
|
+
default: 'DRAFT',
|
|
289
|
+
required: true,
|
|
290
|
+
description: 'Text to stamp on the pages, at most 200 characters. Latin (WinAnsi) characters only; other scripts are rejected.',
|
|
291
|
+
displayOptions: { show: { operation: ['watermark'] } },
|
|
292
|
+
},
|
|
293
|
+
{
|
|
294
|
+
displayName: 'Watermark Options',
|
|
295
|
+
name: 'watermarkOptions',
|
|
296
|
+
type: 'collection',
|
|
297
|
+
placeholder: 'Add Option',
|
|
298
|
+
default: {},
|
|
299
|
+
displayOptions: { show: { operation: ['watermark'] } },
|
|
300
|
+
options: [
|
|
301
|
+
{
|
|
302
|
+
displayName: 'Color',
|
|
303
|
+
name: 'color',
|
|
304
|
+
type: 'color',
|
|
305
|
+
default: '#808080',
|
|
306
|
+
description: 'Text colour as hex, #rgb or #rrggbb',
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
displayName: 'Opacity',
|
|
310
|
+
name: 'opacity',
|
|
311
|
+
type: 'number',
|
|
312
|
+
typeOptions: { minValue: 0.05, maxValue: 1, numberPrecision: 2 },
|
|
313
|
+
default: 0.15,
|
|
314
|
+
description: 'From 0.05 (faint) to 1 (solid)',
|
|
315
|
+
},
|
|
316
|
+
{
|
|
317
|
+
displayName: 'Position',
|
|
318
|
+
name: 'position',
|
|
319
|
+
type: 'options',
|
|
320
|
+
options: [
|
|
321
|
+
{ name: 'Bottom', value: 'bottom' },
|
|
322
|
+
{ name: 'Center', value: 'center' },
|
|
323
|
+
{ name: 'Top', value: 'top' },
|
|
324
|
+
],
|
|
325
|
+
default: 'center',
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
displayName: 'Rotation',
|
|
329
|
+
name: 'rotation',
|
|
330
|
+
type: 'number',
|
|
331
|
+
default: 45,
|
|
332
|
+
description: 'Degrees counter-clockwise as the viewer sees it; 0 is horizontal',
|
|
333
|
+
},
|
|
334
|
+
{
|
|
335
|
+
displayName: 'Size',
|
|
336
|
+
name: 'size',
|
|
337
|
+
type: 'number',
|
|
338
|
+
typeOptions: { minValue: 6, maxValue: 200 },
|
|
339
|
+
default: 48,
|
|
340
|
+
description: 'Font size in points (6-200)',
|
|
341
|
+
},
|
|
342
|
+
],
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
displayName: 'Page Number Options',
|
|
346
|
+
name: 'pageNumberOptions',
|
|
347
|
+
type: 'collection',
|
|
348
|
+
placeholder: 'Add Option',
|
|
349
|
+
default: {},
|
|
350
|
+
displayOptions: { show: { operation: ['pageNumbers'] } },
|
|
351
|
+
options: [
|
|
352
|
+
{
|
|
353
|
+
displayName: 'Format',
|
|
354
|
+
name: 'format',
|
|
355
|
+
type: 'string',
|
|
356
|
+
default: '{n} / {total}',
|
|
357
|
+
description: 'Label template. {n} is the page number, {total} the page count of the document, e.g. "Page {n} of {total}". At most 100 Latin characters.',
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
displayName: 'Margin',
|
|
361
|
+
name: 'margin',
|
|
362
|
+
type: 'number',
|
|
363
|
+
typeOptions: { minValue: 0, maxValue: 200 },
|
|
364
|
+
default: 24,
|
|
365
|
+
description: 'Distance from the page edge in points (0-200)',
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
displayName: 'Position',
|
|
369
|
+
name: 'position',
|
|
370
|
+
type: 'options',
|
|
371
|
+
options: [
|
|
372
|
+
{ name: 'Bottom Center', value: 'bottom-center' },
|
|
373
|
+
{ name: 'Bottom Left', value: 'bottom-left' },
|
|
374
|
+
{ name: 'Bottom Right', value: 'bottom-right' },
|
|
375
|
+
{ name: 'Top Center', value: 'top-center' },
|
|
376
|
+
{ name: 'Top Left', value: 'top-left' },
|
|
377
|
+
{ name: 'Top Right', value: 'top-right' },
|
|
378
|
+
],
|
|
379
|
+
default: 'bottom-center',
|
|
380
|
+
},
|
|
381
|
+
{
|
|
382
|
+
displayName: 'Size',
|
|
383
|
+
name: 'size',
|
|
384
|
+
type: 'number',
|
|
385
|
+
typeOptions: { minValue: 4, maxValue: 72 },
|
|
386
|
+
default: 10,
|
|
387
|
+
description: 'Font size in points (4-72)',
|
|
388
|
+
},
|
|
389
|
+
{
|
|
390
|
+
displayName: 'Start Number',
|
|
391
|
+
name: 'start',
|
|
392
|
+
type: 'number',
|
|
393
|
+
typeOptions: { minValue: 0, maxValue: 100000 },
|
|
394
|
+
default: 1,
|
|
395
|
+
description: 'Number shown on page 1 of the document. Page i shows start+i-1, even when Pages selects only some pages.',
|
|
396
|
+
},
|
|
397
|
+
],
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
displayName: 'Open Password',
|
|
401
|
+
name: 'userPassword',
|
|
402
|
+
type: 'string',
|
|
403
|
+
typeOptions: { password: true },
|
|
404
|
+
default: '',
|
|
405
|
+
description: 'Password required to open the output PDF (at most 128 characters). Set this and/or the Owner Password; at least one is required.',
|
|
406
|
+
displayOptions: { show: { operation: ['protect'] } },
|
|
407
|
+
},
|
|
408
|
+
{
|
|
409
|
+
displayName: 'Owner Password',
|
|
410
|
+
name: 'ownerPassword',
|
|
411
|
+
type: 'string',
|
|
412
|
+
typeOptions: { password: true },
|
|
413
|
+
default: '',
|
|
414
|
+
description: 'Password that lifts the permission restrictions (at most 128 characters). Restrictions only bind a viewer when an owner password is set.',
|
|
415
|
+
displayOptions: { show: { operation: ['protect'] } },
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
displayName: 'Protect Options',
|
|
419
|
+
name: 'protectOptions',
|
|
420
|
+
type: 'collection',
|
|
421
|
+
placeholder: 'Add Option',
|
|
422
|
+
default: {},
|
|
423
|
+
displayOptions: { show: { operation: ['protect'] } },
|
|
424
|
+
options: [
|
|
425
|
+
{
|
|
426
|
+
displayName: 'Allowed Permissions',
|
|
427
|
+
name: 'permissions',
|
|
428
|
+
type: 'multiOptions',
|
|
429
|
+
options: [
|
|
430
|
+
{ name: 'Annotate', value: 'annotate' },
|
|
431
|
+
{ name: 'Copy', value: 'copy' },
|
|
432
|
+
{ name: 'Fill Forms', value: 'fill-forms' },
|
|
433
|
+
{ name: 'Modify', value: 'modify' },
|
|
434
|
+
{ name: 'Print', value: 'print' },
|
|
435
|
+
],
|
|
436
|
+
default: ['print', 'copy', 'annotate', 'fill-forms'],
|
|
437
|
+
description: 'What viewers may do. Leave this option out to allow everything (except modify when an owner password is set); select none to allow nothing.',
|
|
438
|
+
},
|
|
439
|
+
],
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
displayName: 'Metadata',
|
|
443
|
+
name: 'metadataFields',
|
|
444
|
+
type: 'collection',
|
|
445
|
+
placeholder: 'Add Field',
|
|
446
|
+
default: {},
|
|
447
|
+
description: 'At least one field is required; an empty value clears that field',
|
|
448
|
+
displayOptions: { show: { operation: ['setMetadata'] } },
|
|
449
|
+
options: [
|
|
450
|
+
{ displayName: 'Author', name: 'author', type: 'string', default: '' },
|
|
451
|
+
{ displayName: 'Creator', name: 'creator', type: 'string', default: '' },
|
|
452
|
+
{
|
|
453
|
+
displayName: 'Keywords',
|
|
454
|
+
name: 'keywords',
|
|
455
|
+
type: 'string',
|
|
456
|
+
default: '',
|
|
457
|
+
description: 'Comma-separated list',
|
|
458
|
+
},
|
|
459
|
+
{ displayName: 'Subject', name: 'subject', type: 'string', default: '' },
|
|
460
|
+
{ displayName: 'Title', name: 'title', type: 'string', default: '' },
|
|
461
|
+
],
|
|
462
|
+
},
|
|
106
463
|
{
|
|
107
464
|
displayName: 'Invoice',
|
|
108
465
|
name: 'invoice',
|
|
@@ -136,7 +493,7 @@ class Pdfops {
|
|
|
136
493
|
hint: 'The name of the output item’s binary field to write the resulting PDF to',
|
|
137
494
|
displayOptions: {
|
|
138
495
|
show: {
|
|
139
|
-
operation: ['fill', 'merge', 'invoice'],
|
|
496
|
+
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata'],
|
|
140
497
|
},
|
|
141
498
|
},
|
|
142
499
|
},
|
|
@@ -146,10 +503,10 @@ class Pdfops {
|
|
|
146
503
|
type: 'string',
|
|
147
504
|
default: '',
|
|
148
505
|
placeholder: 'e.g. filled.pdf',
|
|
149
|
-
description: 'File name for the output PDF. Defaults per operation.',
|
|
506
|
+
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',
|
|
150
507
|
displayOptions: {
|
|
151
508
|
show: {
|
|
152
|
-
operation: ['fill', 'merge', 'invoice'],
|
|
509
|
+
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata'],
|
|
153
510
|
},
|
|
154
511
|
},
|
|
155
512
|
},
|
|
@@ -157,7 +514,7 @@ class Pdfops {
|
|
|
157
514
|
};
|
|
158
515
|
}
|
|
159
516
|
async execute() {
|
|
160
|
-
var _a, _b, _c, _d;
|
|
517
|
+
var _a, _b, _c, _d, _e, _f;
|
|
161
518
|
const items = this.getInputData();
|
|
162
519
|
const returnData = [];
|
|
163
520
|
const operation = this.getNodeParameter('operation', 0);
|
|
@@ -242,6 +599,7 @@ class Pdfops {
|
|
|
242
599
|
for (let i = 0; i < items.length; i++) {
|
|
243
600
|
let options;
|
|
244
601
|
let binaryOut;
|
|
602
|
+
let splitOut = false;
|
|
245
603
|
try {
|
|
246
604
|
if (operation === 'inspect') {
|
|
247
605
|
const formData = new FormData();
|
|
@@ -279,6 +637,79 @@ class Pdfops {
|
|
|
279
637
|
property: this.getNodeParameter('outputBinaryPropertyName', i),
|
|
280
638
|
};
|
|
281
639
|
}
|
|
640
|
+
else if (DOC_OPS[operation]) {
|
|
641
|
+
const spec = DOC_OPS[operation];
|
|
642
|
+
const formData = new FormData();
|
|
643
|
+
formData.append('pdf', await pdfBlob(i, this.getNodeParameter('binaryPropertyName', i)), 'input.pdf');
|
|
644
|
+
const add = (name, value) => {
|
|
645
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
646
|
+
formData.append(name, String(value));
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
add('password', this.getNodeParameter('password', i));
|
|
650
|
+
const collection = (name) => this.getNodeParameter(name, i, {});
|
|
651
|
+
if (operation === 'extractPages' || operation === 'deletePages') {
|
|
652
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
653
|
+
}
|
|
654
|
+
else if (operation === 'rotate') {
|
|
655
|
+
add('degrees', this.getNodeParameter('degrees', i));
|
|
656
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
657
|
+
}
|
|
658
|
+
else if (operation === 'split') {
|
|
659
|
+
const mode = this.getNodeParameter('splitMode', i);
|
|
660
|
+
add(mode, this.getNodeParameter(mode, i));
|
|
661
|
+
}
|
|
662
|
+
else if (operation === 'watermark') {
|
|
663
|
+
add('text', this.getNodeParameter('text', i));
|
|
664
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
665
|
+
for (const [k, v] of Object.entries(collection('watermarkOptions')))
|
|
666
|
+
add(k, v);
|
|
667
|
+
}
|
|
668
|
+
else if (operation === 'pageNumbers') {
|
|
669
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
670
|
+
for (const [k, v] of Object.entries(collection('pageNumberOptions')))
|
|
671
|
+
add(k, v);
|
|
672
|
+
}
|
|
673
|
+
else if (operation === 'protect') {
|
|
674
|
+
add('user_password', this.getNodeParameter('userPassword', i));
|
|
675
|
+
add('owner_password', this.getNodeParameter('ownerPassword', i));
|
|
676
|
+
const { permissions } = collection('protectOptions');
|
|
677
|
+
if (Array.isArray(permissions))
|
|
678
|
+
formData.append('permissions', permissions.join(','));
|
|
679
|
+
}
|
|
680
|
+
else if (operation === 'setMetadata') {
|
|
681
|
+
for (const [k, v] of Object.entries(collection('metadataFields'))) {
|
|
682
|
+
formData.append(k, String(v !== null && v !== void 0 ? v : ''));
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
if (spec.output === 'pdf') {
|
|
686
|
+
options = {
|
|
687
|
+
method: 'POST',
|
|
688
|
+
url: `${BASE_URL}/api/${spec.path}`,
|
|
689
|
+
body: formData,
|
|
690
|
+
encoding: 'arraybuffer',
|
|
691
|
+
};
|
|
692
|
+
binaryOut = {
|
|
693
|
+
fileName: this.getNodeParameter('fileName', i) || spec.defaultFile,
|
|
694
|
+
property: this.getNodeParameter('outputBinaryPropertyName', i),
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
else {
|
|
698
|
+
options = {
|
|
699
|
+
method: 'POST',
|
|
700
|
+
url: `${BASE_URL}/api/${spec.path}`,
|
|
701
|
+
body: formData,
|
|
702
|
+
json: true,
|
|
703
|
+
};
|
|
704
|
+
if (spec.output === 'parts') {
|
|
705
|
+
splitOut = true;
|
|
706
|
+
binaryOut = {
|
|
707
|
+
fileName: (this.getNodeParameter('fileName', i) || spec.defaultFile).replace(/\.pdf$/i, ''),
|
|
708
|
+
property: this.getNodeParameter('outputBinaryPropertyName', i),
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
282
713
|
else if (operation === 'usage') {
|
|
283
714
|
options = { method: 'GET', url: `${BASE_URL}/api/usage`, json: true };
|
|
284
715
|
}
|
|
@@ -296,12 +727,46 @@ class Pdfops {
|
|
|
296
727
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
|
|
297
728
|
}
|
|
298
729
|
try {
|
|
730
|
+
if (binaryOut && !splitOut)
|
|
731
|
+
options.returnFullResponse = true;
|
|
299
732
|
const response = await request(options);
|
|
300
|
-
if (binaryOut) {
|
|
733
|
+
if (splitOut && binaryOut) {
|
|
734
|
+
const parts = response.parts;
|
|
735
|
+
if (!Array.isArray(parts)) {
|
|
736
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unexpected split response: no parts', {
|
|
737
|
+
itemIndex: i,
|
|
738
|
+
});
|
|
739
|
+
}
|
|
740
|
+
for (let n = 0; n < parts.length; n++) {
|
|
741
|
+
const name = `${binaryOut.fileName}-${n + 1}.pdf`;
|
|
742
|
+
returnData.push({
|
|
743
|
+
json: { pages: parts[n].pages, page_count: parts[n].page_count, part: n + 1 },
|
|
744
|
+
binary: {
|
|
745
|
+
[binaryOut.property]: await this.helpers.prepareBinaryData(Buffer.from(parts[n].pdf, 'base64'), name, 'application/pdf'),
|
|
746
|
+
},
|
|
747
|
+
pairedItem: { item: i },
|
|
748
|
+
});
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
else if (binaryOut) {
|
|
752
|
+
const full = response;
|
|
753
|
+
const json = { fileName: binaryOut.fileName };
|
|
754
|
+
const fieldMap = (_d = full.headers) === null || _d === void 0 ? void 0 : _d['x-pdfops-field-map'];
|
|
755
|
+
if (fieldMap) {
|
|
756
|
+
try {
|
|
757
|
+
json.field_map = JSON.parse(fieldMap);
|
|
758
|
+
}
|
|
759
|
+
catch {
|
|
760
|
+
json.field_map = fieldMap;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
const note = (_e = full.headers) === null || _e === void 0 ? void 0 : _e['x-pdfops-note'];
|
|
764
|
+
if (note)
|
|
765
|
+
json.note = note;
|
|
301
766
|
returnData.push({
|
|
302
|
-
json
|
|
767
|
+
json,
|
|
303
768
|
binary: {
|
|
304
|
-
[binaryOut.property]: await this.helpers.prepareBinaryData(
|
|
769
|
+
[binaryOut.property]: await this.helpers.prepareBinaryData(full.body, binaryOut.fileName, 'application/pdf'),
|
|
305
770
|
},
|
|
306
771
|
pairedItem: { item: i },
|
|
307
772
|
});
|
|
@@ -315,7 +780,7 @@ class Pdfops {
|
|
|
315
780
|
if (this.continueOnFail()) {
|
|
316
781
|
returnData.push({
|
|
317
782
|
json: {
|
|
318
|
-
error: (
|
|
783
|
+
error: (_f = apiError === null || apiError === void 0 ? void 0 : apiError.message) !== null && _f !== void 0 ? _f : error.message,
|
|
319
784
|
...((apiError === null || apiError === void 0 ? void 0 : apiError.details) ? { message: apiError.details } : {}),
|
|
320
785
|
},
|
|
321
786
|
pairedItem: { item: i },
|