n8n-nodes-pdfops 0.2.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +47 -28
- package/dist/nodes/Pdfops/Pdfops.node.js +489 -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 +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -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.1';
|
|
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,294 @@ 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
|
+
'fill',
|
|
189
|
+
'inspect',
|
|
190
|
+
'merge',
|
|
191
|
+
'extractPages',
|
|
192
|
+
'deletePages',
|
|
193
|
+
'rotate',
|
|
194
|
+
'split',
|
|
195
|
+
'watermark',
|
|
196
|
+
'pageNumbers',
|
|
197
|
+
'unlock',
|
|
198
|
+
'protect',
|
|
199
|
+
'metadata',
|
|
200
|
+
'setMetadata',
|
|
201
|
+
],
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
displayName: 'Pages',
|
|
207
|
+
name: 'pages',
|
|
208
|
+
type: 'string',
|
|
209
|
+
default: '',
|
|
210
|
+
required: true,
|
|
211
|
+
placeholder: 'e.g. 1-3,5,8-',
|
|
212
|
+
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.',
|
|
213
|
+
displayOptions: { show: { operation: ['extractPages'] } },
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
displayName: 'Pages to Delete',
|
|
217
|
+
name: 'pages',
|
|
218
|
+
type: 'string',
|
|
219
|
+
default: '',
|
|
220
|
+
required: true,
|
|
221
|
+
placeholder: 'e.g. 2,4-6,9-',
|
|
222
|
+
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.',
|
|
223
|
+
displayOptions: { show: { operation: ['deletePages'] } },
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
displayName: 'Pages',
|
|
227
|
+
name: 'pages',
|
|
228
|
+
type: 'string',
|
|
229
|
+
default: '',
|
|
230
|
+
placeholder: 'e.g. 1-3,5 (empty = all pages)',
|
|
231
|
+
description: '1-based page spec such as "1-3,5". Leave empty to apply to every page.',
|
|
232
|
+
displayOptions: { show: { operation: ['rotate', 'watermark', 'pageNumbers'] } },
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
displayName: 'Degrees',
|
|
236
|
+
name: 'degrees',
|
|
237
|
+
type: 'options',
|
|
238
|
+
options: [
|
|
239
|
+
{ name: '90 (Clockwise)', value: 90 },
|
|
240
|
+
{ name: '180', value: 180 },
|
|
241
|
+
{ name: '270 (Clockwise)', value: 270 },
|
|
242
|
+
{ name: '-90 (Counter-Clockwise)', value: -90 },
|
|
243
|
+
],
|
|
244
|
+
default: 90,
|
|
245
|
+
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.',
|
|
246
|
+
displayOptions: { show: { operation: ['rotate'] } },
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
displayName: 'Split By',
|
|
250
|
+
name: 'splitMode',
|
|
251
|
+
type: 'options',
|
|
252
|
+
options: [
|
|
253
|
+
{
|
|
254
|
+
name: 'Page Ranges',
|
|
255
|
+
value: 'ranges',
|
|
256
|
+
description: 'Each comma-separated group becomes one part, e.g. "1-2,3-5" gives two parts',
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
name: 'Chunk Size',
|
|
260
|
+
value: 'every',
|
|
261
|
+
description: 'Cut into parts of N pages each (the last part may be shorter)',
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
default: 'ranges',
|
|
265
|
+
displayOptions: { show: { operation: ['split'] } },
|
|
266
|
+
},
|
|
267
|
+
{
|
|
268
|
+
displayName: 'Ranges',
|
|
269
|
+
name: 'ranges',
|
|
270
|
+
type: 'string',
|
|
271
|
+
default: '',
|
|
272
|
+
required: true,
|
|
273
|
+
placeholder: 'e.g. 1-2,3-5',
|
|
274
|
+
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',
|
|
275
|
+
displayOptions: { show: { operation: ['split'], splitMode: ['ranges'] } },
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
displayName: 'Pages per Part',
|
|
279
|
+
name: 'every',
|
|
280
|
+
type: 'number',
|
|
281
|
+
typeOptions: { minValue: 1 },
|
|
282
|
+
default: 1,
|
|
283
|
+
required: true,
|
|
284
|
+
description: 'Number of pages in each part; for example 2 on a 5-page PDF gives parts 1-2, 3-4 and 5',
|
|
285
|
+
displayOptions: { show: { operation: ['split'], splitMode: ['every'] } },
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
displayName: 'Watermark Text',
|
|
289
|
+
name: 'text',
|
|
290
|
+
type: 'string',
|
|
291
|
+
default: 'DRAFT',
|
|
292
|
+
required: true,
|
|
293
|
+
description: 'Text to stamp on the pages, at most 200 characters. Latin (WinAnsi) characters only; other scripts are rejected.',
|
|
294
|
+
displayOptions: { show: { operation: ['watermark'] } },
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
displayName: 'Watermark Options',
|
|
298
|
+
name: 'watermarkOptions',
|
|
299
|
+
type: 'collection',
|
|
300
|
+
placeholder: 'Add Option',
|
|
301
|
+
default: {},
|
|
302
|
+
displayOptions: { show: { operation: ['watermark'] } },
|
|
303
|
+
options: [
|
|
304
|
+
{
|
|
305
|
+
displayName: 'Color',
|
|
306
|
+
name: 'color',
|
|
307
|
+
type: 'color',
|
|
308
|
+
default: '#808080',
|
|
309
|
+
description: 'Text colour as hex, #rgb or #rrggbb',
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
displayName: 'Opacity',
|
|
313
|
+
name: 'opacity',
|
|
314
|
+
type: 'number',
|
|
315
|
+
typeOptions: { minValue: 0.05, maxValue: 1, numberPrecision: 2 },
|
|
316
|
+
default: 0.15,
|
|
317
|
+
description: 'From 0.05 (faint) to 1 (solid)',
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
displayName: 'Position',
|
|
321
|
+
name: 'position',
|
|
322
|
+
type: 'options',
|
|
323
|
+
options: [
|
|
324
|
+
{ name: 'Bottom', value: 'bottom' },
|
|
325
|
+
{ name: 'Center', value: 'center' },
|
|
326
|
+
{ name: 'Top', value: 'top' },
|
|
327
|
+
],
|
|
328
|
+
default: 'center',
|
|
329
|
+
},
|
|
330
|
+
{
|
|
331
|
+
displayName: 'Rotation',
|
|
332
|
+
name: 'rotation',
|
|
333
|
+
type: 'number',
|
|
334
|
+
default: 45,
|
|
335
|
+
description: 'Degrees counter-clockwise as the viewer sees it; 0 is horizontal',
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
displayName: 'Size',
|
|
339
|
+
name: 'size',
|
|
340
|
+
type: 'number',
|
|
341
|
+
typeOptions: { minValue: 6, maxValue: 200 },
|
|
342
|
+
default: 48,
|
|
343
|
+
description: 'Font size in points (6-200)',
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
displayName: 'Page Number Options',
|
|
349
|
+
name: 'pageNumberOptions',
|
|
350
|
+
type: 'collection',
|
|
351
|
+
placeholder: 'Add Option',
|
|
352
|
+
default: {},
|
|
353
|
+
displayOptions: { show: { operation: ['pageNumbers'] } },
|
|
354
|
+
options: [
|
|
355
|
+
{
|
|
356
|
+
displayName: 'Format',
|
|
357
|
+
name: 'format',
|
|
358
|
+
type: 'string',
|
|
359
|
+
default: '{n} / {total}',
|
|
360
|
+
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.',
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
displayName: 'Margin',
|
|
364
|
+
name: 'margin',
|
|
365
|
+
type: 'number',
|
|
366
|
+
typeOptions: { minValue: 0, maxValue: 200 },
|
|
367
|
+
default: 24,
|
|
368
|
+
description: 'Distance from the page edge in points (0-200)',
|
|
369
|
+
},
|
|
370
|
+
{
|
|
371
|
+
displayName: 'Position',
|
|
372
|
+
name: 'position',
|
|
373
|
+
type: 'options',
|
|
374
|
+
options: [
|
|
375
|
+
{ name: 'Bottom Center', value: 'bottom-center' },
|
|
376
|
+
{ name: 'Bottom Left', value: 'bottom-left' },
|
|
377
|
+
{ name: 'Bottom Right', value: 'bottom-right' },
|
|
378
|
+
{ name: 'Top Center', value: 'top-center' },
|
|
379
|
+
{ name: 'Top Left', value: 'top-left' },
|
|
380
|
+
{ name: 'Top Right', value: 'top-right' },
|
|
381
|
+
],
|
|
382
|
+
default: 'bottom-center',
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
displayName: 'Size',
|
|
386
|
+
name: 'size',
|
|
387
|
+
type: 'number',
|
|
388
|
+
typeOptions: { minValue: 4, maxValue: 72 },
|
|
389
|
+
default: 10,
|
|
390
|
+
description: 'Font size in points (4-72)',
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
displayName: 'Start Number',
|
|
394
|
+
name: 'start',
|
|
395
|
+
type: 'number',
|
|
396
|
+
typeOptions: { minValue: 0, maxValue: 100000 },
|
|
397
|
+
default: 1,
|
|
398
|
+
description: 'Number shown on page 1 of the document. Page i shows start+i-1, even when Pages selects only some pages.',
|
|
399
|
+
},
|
|
400
|
+
],
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
displayName: 'Open Password',
|
|
404
|
+
name: 'userPassword',
|
|
405
|
+
type: 'string',
|
|
406
|
+
typeOptions: { password: true },
|
|
407
|
+
default: '',
|
|
408
|
+
description: 'Password required to open the output PDF (at most 128 characters). Set this and/or the Owner Password; at least one is required.',
|
|
409
|
+
displayOptions: { show: { operation: ['protect'] } },
|
|
410
|
+
},
|
|
411
|
+
{
|
|
412
|
+
displayName: 'Owner Password',
|
|
413
|
+
name: 'ownerPassword',
|
|
414
|
+
type: 'string',
|
|
415
|
+
typeOptions: { password: true },
|
|
416
|
+
default: '',
|
|
417
|
+
description: 'Password that lifts the permission restrictions (at most 128 characters). Restrictions only bind a viewer when an owner password is set.',
|
|
418
|
+
displayOptions: { show: { operation: ['protect'] } },
|
|
419
|
+
},
|
|
420
|
+
{
|
|
421
|
+
displayName: 'Protect Options',
|
|
422
|
+
name: 'protectOptions',
|
|
423
|
+
type: 'collection',
|
|
424
|
+
placeholder: 'Add Option',
|
|
425
|
+
default: {},
|
|
426
|
+
displayOptions: { show: { operation: ['protect'] } },
|
|
427
|
+
options: [
|
|
428
|
+
{
|
|
429
|
+
displayName: 'Allowed Permissions',
|
|
430
|
+
name: 'permissions',
|
|
431
|
+
type: 'multiOptions',
|
|
432
|
+
options: [
|
|
433
|
+
{ name: 'Annotate', value: 'annotate' },
|
|
434
|
+
{ name: 'Copy', value: 'copy' },
|
|
435
|
+
{ name: 'Fill Forms', value: 'fill-forms' },
|
|
436
|
+
{ name: 'Modify', value: 'modify' },
|
|
437
|
+
{ name: 'Print', value: 'print' },
|
|
438
|
+
],
|
|
439
|
+
default: ['print', 'copy', 'annotate', 'fill-forms'],
|
|
440
|
+
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.',
|
|
441
|
+
},
|
|
442
|
+
],
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
displayName: 'Metadata',
|
|
446
|
+
name: 'metadataFields',
|
|
447
|
+
type: 'collection',
|
|
448
|
+
placeholder: 'Add Field',
|
|
449
|
+
default: {},
|
|
450
|
+
description: 'At least one field is required; an empty value clears that field',
|
|
451
|
+
displayOptions: { show: { operation: ['setMetadata'] } },
|
|
452
|
+
options: [
|
|
453
|
+
{ displayName: 'Author', name: 'author', type: 'string', default: '' },
|
|
454
|
+
{ displayName: 'Creator', name: 'creator', type: 'string', default: '' },
|
|
455
|
+
{
|
|
456
|
+
displayName: 'Keywords',
|
|
457
|
+
name: 'keywords',
|
|
458
|
+
type: 'string',
|
|
459
|
+
default: '',
|
|
460
|
+
description: 'Comma-separated list',
|
|
461
|
+
},
|
|
462
|
+
{ displayName: 'Subject', name: 'subject', type: 'string', default: '' },
|
|
463
|
+
{ displayName: 'Title', name: 'title', type: 'string', default: '' },
|
|
464
|
+
],
|
|
465
|
+
},
|
|
106
466
|
{
|
|
107
467
|
displayName: 'Invoice',
|
|
108
468
|
name: 'invoice',
|
|
@@ -136,7 +496,7 @@ class Pdfops {
|
|
|
136
496
|
hint: 'The name of the output item’s binary field to write the resulting PDF to',
|
|
137
497
|
displayOptions: {
|
|
138
498
|
show: {
|
|
139
|
-
operation: ['fill', 'merge', 'invoice'],
|
|
499
|
+
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata'],
|
|
140
500
|
},
|
|
141
501
|
},
|
|
142
502
|
},
|
|
@@ -146,10 +506,10 @@ class Pdfops {
|
|
|
146
506
|
type: 'string',
|
|
147
507
|
default: '',
|
|
148
508
|
placeholder: 'e.g. filled.pdf',
|
|
149
|
-
description: 'File name for the output PDF. Defaults per operation.',
|
|
509
|
+
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
510
|
displayOptions: {
|
|
151
511
|
show: {
|
|
152
|
-
operation: ['fill', 'merge', 'invoice'],
|
|
512
|
+
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata'],
|
|
153
513
|
},
|
|
154
514
|
},
|
|
155
515
|
},
|
|
@@ -157,7 +517,7 @@ class Pdfops {
|
|
|
157
517
|
};
|
|
158
518
|
}
|
|
159
519
|
async execute() {
|
|
160
|
-
var _a, _b, _c, _d;
|
|
520
|
+
var _a, _b, _c, _d, _e, _f;
|
|
161
521
|
const items = this.getInputData();
|
|
162
522
|
const returnData = [];
|
|
163
523
|
const operation = this.getNodeParameter('operation', 0);
|
|
@@ -205,6 +565,9 @@ class Pdfops {
|
|
|
205
565
|
for (let i = 0; i < items.length; i++) {
|
|
206
566
|
formData.append('pdf', await pdfBlob(i, binaryPropertyName), `input-${i}.pdf`);
|
|
207
567
|
}
|
|
568
|
+
const mergePassword = this.getNodeParameter('password', 0);
|
|
569
|
+
if (mergePassword)
|
|
570
|
+
formData.append('password', mergePassword);
|
|
208
571
|
const response = (await request({
|
|
209
572
|
method: 'POST',
|
|
210
573
|
url: `${BASE_URL}/api/merge`,
|
|
@@ -242,10 +605,14 @@ class Pdfops {
|
|
|
242
605
|
for (let i = 0; i < items.length; i++) {
|
|
243
606
|
let options;
|
|
244
607
|
let binaryOut;
|
|
608
|
+
let splitOut = false;
|
|
245
609
|
try {
|
|
246
610
|
if (operation === 'inspect') {
|
|
247
611
|
const formData = new FormData();
|
|
248
612
|
formData.append('pdf', await pdfBlob(i, this.getNodeParameter('binaryPropertyName', i)), 'input.pdf');
|
|
613
|
+
const inspectPassword = this.getNodeParameter('password', i);
|
|
614
|
+
if (inspectPassword)
|
|
615
|
+
formData.append('password', inspectPassword);
|
|
249
616
|
options = { method: 'POST', url: `${BASE_URL}/api/inspect`, body: formData, json: true };
|
|
250
617
|
}
|
|
251
618
|
else if (operation === 'fill') {
|
|
@@ -255,6 +622,9 @@ class Pdfops {
|
|
|
255
622
|
if (this.getNodeParameter('flatten', i)) {
|
|
256
623
|
formData.append('flatten', 'true');
|
|
257
624
|
}
|
|
625
|
+
const fillPassword = this.getNodeParameter('password', i);
|
|
626
|
+
if (fillPassword)
|
|
627
|
+
formData.append('password', fillPassword);
|
|
258
628
|
options = {
|
|
259
629
|
method: 'POST',
|
|
260
630
|
url: `${BASE_URL}/api/fill-form`,
|
|
@@ -279,6 +649,79 @@ class Pdfops {
|
|
|
279
649
|
property: this.getNodeParameter('outputBinaryPropertyName', i),
|
|
280
650
|
};
|
|
281
651
|
}
|
|
652
|
+
else if (DOC_OPS[operation]) {
|
|
653
|
+
const spec = DOC_OPS[operation];
|
|
654
|
+
const formData = new FormData();
|
|
655
|
+
formData.append('pdf', await pdfBlob(i, this.getNodeParameter('binaryPropertyName', i)), 'input.pdf');
|
|
656
|
+
const add = (name, value) => {
|
|
657
|
+
if (value !== undefined && value !== null && value !== '') {
|
|
658
|
+
formData.append(name, String(value));
|
|
659
|
+
}
|
|
660
|
+
};
|
|
661
|
+
add('password', this.getNodeParameter('password', i));
|
|
662
|
+
const collection = (name) => this.getNodeParameter(name, i, {});
|
|
663
|
+
if (operation === 'extractPages' || operation === 'deletePages') {
|
|
664
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
665
|
+
}
|
|
666
|
+
else if (operation === 'rotate') {
|
|
667
|
+
add('degrees', this.getNodeParameter('degrees', i));
|
|
668
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
669
|
+
}
|
|
670
|
+
else if (operation === 'split') {
|
|
671
|
+
const mode = this.getNodeParameter('splitMode', i);
|
|
672
|
+
add(mode, this.getNodeParameter(mode, i));
|
|
673
|
+
}
|
|
674
|
+
else if (operation === 'watermark') {
|
|
675
|
+
add('text', this.getNodeParameter('text', i));
|
|
676
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
677
|
+
for (const [k, v] of Object.entries(collection('watermarkOptions')))
|
|
678
|
+
add(k, v);
|
|
679
|
+
}
|
|
680
|
+
else if (operation === 'pageNumbers') {
|
|
681
|
+
add('pages', this.getNodeParameter('pages', i));
|
|
682
|
+
for (const [k, v] of Object.entries(collection('pageNumberOptions')))
|
|
683
|
+
add(k, v);
|
|
684
|
+
}
|
|
685
|
+
else if (operation === 'protect') {
|
|
686
|
+
add('user_password', this.getNodeParameter('userPassword', i));
|
|
687
|
+
add('owner_password', this.getNodeParameter('ownerPassword', i));
|
|
688
|
+
const { permissions } = collection('protectOptions');
|
|
689
|
+
if (Array.isArray(permissions))
|
|
690
|
+
formData.append('permissions', permissions.join(','));
|
|
691
|
+
}
|
|
692
|
+
else if (operation === 'setMetadata') {
|
|
693
|
+
for (const [k, v] of Object.entries(collection('metadataFields'))) {
|
|
694
|
+
formData.append(k, String(v !== null && v !== void 0 ? v : ''));
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
if (spec.output === 'pdf') {
|
|
698
|
+
options = {
|
|
699
|
+
method: 'POST',
|
|
700
|
+
url: `${BASE_URL}/api/${spec.path}`,
|
|
701
|
+
body: formData,
|
|
702
|
+
encoding: 'arraybuffer',
|
|
703
|
+
};
|
|
704
|
+
binaryOut = {
|
|
705
|
+
fileName: this.getNodeParameter('fileName', i) || spec.defaultFile,
|
|
706
|
+
property: this.getNodeParameter('outputBinaryPropertyName', i),
|
|
707
|
+
};
|
|
708
|
+
}
|
|
709
|
+
else {
|
|
710
|
+
options = {
|
|
711
|
+
method: 'POST',
|
|
712
|
+
url: `${BASE_URL}/api/${spec.path}`,
|
|
713
|
+
body: formData,
|
|
714
|
+
json: true,
|
|
715
|
+
};
|
|
716
|
+
if (spec.output === 'parts') {
|
|
717
|
+
splitOut = true;
|
|
718
|
+
binaryOut = {
|
|
719
|
+
fileName: (this.getNodeParameter('fileName', i) || spec.defaultFile).replace(/\.pdf$/i, ''),
|
|
720
|
+
property: this.getNodeParameter('outputBinaryPropertyName', i),
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
282
725
|
else if (operation === 'usage') {
|
|
283
726
|
options = { method: 'GET', url: `${BASE_URL}/api/usage`, json: true };
|
|
284
727
|
}
|
|
@@ -296,12 +739,46 @@ class Pdfops {
|
|
|
296
739
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
|
|
297
740
|
}
|
|
298
741
|
try {
|
|
742
|
+
if (binaryOut && !splitOut)
|
|
743
|
+
options.returnFullResponse = true;
|
|
299
744
|
const response = await request(options);
|
|
300
|
-
if (binaryOut) {
|
|
745
|
+
if (splitOut && binaryOut) {
|
|
746
|
+
const parts = response.parts;
|
|
747
|
+
if (!Array.isArray(parts)) {
|
|
748
|
+
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Unexpected split response: no parts', {
|
|
749
|
+
itemIndex: i,
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
for (let n = 0; n < parts.length; n++) {
|
|
753
|
+
const name = `${binaryOut.fileName}-${n + 1}.pdf`;
|
|
754
|
+
returnData.push({
|
|
755
|
+
json: { pages: parts[n].pages, page_count: parts[n].page_count, part: n + 1 },
|
|
756
|
+
binary: {
|
|
757
|
+
[binaryOut.property]: await this.helpers.prepareBinaryData(Buffer.from(parts[n].pdf, 'base64'), name, 'application/pdf'),
|
|
758
|
+
},
|
|
759
|
+
pairedItem: { item: i },
|
|
760
|
+
});
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
else if (binaryOut) {
|
|
764
|
+
const full = response;
|
|
765
|
+
const json = { fileName: binaryOut.fileName };
|
|
766
|
+
const fieldMap = (_d = full.headers) === null || _d === void 0 ? void 0 : _d['x-pdfops-field-map'];
|
|
767
|
+
if (fieldMap) {
|
|
768
|
+
try {
|
|
769
|
+
json.field_map = JSON.parse(fieldMap);
|
|
770
|
+
}
|
|
771
|
+
catch {
|
|
772
|
+
json.field_map = fieldMap;
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
const note = (_e = full.headers) === null || _e === void 0 ? void 0 : _e['x-pdfops-note'];
|
|
776
|
+
if (note)
|
|
777
|
+
json.note = note;
|
|
301
778
|
returnData.push({
|
|
302
|
-
json
|
|
779
|
+
json,
|
|
303
780
|
binary: {
|
|
304
|
-
[binaryOut.property]: await this.helpers.prepareBinaryData(
|
|
781
|
+
[binaryOut.property]: await this.helpers.prepareBinaryData(full.body, binaryOut.fileName, 'application/pdf'),
|
|
305
782
|
},
|
|
306
783
|
pairedItem: { item: i },
|
|
307
784
|
});
|
|
@@ -315,7 +792,7 @@ class Pdfops {
|
|
|
315
792
|
if (this.continueOnFail()) {
|
|
316
793
|
returnData.push({
|
|
317
794
|
json: {
|
|
318
|
-
error: (
|
|
795
|
+
error: (_f = apiError === null || apiError === void 0 ? void 0 : apiError.message) !== null && _f !== void 0 ? _f : error.message,
|
|
319
796
|
...((apiError === null || apiError === void 0 ? void 0 : apiError.details) ? { message: apiError.details } : {}),
|
|
320
797
|
},
|
|
321
798
|
pairedItem: { item: i },
|