@custom-js/n8n-nodes-pdf-toolkit 1.49.0 → 1.50.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 CHANGED
@@ -23,6 +23,45 @@ Use the package at [here](https://www.npmjs.com/package/@custom-js/n8n-nodes-pdf
23
23
 
24
24
  Add your Api Key and store securely
25
25
 
26
+ ## Local Development with Docker
27
+
28
+ To test your local changes using Docker:
29
+
30
+ ### Prerequisites
31
+ - Docker and Docker Compose installed
32
+ - Node.js and npm installed
33
+
34
+ ### Setup Steps
35
+
36
+ 1. **Build the package:**
37
+ ```bash
38
+ npm run build
39
+ ```
40
+
41
+ 2. **Start n8n with Docker:**
42
+ ```bash
43
+ docker compose up -d
44
+ ```
45
+
46
+ ### Development Workflow
47
+
48
+ After making code changes:
49
+
50
+ ```bash
51
+ npm run build && docker restart n8n-dev
52
+ ```
53
+
54
+ To view logs:
55
+ ```bash
56
+ docker logs n8n-dev -f
57
+ ```
58
+
59
+ To stop the environment:
60
+ ```bash
61
+ docker compose down
62
+ ```
63
+
64
+
26
65
  ## Usage
27
66
 
28
67
  ### "HTML to PDF" node
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CompressPDF = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class CompressPDF {
5
6
  constructor() {
6
7
  this.description = {
@@ -13,8 +14,8 @@ class CompressPDF {
13
14
  defaults: {
14
15
  name: "Compress PDF file",
15
16
  },
16
- inputs: ["main"],
17
- outputs: ["main"],
17
+ inputs: ['main'],
18
+ outputs: ['main'],
18
19
  credentials: [
19
20
  {
20
21
  name: "customJsApi",
@@ -61,48 +62,70 @@ class CompressPDF {
61
62
  return Buffer.from(file.data, "base64");
62
63
  };
63
64
  for (let i = 0; i < items.length; i++) {
64
- const credentials = await this.getCredentials("customJsApi");
65
- const field_name = this.getNodeParameter("field_name", i);
66
- const isBinary = this.getNodeParameter("resource", i) === "binary";
67
- const file = isBinary ? getFile(field_name, i) : "";
68
- if (!isBinary &&
69
- !field_name.startsWith("http://") &&
70
- !field_name.startsWith("https://")) {
71
- throw new Error(`Invalid URL: ${field_name}`);
72
- }
73
- const options = {
74
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
75
- method: 'POST',
76
- headers: {
77
- "customjs-origin": "n8n/compressPdf",
78
- "x-api-key": credentials.apiKey,
79
- },
80
- body: {
81
- input: isBinary ? { file: file } : { urls: field_name },
82
- code: `
83
- const { PDF_COMPRESS } = require('./utils');
84
- input = input.file || input.urls;
85
- return PDF_COMPRESS(input);`,
86
- returnBinary: "true",
87
- },
88
- encoding: 'arraybuffer',
89
- json: true,
90
- };
91
- const response = await this.helpers.httpRequest(options);
92
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
93
- // No binary data returned; emit only JSON without a binary property
65
+ try {
66
+ const credentials = await this.getCredentials("customJsApi");
67
+ const field_name = this.getNodeParameter("field_name", i);
68
+ const isBinary = this.getNodeParameter("resource", i) === "binary";
69
+ const file = isBinary ? getFile(field_name, i) : "";
70
+ if (!isBinary &&
71
+ !field_name.startsWith("http://") &&
72
+ !field_name.startsWith("https://")) {
73
+ throw new Error(`Invalid URL: ${field_name}`);
74
+ }
75
+ const options = {
76
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
77
+ method: 'POST',
78
+ headers: {
79
+ "customjs-origin": "n8n/compressPdf",
80
+ },
81
+ body: {
82
+ input: isBinary ? { file: file } : { urls: field_name },
83
+ code: `
84
+ const { PDF_COMPRESS } = require('./utils');
85
+ input = input.file || input.urls;
86
+ return PDF_COMPRESS(input);`,
87
+ returnBinary: "true",
88
+ },
89
+ encoding: null,
90
+ json: true,
91
+ };
92
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
93
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
94
+ // No binary data returned; emit only JSON without a binary property
95
+ returnData.push({
96
+ json: items[i].json,
97
+ pairedItem: {
98
+ item: i,
99
+ },
100
+ });
101
+ continue;
102
+ }
103
+ const binaryData = await this.helpers.prepareBinaryData(response, "output.pdf");
94
104
  returnData.push({
95
105
  json: items[i].json,
106
+ binary: {
107
+ data: binaryData,
108
+ },
109
+ pairedItem: {
110
+ item: i,
111
+ },
96
112
  });
97
- continue;
98
113
  }
99
- const binaryData = await this.helpers.prepareBinaryData(response, "output.pdf");
100
- returnData.push({
101
- json: items[i].json,
102
- binary: {
103
- data: binaryData,
104
- },
105
- });
114
+ catch (error) {
115
+ const errorMessage = error instanceof Error ? error.message : String(error);
116
+ if (this.continueOnFail()) {
117
+ returnData.push({
118
+ json: {
119
+ error: errorMessage,
120
+ },
121
+ pairedItem: {
122
+ item: i,
123
+ },
124
+ });
125
+ continue;
126
+ }
127
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
128
+ }
106
129
  }
107
130
  return [returnData];
108
131
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExtractPages = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class ExtractPages {
5
6
  constructor() {
6
7
  this.description = {
@@ -13,8 +14,8 @@ class ExtractPages {
13
14
  defaults: {
14
15
  name: "Extract Pages From PDF",
15
16
  },
16
- inputs: ["main"],
17
- outputs: ["main"],
17
+ inputs: ['main'],
18
+ outputs: ['main'],
18
19
  credentials: [
19
20
  {
20
21
  name: "customJsApi",
@@ -68,51 +69,73 @@ class ExtractPages {
68
69
  return Buffer.from(file.data, "base64");
69
70
  };
70
71
  for (let i = 0; i < items.length; i++) {
71
- const credentials = await this.getCredentials("customJsApi");
72
- const field_name = this.getNodeParameter("field_name", i);
73
- const pageRange = this.getNodeParameter("pageRange", i);
74
- const isBinary = this.getNodeParameter("resource", i) === "binary";
75
- const file = isBinary ? getFile(field_name, i) : "";
76
- if (!isBinary &&
77
- !field_name.startsWith("http://") &&
78
- !field_name.startsWith("https://")) {
79
- throw new Error(`Invalid URL: ${field_name}`);
80
- }
81
- const options = {
82
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
83
- method: 'POST',
84
- headers: {
85
- "customjs-origin": "n8n/extractPages",
86
- "x-api-key": credentials.apiKey,
87
- },
88
- body: {
89
- input: isBinary
90
- ? { file: file, pageRange }
91
- : { urls: field_name, pageRange },
92
- code: `
72
+ try {
73
+ const credentials = await this.getCredentials("customJsApi");
74
+ const field_name = this.getNodeParameter("field_name", i);
75
+ const pageRange = this.getNodeParameter("pageRange", i);
76
+ const isBinary = this.getNodeParameter("resource", i) === "binary";
77
+ const file = isBinary ? getFile(field_name, i) : "";
78
+ if (!isBinary &&
79
+ !field_name.startsWith("http://") &&
80
+ !field_name.startsWith("https://")) {
81
+ throw new Error(`Invalid URL: ${field_name}`);
82
+ }
83
+ const options = {
84
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
85
+ method: 'POST',
86
+ headers: {
87
+ "customjs-origin": "n8n/extractPages",
88
+ },
89
+ body: {
90
+ input: isBinary
91
+ ? { file: file, pageRange }
92
+ : { urls: field_name, pageRange },
93
+ code: `
93
94
  const { EXTRACT_PAGES_FROM_PDF } = require('./utils');
94
95
  const pdfBuffer = input.file ? Buffer.from(input.file, 'base64') : input.urls;
95
96
  return EXTRACT_PAGES_FROM_PDF(pdfBuffer, input.pageRange);`,
96
- returnBinary: "true",
97
- },
98
- encoding: 'arraybuffer',
99
- json: true,
100
- };
101
- const response = await this.helpers.httpRequest(options);
102
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
103
- // No binary data returned; emit only JSON without a binary property
97
+ returnBinary: "true",
98
+ },
99
+ encoding: null,
100
+ json: true,
101
+ };
102
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
103
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
104
+ // No binary data returned; emit only JSON without a binary property
105
+ returnData.push({
106
+ json: items[i].json,
107
+ pairedItem: {
108
+ item: i,
109
+ },
110
+ });
111
+ continue;
112
+ }
113
+ const binaryData = await this.helpers.prepareBinaryData(response, "output.pdf");
104
114
  returnData.push({
105
115
  json: items[i].json,
116
+ binary: {
117
+ data: binaryData,
118
+ },
119
+ pairedItem: {
120
+ item: i,
121
+ },
106
122
  });
107
- continue;
108
123
  }
109
- const binaryData = await this.helpers.prepareBinaryData(response, "output.pdf");
110
- returnData.push({
111
- json: items[i].json,
112
- binary: {
113
- data: binaryData,
114
- },
115
- });
124
+ catch (error) {
125
+ const errorMessage = error instanceof Error ? error.message : String(error);
126
+ if (this.continueOnFail()) {
127
+ returnData.push({
128
+ json: {
129
+ error: errorMessage,
130
+ },
131
+ pairedItem: {
132
+ item: i,
133
+ },
134
+ });
135
+ continue;
136
+ }
137
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
138
+ }
116
139
  }
117
140
  return [returnData];
118
141
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.GetFormFieldNames = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class GetFormFieldNames {
5
6
  constructor() {
6
7
  this.description = {
@@ -13,8 +14,8 @@ class GetFormFieldNames {
13
14
  defaults: {
14
15
  name: "Get PDF Form Fields",
15
16
  },
16
- inputs: ["main"],
17
- outputs: ["main"],
17
+ inputs: ['main'],
18
+ outputs: ['main'],
18
19
  credentials: [
19
20
  {
20
21
  name: "customJsApi",
@@ -57,36 +58,55 @@ class GetFormFieldNames {
57
58
  return Buffer.from(file.data, "base64");
58
59
  };
59
60
  for (let i = 0; i < items.length; i++) {
60
- const credentials = await this.getCredentials("customJsApi");
61
- const field_name = this.getNodeParameter("field_name", i);
62
- const isBinary = this.getNodeParameter("resource", i) === "binary";
63
- const file = isBinary ? getFile(field_name, i) : "";
64
- if (!isBinary) {
65
- throw new Error(`Invalid binary data`);
66
- }
67
- const options = {
68
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
69
- method: 'POST',
70
- headers: {
71
- "customjs-origin": "n8n/getFormFieldNames",
72
- "x-api-key": credentials.apiKey,
73
- },
74
- body: {
75
- input: { file: file },
76
- code: `
61
+ try {
62
+ const credentials = await this.getCredentials("customJsApi");
63
+ const field_name = this.getNodeParameter("field_name", i);
64
+ const isBinary = this.getNodeParameter("resource", i) === "binary";
65
+ const file = isBinary ? getFile(field_name, i) : "";
66
+ if (!isBinary) {
67
+ throw new Error(`Invalid binary data`);
68
+ }
69
+ const options = {
70
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
71
+ method: 'POST',
72
+ headers: {
73
+ "customjs-origin": "n8n/getFormFieldNames",
74
+ },
75
+ body: {
76
+ input: { file: file },
77
+ code: `
77
78
  const { PDF_GET_FORM_FIELD_NAMES } = require('./utils');
78
79
  const pdfInput = input.file;
79
80
  return PDF_GET_FORM_FIELD_NAMES(pdfInput);`,
80
- returnBinary: "false",
81
- },
82
- json: true,
83
- };
84
- const response = await this.helpers.httpRequest(options);
85
- returnData.push({
86
- json: {
87
- output: JSON.parse(response.toString()),
88
- },
89
- });
81
+ returnBinary: "false",
82
+ },
83
+ json: true,
84
+ };
85
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
86
+ returnData.push({
87
+ json: {
88
+ output: JSON.parse(response.toString()),
89
+ },
90
+ pairedItem: {
91
+ item: i,
92
+ },
93
+ });
94
+ }
95
+ catch (error) {
96
+ const errorMessage = error instanceof Error ? error.message : String(error);
97
+ if (this.continueOnFail()) {
98
+ returnData.push({
99
+ json: {
100
+ error: errorMessage,
101
+ },
102
+ pairedItem: {
103
+ item: i,
104
+ },
105
+ });
106
+ continue;
107
+ }
108
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
109
+ }
90
110
  }
91
111
  return [returnData];
92
112
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Html2Docx = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class Html2Docx {
5
6
  constructor() {
6
7
  this.description = {
@@ -40,38 +41,60 @@ class Html2Docx {
40
41
  const items = this.getInputData();
41
42
  const returnData = [];
42
43
  for (let i = 0; i < items.length; i++) {
43
- const credentials = await this.getCredentials("customJsApi");
44
- const htmlInput = this.getNodeParameter("htmlInput", i);
45
- const options = {
46
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
47
- method: 'POST',
48
- headers: {
49
- "customjs-origin": "n8n/html2Docx",
50
- "x-api-key": credentials.apiKey,
51
- },
52
- body: {
53
- input: htmlInput,
54
- code: "const { HTML2DOCX } = require('./utils'); return HTML2DOCX(input)",
55
- returnBinary: "true",
56
- },
57
- encoding: 'arraybuffer',
58
- json: true,
59
- };
60
- const response = await this.helpers.httpRequest(options);
61
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
62
- // No binary data returned; emit only JSON without a binary property
44
+ try {
45
+ const credentials = await this.getCredentials("customJsApi");
46
+ const htmlInput = this.getNodeParameter("htmlInput", i);
47
+ const options = {
48
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
49
+ method: 'POST',
50
+ headers: {
51
+ "customjs-origin": "n8n/html2Docx",
52
+ },
53
+ body: {
54
+ input: htmlInput,
55
+ code: "const { HTML2DOCX } = require('./utils'); return HTML2DOCX(input)",
56
+ returnBinary: "true",
57
+ },
58
+ encoding: null,
59
+ json: true,
60
+ };
61
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
62
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
63
+ // No binary data returned; emit only JSON without a binary property
64
+ returnData.push({
65
+ json: items[i].json,
66
+ pairedItem: {
67
+ item: i,
68
+ },
69
+ });
70
+ continue;
71
+ }
72
+ const binaryData = await this.helpers.prepareBinaryData(response, "output.docx");
63
73
  returnData.push({
64
74
  json: items[i].json,
75
+ binary: {
76
+ data: binaryData,
77
+ },
78
+ pairedItem: {
79
+ item: i,
80
+ },
65
81
  });
66
- continue;
67
82
  }
68
- const binaryData = await this.helpers.prepareBinaryData(response, "output.docx");
69
- returnData.push({
70
- json: items[i].json,
71
- binary: {
72
- data: binaryData,
73
- },
74
- });
83
+ catch (error) {
84
+ const errorMessage = error instanceof Error ? error.message : String(error);
85
+ if (this.continueOnFail()) {
86
+ returnData.push({
87
+ json: {
88
+ error: errorMessage,
89
+ },
90
+ pairedItem: {
91
+ item: i,
92
+ },
93
+ });
94
+ continue;
95
+ }
96
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
97
+ }
75
98
  }
76
99
  return [returnData];
77
100
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Html2Pdf = void 0;
4
+ const n8n_workflow_1 = require("n8n-workflow");
4
5
  class Html2Pdf {
5
6
  constructor() {
6
7
  this.description = {
@@ -40,38 +41,60 @@ class Html2Pdf {
40
41
  const items = this.getInputData();
41
42
  const returnData = [];
42
43
  for (let i = 0; i < items.length; i++) {
43
- const credentials = await this.getCredentials("customJsApi");
44
- const htmlInput = this.getNodeParameter("htmlInput", i);
45
- const options = {
46
- url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
47
- method: 'POST',
48
- headers: {
49
- "customjs-origin": "n8n/generatePDF",
50
- "x-api-key": credentials.apiKey,
51
- },
52
- body: {
53
- input: htmlInput,
54
- code: "const { HTML2PDF } = require('./utils'); return HTML2PDF(input)",
55
- returnBinary: "true",
56
- },
57
- encoding: 'arraybuffer',
58
- json: true,
59
- };
60
- const response = await this.helpers.httpRequest(options);
61
- if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
62
- // No binary data returned; emit only JSON without a binary property
44
+ try {
45
+ const credentials = await this.getCredentials("customJsApi");
46
+ const htmlInput = this.getNodeParameter("htmlInput", i);
47
+ const options = {
48
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
49
+ method: 'POST',
50
+ headers: {
51
+ "customjs-origin": "n8n/generatePDF",
52
+ },
53
+ body: {
54
+ input: htmlInput,
55
+ code: "const { HTML2PDF } = require('./utils'); return HTML2PDF(input)",
56
+ returnBinary: "true",
57
+ },
58
+ encoding: null,
59
+ json: true,
60
+ };
61
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
62
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
63
+ // No binary data returned; emit only JSON without a binary property
64
+ returnData.push({
65
+ json: items[i].json,
66
+ pairedItem: {
67
+ item: i,
68
+ },
69
+ });
70
+ continue;
71
+ }
72
+ const binaryData = await this.helpers.prepareBinaryData(response, "output.pdf");
63
73
  returnData.push({
64
74
  json: items[i].json,
75
+ binary: {
76
+ data: binaryData,
77
+ },
78
+ pairedItem: {
79
+ item: i,
80
+ },
65
81
  });
66
- continue;
67
82
  }
68
- const binaryData = await this.helpers.prepareBinaryData(response, "output.pdf");
69
- returnData.push({
70
- json: items[i].json,
71
- binary: {
72
- data: binaryData,
73
- },
74
- });
83
+ catch (error) {
84
+ const errorMessage = error instanceof Error ? error.message : String(error);
85
+ if (this.continueOnFail()) {
86
+ returnData.push({
87
+ json: {
88
+ error: errorMessage,
89
+ },
90
+ pairedItem: {
91
+ item: i,
92
+ },
93
+ });
94
+ continue;
95
+ }
96
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
97
+ }
75
98
  }
76
99
  return [returnData];
77
100
  }