@custom-js/n8n-nodes-pdf-toolkit 1.49.0 → 1.51.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",
@@ -46,6 +47,14 @@ class CompressPDF {
46
47
  description: "The field name for binary PDF file or url that indicates PDF file. Please make sure the size of PDf file doesn't exceed 6mb. If it's bigger, pass URL rather than binary file.",
47
48
  required: true,
48
49
  },
50
+ {
51
+ displayName: "Output Filename",
52
+ name: "outputFilename",
53
+ type: "string",
54
+ default: "output.pdf",
55
+ description: "Name for the generated PDF file (include .pdf extension)",
56
+ required: false,
57
+ },
49
58
  ],
50
59
  };
51
60
  }
@@ -61,48 +70,71 @@ class CompressPDF {
61
70
  return Buffer.from(file.data, "base64");
62
71
  };
63
72
  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
73
+ try {
74
+ const credentials = await this.getCredentials("customJsApi");
75
+ const field_name = this.getNodeParameter("field_name", 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/compressPdf",
88
+ },
89
+ body: {
90
+ input: isBinary ? { file: file } : { urls: field_name },
91
+ code: `
92
+ const { PDF_COMPRESS } = require('./utils');
93
+ input = input.file || input.urls;
94
+ return PDF_COMPRESS(input);`,
95
+ returnBinary: "true",
96
+ },
97
+ encoding: null,
98
+ json: true,
99
+ };
100
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
101
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
102
+ // No binary data returned; emit only JSON without a binary property
103
+ returnData.push({
104
+ json: items[i].json,
105
+ pairedItem: {
106
+ item: i,
107
+ },
108
+ });
109
+ continue;
110
+ }
111
+ const outputFilename = this.getNodeParameter("outputFilename", i, "output.pdf");
112
+ const binaryData = await this.helpers.prepareBinaryData(response, outputFilename);
94
113
  returnData.push({
95
114
  json: items[i].json,
115
+ binary: {
116
+ data: binaryData,
117
+ },
118
+ pairedItem: {
119
+ item: i,
120
+ },
96
121
  });
97
- continue;
98
122
  }
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
- });
123
+ catch (error) {
124
+ const errorMessage = error instanceof Error ? error.message : String(error);
125
+ if (this.continueOnFail()) {
126
+ returnData.push({
127
+ json: {
128
+ error: errorMessage,
129
+ },
130
+ pairedItem: {
131
+ item: i,
132
+ },
133
+ });
134
+ continue;
135
+ }
136
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
137
+ }
106
138
  }
107
139
  return [returnData];
108
140
  }
@@ -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",
@@ -53,6 +54,14 @@ class ExtractPages {
53
54
  default: "1",
54
55
  description: "The range of pages to extract. Default is first page. (ex: 1-3, or 4)",
55
56
  },
57
+ {
58
+ displayName: "Output Filename",
59
+ name: "outputFilename",
60
+ type: "string",
61
+ default: "output.pdf",
62
+ description: "Name for the generated PDF file (include .pdf extension)",
63
+ required: false,
64
+ },
56
65
  ],
57
66
  };
58
67
  }
@@ -68,51 +77,74 @@ class ExtractPages {
68
77
  return Buffer.from(file.data, "base64");
69
78
  };
70
79
  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: `
80
+ try {
81
+ const credentials = await this.getCredentials("customJsApi");
82
+ const field_name = this.getNodeParameter("field_name", i);
83
+ const pageRange = this.getNodeParameter("pageRange", i);
84
+ const isBinary = this.getNodeParameter("resource", i) === "binary";
85
+ const file = isBinary ? getFile(field_name, i) : "";
86
+ if (!isBinary &&
87
+ !field_name.startsWith("http://") &&
88
+ !field_name.startsWith("https://")) {
89
+ throw new Error(`Invalid URL: ${field_name}`);
90
+ }
91
+ const options = {
92
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
93
+ method: 'POST',
94
+ headers: {
95
+ "customjs-origin": "n8n/extractPages",
96
+ },
97
+ body: {
98
+ input: isBinary
99
+ ? { file: file, pageRange }
100
+ : { urls: field_name, pageRange },
101
+ code: `
93
102
  const { EXTRACT_PAGES_FROM_PDF } = require('./utils');
94
103
  const pdfBuffer = input.file ? Buffer.from(input.file, 'base64') : input.urls;
95
104
  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
105
+ returnBinary: "true",
106
+ },
107
+ encoding: null,
108
+ json: true,
109
+ };
110
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
111
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
112
+ // No binary data returned; emit only JSON without a binary property
113
+ returnData.push({
114
+ json: items[i].json,
115
+ pairedItem: {
116
+ item: i,
117
+ },
118
+ });
119
+ continue;
120
+ }
121
+ const outputFilename = this.getNodeParameter("outputFilename", i, "output.pdf");
122
+ const binaryData = await this.helpers.prepareBinaryData(response, outputFilename);
104
123
  returnData.push({
105
124
  json: items[i].json,
125
+ binary: {
126
+ data: binaryData,
127
+ },
128
+ pairedItem: {
129
+ item: i,
130
+ },
106
131
  });
107
- continue;
108
132
  }
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
- });
133
+ catch (error) {
134
+ const errorMessage = error instanceof Error ? error.message : String(error);
135
+ if (this.continueOnFail()) {
136
+ returnData.push({
137
+ json: {
138
+ error: errorMessage,
139
+ },
140
+ pairedItem: {
141
+ item: i,
142
+ },
143
+ });
144
+ continue;
145
+ }
146
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
147
+ }
116
148
  }
117
149
  return [returnData];
118
150
  }
@@ -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 = {
@@ -33,6 +34,14 @@ class Html2Docx {
33
34
  description: "The HTML content to convert to Docx",
34
35
  required: true,
35
36
  },
37
+ {
38
+ displayName: "Output Filename",
39
+ name: "outputFilename",
40
+ type: "string",
41
+ default: "output.docx",
42
+ description: "Name for the generated DOCX file (include .docx extension)",
43
+ required: false,
44
+ },
36
45
  ],
37
46
  };
38
47
  }
@@ -40,38 +49,61 @@ class Html2Docx {
40
49
  const items = this.getInputData();
41
50
  const returnData = [];
42
51
  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
52
+ try {
53
+ const credentials = await this.getCredentials("customJsApi");
54
+ const htmlInput = this.getNodeParameter("htmlInput", i);
55
+ const options = {
56
+ url: `https://e.customjs.io/__js1-${credentials.apiKey}`,
57
+ method: 'POST',
58
+ headers: {
59
+ "customjs-origin": "n8n/html2Docx",
60
+ },
61
+ body: {
62
+ input: htmlInput,
63
+ code: "const { HTML2DOCX } = require('./utils'); return HTML2DOCX(input)",
64
+ returnBinary: "true",
65
+ },
66
+ encoding: null,
67
+ json: true,
68
+ };
69
+ const response = await this.helpers.requestWithAuthentication.call(this, 'customJsApi', options);
70
+ if (!response || (Buffer.isBuffer(response) && response.length === 0)) {
71
+ // No binary data returned; emit only JSON without a binary property
72
+ returnData.push({
73
+ json: items[i].json,
74
+ pairedItem: {
75
+ item: i,
76
+ },
77
+ });
78
+ continue;
79
+ }
80
+ const outputFilename = this.getNodeParameter("outputFilename", i, "output.docx");
81
+ const binaryData = await this.helpers.prepareBinaryData(response, outputFilename);
63
82
  returnData.push({
64
83
  json: items[i].json,
84
+ binary: {
85
+ data: binaryData,
86
+ },
87
+ pairedItem: {
88
+ item: i,
89
+ },
65
90
  });
66
- continue;
67
91
  }
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
- });
92
+ catch (error) {
93
+ const errorMessage = error instanceof Error ? error.message : String(error);
94
+ if (this.continueOnFail()) {
95
+ returnData.push({
96
+ json: {
97
+ error: errorMessage,
98
+ },
99
+ pairedItem: {
100
+ item: i,
101
+ },
102
+ });
103
+ continue;
104
+ }
105
+ throw new n8n_workflow_1.NodeOperationError(this.getNode(), error, { itemIndex: i });
106
+ }
75
107
  }
76
108
  return [returnData];
77
109
  }