n8n-nodes-pdfops 0.5.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.
- package/README.md +4 -2
- package/dist/nodes/Pdfops/Pdfops.node.js +265 -18
- package/dist/nodes/Pdfops/Pdfops.node.js.map +1 -1
- package/dist/nodes/Pdfops/Pdfops.node.json +3 -0
- package/dist/nodes/Pdfops/decodeApiError.d.ts +1 -0
- package/dist/nodes/Pdfops/decodeApiError.js +18 -0
- package/dist/nodes/Pdfops/decodeApiError.js.map +1 -1
- package/dist/package.json +2 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ from **Settings → Community Nodes → Install** → `n8n-nodes-pdfops`.
|
|
|
21
21
|
|
|
22
22
|
## Operations
|
|
23
23
|
|
|
24
|
-
Operations are grouped by resource: **Form** (Add Fields, Fill, Inspect Fields), **Document**
|
|
24
|
+
Operations are grouped by resource: **Form** (Add Fields, Detect Fields, Fill, Inspect Fields, Make Fillable), **Document**
|
|
25
25
|
(Delete Pages, Extract Pages, Merge, Rotate Pages, Split PDF), **Stamp** (Add Page Numbers, Add
|
|
26
26
|
Watermark, Edit), **Text** (Extract, Find), **Attachment** (Attach), **Convert** (HTML to PDF,
|
|
27
27
|
Images to PDF, Text to PDF), **Security** (Protect, Unlock), **Metadata** (Get, Set), **Invoice**
|
|
@@ -51,6 +51,8 @@ instead of a binary input.
|
|
|
51
51
|
| **Metadata → Set** | Sets title, author, subject, keywords or creator and outputs the updated PDF. | Metadata fields (at least one) |
|
|
52
52
|
| **Account → Get Usage** | Returns tier, quota, used, remaining and reset date for your API key (needs a credential). | - |
|
|
53
53
|
| **Form → Add Fields** | Creates fillable AcroForm fields (text, multiline, checkbox, radio group, dropdown, signature box) at exact positions. The signature type is an empty field for a signing tool; nothing is signed. | Fields to Add (JSON array: type, name, page, x, y, width, height, options...), Input PDF Password |
|
|
54
|
+
| **Form → Detect Fields** | Suggests text and checkbox fields for a flat PDF (no form fields yet) and returns them as JSON: `count`, `truncated`, `nextPages` and `fields` (type, name from the nearest printed label, page, x, y, width, height, label, confidence). Detects fields drawn as lines, boxes, underscores and checkboxes; review the result. The PDF is not changed. | Pages; options: Max Pages (default 40), Min Confidence (default 0.4), Input PDF Password |
|
|
55
|
+
| **Form → Make Fillable (Detect Fields)** | Detects the fields and adds them in one call: outputs the fillable PDF as binary data, and the item JSON carries `fields_count`, `field_names`, `truncated`, `next_pages`, `pages_skipped` and `warning` when they apply. Nothing found is the error `no_fields`. Long documents are handled for you: the node sends the result back with the pages not done (up to 25 calls per item), continues past `no_fields` while pages are left, and reports `pages_skipped` and the first `warning`. When the loop ends early you get a partial result (the PDF so far with `truncated` true, `next_pages`, `stopped_by` = `{code, message}` and a `message`; code is `stalled`, `max_rounds` or the API error code of the failed call) only if at least one field was added, so you can resume; otherwise the item fails with an error that carries the stop code and the pages left. Review the result. | Pages; options: Max Pages, Min Confidence; Input PDF Password, Output Binary Field, Output File Name |
|
|
54
56
|
| **Stamp → Edit** | Draws text, images (a logo, a signature picture), QR codes and barcodes at exact positions. x and y are PDF points from the bottom-left of the page as displayed. | Items (JSON array), Image Files (binary field plus the name Items refer to), Input PDF Password |
|
|
55
57
|
| **Text → Extract** | Reads the text layer of a born-digital PDF (no OCR; scanned pages are listed in `pagesWithoutText`). JSON with per-page text, positioned lines and tables; Plain Text returns `{ text, truncated }`; Tables As Excel Workbook returns an `.xlsx` as binary data with its own mime type (one sheet per table) and fails with `no_tables` when the pages hold none. | Result Format (JSON, Plain Text), Tables As (JSON Rows, CSV, Excel Workbook), Pages, Output Binary Field and Output File Name (workbook) |
|
|
56
58
|
| **Text → Find** | Searches the text layer for a word, phrase or regex and returns each hit with its page and box in the same coordinates Stamp → Edit uses. When `truncated` is true and `nextPage` is set, run again with Pages set to `<nextPage>-`. | Query; options: Case Sensitive, Max Hits (default 100), Regex, Whole Word; Pages |
|
|
@@ -63,7 +65,7 @@ Page specs are 1-based: comma-separated pages and ranges, `8-` meaning page 8
|
|
|
63
65
|
to the end. All operations that read a PDF accept an **Input PDF Password** for inputs that need one to open.
|
|
64
66
|
Output is deterministic (the same input gives a byte-identical PDF) for every PDF-producing
|
|
65
67
|
operation except Security → Protect (salted encryption) and Convert → HTML to PDF (rendered by a
|
|
66
|
-
browser, so two renders can differ in bytes). Extract Text
|
|
68
|
+
browser, so two renders can differ in bytes). Extract Text, Find Text and Detect Fields only read.
|
|
67
69
|
|
|
68
70
|
Errors carry the API's own message (for example which AcroForm field name was
|
|
69
71
|
wrong). With **Continue on Fail** a failing item becomes `{ error, message }`
|
|
@@ -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.6.0';
|
|
8
8
|
function headerTrue(value) {
|
|
9
9
|
return typeof value === 'string' && value.split(',')[0].trim().toLowerCase() === 'true';
|
|
10
10
|
}
|
|
@@ -34,6 +34,7 @@ const DOC_OPS = {
|
|
|
34
34
|
edit: { path: 'edit', output: 'pdf', defaultFile: 'edited.pdf' },
|
|
35
35
|
extractText: { path: 'extract-text', output: 'extract', defaultFile: 'tables.xlsx' },
|
|
36
36
|
findText: { path: 'find-text', output: 'json', defaultFile: '' },
|
|
37
|
+
detectFields: { path: 'detect-fields', output: 'json', defaultFile: '' },
|
|
37
38
|
};
|
|
38
39
|
const XLSX_MIME_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
39
40
|
const OPERATION_PROPERTIES = [
|
|
@@ -210,6 +211,12 @@ const OPERATION_PROPERTIES = [
|
|
|
210
211
|
action: 'Add form fields to a PDF',
|
|
211
212
|
description: 'Create fillable form fields (text, checkbox, radio group, dropdown, signature box) at exact positions in a PDF',
|
|
212
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
|
+
},
|
|
213
220
|
{
|
|
214
221
|
name: 'Fill',
|
|
215
222
|
value: 'fill',
|
|
@@ -222,6 +229,12 @@ const OPERATION_PROPERTIES = [
|
|
|
222
229
|
action: 'List the form fields of a PDF',
|
|
223
230
|
description: 'List a PDF’s AcroForm fields — names, types, options, current values — plus a paste-ready fill template',
|
|
224
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
|
+
},
|
|
225
238
|
],
|
|
226
239
|
default: 'fill',
|
|
227
240
|
},
|
|
@@ -370,7 +383,7 @@ class Pdfops {
|
|
|
370
383
|
hint: 'The name of the input item’s binary field containing the PDF',
|
|
371
384
|
displayOptions: {
|
|
372
385
|
show: {
|
|
373
|
-
operation: ['fill', 'inspect', 'merge', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'metadata', 'setMetadata', 'addFields', 'attach', 'edit', 'extractText', 'findText'],
|
|
386
|
+
operation: ['fill', 'inspect', 'merge', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'metadata', 'setMetadata', 'addFields', 'attach', 'edit', 'extractText', 'findText', 'detectFields', 'makeFillable'],
|
|
374
387
|
},
|
|
375
388
|
},
|
|
376
389
|
},
|
|
@@ -424,6 +437,8 @@ class Pdfops {
|
|
|
424
437
|
'edit',
|
|
425
438
|
'extractText',
|
|
426
439
|
'findText',
|
|
440
|
+
'detectFields',
|
|
441
|
+
'makeFillable',
|
|
427
442
|
],
|
|
428
443
|
},
|
|
429
444
|
},
|
|
@@ -457,6 +472,41 @@ class Pdfops {
|
|
|
457
472
|
description: '1-based page spec such as "1-3,5". Leave empty to apply to every page.',
|
|
458
473
|
displayOptions: { show: { operation: ['rotate', 'watermark', 'pageNumbers', 'extractText', 'findText'] } },
|
|
459
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
|
+
],
|
|
509
|
+
},
|
|
460
510
|
{
|
|
461
511
|
displayName: 'Degrees',
|
|
462
512
|
name: 'degrees',
|
|
@@ -1174,7 +1224,7 @@ class Pdfops {
|
|
|
1174
1224
|
hint: 'The name of the output item’s binary field to write the resulting PDF to',
|
|
1175
1225
|
displayOptions: {
|
|
1176
1226
|
show: {
|
|
1177
|
-
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata', 'addFields', 'attach', 'edit', 'htmlToPdf', 'imageToPdf', 'textToPdf'],
|
|
1227
|
+
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata', 'addFields', 'makeFillable', 'attach', 'edit', 'htmlToPdf', 'imageToPdf', 'textToPdf'],
|
|
1178
1228
|
},
|
|
1179
1229
|
},
|
|
1180
1230
|
},
|
|
@@ -1187,7 +1237,7 @@ class Pdfops {
|
|
|
1187
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',
|
|
1188
1238
|
displayOptions: {
|
|
1189
1239
|
show: {
|
|
1190
|
-
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata', 'addFields', 'attach', 'edit', 'htmlToPdf', 'imageToPdf', 'textToPdf'],
|
|
1240
|
+
operation: ['fill', 'merge', 'invoice', 'extractPages', 'deletePages', 'rotate', 'split', 'watermark', 'pageNumbers', 'unlock', 'protect', 'setMetadata', 'addFields', 'makeFillable', 'attach', 'edit', 'htmlToPdf', 'imageToPdf', 'textToPdf'],
|
|
1191
1241
|
},
|
|
1192
1242
|
},
|
|
1193
1243
|
},
|
|
@@ -1216,7 +1266,7 @@ class Pdfops {
|
|
|
1216
1266
|
};
|
|
1217
1267
|
}
|
|
1218
1268
|
async execute() {
|
|
1219
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s;
|
|
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;
|
|
1220
1270
|
const items = this.getInputData();
|
|
1221
1271
|
const returnData = [];
|
|
1222
1272
|
const operation = this.getNodeParameter('operation', 0);
|
|
@@ -1378,6 +1428,198 @@ class Pdfops {
|
|
|
1378
1428
|
if (operation === 'usage' && !hasCredential) {
|
|
1379
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)');
|
|
1380
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
|
+
}
|
|
1381
1623
|
for (let i = 0; i < items.length; i++) {
|
|
1382
1624
|
let options;
|
|
1383
1625
|
let binaryOut;
|
|
@@ -1510,8 +1752,8 @@ class Pdfops {
|
|
|
1510
1752
|
const images = this.getNodeParameter('imageFiles', i, {}).image;
|
|
1511
1753
|
const seenImageNames = new Set();
|
|
1512
1754
|
for (const image of images !== null && images !== void 0 ? images : []) {
|
|
1513
|
-
if (!/^[A-Za-z0-9_.-]{1,64}$/.test((
|
|
1514
|
-
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Image field name "${(
|
|
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 });
|
|
1515
1757
|
}
|
|
1516
1758
|
if (['pdf', 'password', 'items'].includes(image.fieldName)) {
|
|
1517
1759
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Image field name "${image.fieldName}" is reserved; use another name`, { itemIndex: i });
|
|
@@ -1556,6 +1798,11 @@ class Pdfops {
|
|
|
1556
1798
|
else if (operation === 'extractText') {
|
|
1557
1799
|
add('pages', this.getNodeParameter('pages', i));
|
|
1558
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
|
+
}
|
|
1559
1806
|
if (spec.output === 'extract') {
|
|
1560
1807
|
const format = this.getNodeParameter('textFormat', i);
|
|
1561
1808
|
const tablesFormat = format === 'json' ? this.getNodeParameter('tablesFormat', i) : 'json';
|
|
@@ -1665,7 +1912,7 @@ class Pdfops {
|
|
|
1665
1912
|
returnData.push({
|
|
1666
1913
|
json: {
|
|
1667
1914
|
text: full.body,
|
|
1668
|
-
truncated: headerTrue((
|
|
1915
|
+
truncated: headerTrue((_o = full.headers) === null || _o === void 0 ? void 0 : _o['x-pdfops-truncated']),
|
|
1669
1916
|
},
|
|
1670
1917
|
pairedItem: { item: i },
|
|
1671
1918
|
});
|
|
@@ -1673,7 +1920,7 @@ class Pdfops {
|
|
|
1673
1920
|
else if (binaryOut) {
|
|
1674
1921
|
const full = response;
|
|
1675
1922
|
const json = { fileName: binaryOut.fileName };
|
|
1676
|
-
const fieldMap = (
|
|
1923
|
+
const fieldMap = (_p = full.headers) === null || _p === void 0 ? void 0 : _p['x-pdfops-field-map'];
|
|
1677
1924
|
if (fieldMap) {
|
|
1678
1925
|
try {
|
|
1679
1926
|
json.field_map = JSON.parse(fieldMap);
|
|
@@ -1682,13 +1929,13 @@ class Pdfops {
|
|
|
1682
1929
|
json.field_map = fieldMap;
|
|
1683
1930
|
}
|
|
1684
1931
|
}
|
|
1685
|
-
const note = (
|
|
1932
|
+
const note = (_q = full.headers) === null || _q === void 0 ? void 0 : _q['x-pdfops-note'];
|
|
1686
1933
|
if (note)
|
|
1687
1934
|
json.note = note;
|
|
1688
1935
|
if (operation === 'attach') {
|
|
1689
1936
|
let keys = [];
|
|
1690
1937
|
try {
|
|
1691
|
-
const parsed = JSON.parse(String((
|
|
1938
|
+
const parsed = JSON.parse(String((_r = full.headers) === null || _r === void 0 ? void 0 : _r['x-pdfops-attachment-keys']));
|
|
1692
1939
|
if (Array.isArray(parsed)) {
|
|
1693
1940
|
keys = parsed
|
|
1694
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')
|
|
@@ -1701,14 +1948,14 @@ class Pdfops {
|
|
|
1701
1948
|
json.attachment_keys = keys;
|
|
1702
1949
|
}
|
|
1703
1950
|
if (operation === 'extractText') {
|
|
1704
|
-
if (headerTrue((
|
|
1951
|
+
if (headerTrue((_s = full.headers) === null || _s === void 0 ? void 0 : _s['x-pdfops-truncated'])) {
|
|
1705
1952
|
json.truncated = true;
|
|
1706
|
-
const truncatedBy = (
|
|
1953
|
+
const truncatedBy = (_t = full.headers) === null || _t === void 0 ? void 0 : _t['x-pdfops-truncated-by'];
|
|
1707
1954
|
if (typeof truncatedBy === 'string' && truncatedBy) {
|
|
1708
1955
|
json.truncated_by = truncatedBy.split(',');
|
|
1709
1956
|
}
|
|
1710
1957
|
}
|
|
1711
|
-
if (headerTrue((
|
|
1958
|
+
if (headerTrue((_u = full.headers) === null || _u === void 0 ? void 0 : _u['x-pdfops-cells-truncated']))
|
|
1712
1959
|
json.cells_truncated = true;
|
|
1713
1960
|
const body = Buffer.from(full.body);
|
|
1714
1961
|
if (body.length < 4 || body.readUInt32BE(0) !== 0x504b0304) {
|
|
@@ -1716,7 +1963,7 @@ class Pdfops {
|
|
|
1716
1963
|
}
|
|
1717
1964
|
}
|
|
1718
1965
|
if (operation === 'addFields') {
|
|
1719
|
-
const warning = (
|
|
1966
|
+
const warning = (_v = full.headers) === null || _v === void 0 ? void 0 : _v['x-pdfops-warning'];
|
|
1720
1967
|
if (typeof warning === 'string' && warning)
|
|
1721
1968
|
json.warning = warning;
|
|
1722
1969
|
}
|
|
@@ -1725,7 +1972,7 @@ class Pdfops {
|
|
|
1725
1972
|
['x-pdfops-pages', 'pages'],
|
|
1726
1973
|
['x-pdfops-blocked-requests', 'blocked_requests'],
|
|
1727
1974
|
]) {
|
|
1728
|
-
const value = (
|
|
1975
|
+
const value = (_w = full.headers) === null || _w === void 0 ? void 0 : _w[header];
|
|
1729
1976
|
if (typeof value === 'string' && /^\d+$/.test(value))
|
|
1730
1977
|
json[key] = Number(value);
|
|
1731
1978
|
}
|
|
@@ -1733,7 +1980,7 @@ class Pdfops {
|
|
|
1733
1980
|
returnData.push({
|
|
1734
1981
|
json,
|
|
1735
1982
|
binary: {
|
|
1736
|
-
[binaryOut.property]: await this.helpers.prepareBinaryData(full.body, binaryOut.fileName, (
|
|
1983
|
+
[binaryOut.property]: await this.helpers.prepareBinaryData(full.body, binaryOut.fileName, (_x = binaryOut.mimeType) !== null && _x !== void 0 ? _x : 'application/pdf'),
|
|
1737
1984
|
},
|
|
1738
1985
|
pairedItem: { item: i },
|
|
1739
1986
|
});
|
|
@@ -1747,7 +1994,7 @@ class Pdfops {
|
|
|
1747
1994
|
if (this.continueOnFail()) {
|
|
1748
1995
|
returnData.push({
|
|
1749
1996
|
json: {
|
|
1750
|
-
error: (
|
|
1997
|
+
error: (_y = apiError === null || apiError === void 0 ? void 0 : apiError.message) !== null && _y !== void 0 ? _y : error.message,
|
|
1751
1998
|
...((apiError === null || apiError === void 0 ? void 0 : apiError.details) ? { message: apiError.details } : {}),
|
|
1752
1999
|
},
|
|
1753
2000
|
pairedItem: { item: i },
|