n8n-nodes-make-pdf 1.0.8 → 1.1.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.
|
@@ -7,7 +7,7 @@ class MakePdf {
|
|
|
7
7
|
this.description = {
|
|
8
8
|
displayName: 'Make PDF',
|
|
9
9
|
name: 'makePdf',
|
|
10
|
-
icon: '
|
|
10
|
+
icon: 'file:MakePdf.svg',
|
|
11
11
|
group: ['transform'],
|
|
12
12
|
version: 1,
|
|
13
13
|
description: 'Generate PDF via Gotenberg (HTML → PDF)',
|
|
@@ -44,6 +44,130 @@ class MakePdf {
|
|
|
44
44
|
description: 'The URL of your Gotenberg instance',
|
|
45
45
|
placeholder: 'http://gotenberg:3000/forms/chromium/convert/html',
|
|
46
46
|
},
|
|
47
|
+
{
|
|
48
|
+
displayName: 'Options',
|
|
49
|
+
name: 'options',
|
|
50
|
+
type: 'collection',
|
|
51
|
+
placeholder: 'Add Option',
|
|
52
|
+
default: {},
|
|
53
|
+
options: [
|
|
54
|
+
{
|
|
55
|
+
displayName: 'Paper Format',
|
|
56
|
+
name: 'paperFormat',
|
|
57
|
+
type: 'options',
|
|
58
|
+
options: [
|
|
59
|
+
{ name: 'A3', value: 'A3' },
|
|
60
|
+
{ name: 'A4', value: 'A4' },
|
|
61
|
+
{ name: 'A5', value: 'A5' },
|
|
62
|
+
{ name: 'A6', value: 'A6' },
|
|
63
|
+
{ name: 'Letter', value: 'Letter' },
|
|
64
|
+
{ name: 'Legal', value: 'Legal' },
|
|
65
|
+
{ name: 'Tabloid', value: 'Tabloid' },
|
|
66
|
+
],
|
|
67
|
+
default: 'A4',
|
|
68
|
+
description: 'The paper format for the PDF',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
displayName: 'Landscape',
|
|
72
|
+
name: 'landscape',
|
|
73
|
+
type: 'boolean',
|
|
74
|
+
default: false,
|
|
75
|
+
description: 'Whether to use landscape orientation',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
displayName: 'Print Background',
|
|
79
|
+
name: 'printBackground',
|
|
80
|
+
type: 'boolean',
|
|
81
|
+
default: true,
|
|
82
|
+
description: 'Whether to print background graphics',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
displayName: 'Scale',
|
|
86
|
+
name: 'scale',
|
|
87
|
+
type: 'number',
|
|
88
|
+
default: 1,
|
|
89
|
+
typeOptions: {
|
|
90
|
+
minValue: 0.1,
|
|
91
|
+
maxValue: 2,
|
|
92
|
+
numberStepSize: 0.1,
|
|
93
|
+
},
|
|
94
|
+
description: 'Scale of the webpage rendering (0.1 - 2)',
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
displayName: 'Margins',
|
|
98
|
+
name: 'margins',
|
|
99
|
+
type: 'fixedCollection',
|
|
100
|
+
placeholder: 'Add Margin',
|
|
101
|
+
default: {},
|
|
102
|
+
options: [
|
|
103
|
+
{
|
|
104
|
+
displayName: 'Margin Values',
|
|
105
|
+
name: 'marginValues',
|
|
106
|
+
values: [
|
|
107
|
+
{
|
|
108
|
+
displayName: 'Top',
|
|
109
|
+
name: 'top',
|
|
110
|
+
type: 'string',
|
|
111
|
+
default: '0',
|
|
112
|
+
description: 'Top margin (e.g., "1cm", "10mm", "0.5in")',
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
displayName: 'Bottom',
|
|
116
|
+
name: 'bottom',
|
|
117
|
+
type: 'string',
|
|
118
|
+
default: '0',
|
|
119
|
+
description: 'Bottom margin',
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
displayName: 'Left',
|
|
123
|
+
name: 'left',
|
|
124
|
+
type: 'string',
|
|
125
|
+
default: '0',
|
|
126
|
+
description: 'Left margin',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
displayName: 'Right',
|
|
130
|
+
name: 'right',
|
|
131
|
+
type: 'string',
|
|
132
|
+
default: '0',
|
|
133
|
+
description: 'Right margin',
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
displayName: 'Wait Delay',
|
|
141
|
+
name: 'waitDelay',
|
|
142
|
+
type: 'number',
|
|
143
|
+
default: 0,
|
|
144
|
+
typeOptions: {
|
|
145
|
+
minValue: 0,
|
|
146
|
+
maxValue: 30,
|
|
147
|
+
},
|
|
148
|
+
description: 'Wait delay in seconds before PDF generation (0-30)',
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
displayName: 'Timeout',
|
|
152
|
+
name: 'timeout',
|
|
153
|
+
type: 'number',
|
|
154
|
+
default: 30,
|
|
155
|
+
typeOptions: {
|
|
156
|
+
minValue: 1,
|
|
157
|
+
maxValue: 300,
|
|
158
|
+
},
|
|
159
|
+
description: 'Timeout in seconds for the HTTP request (1-300)',
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
displayName: 'Output Filename',
|
|
163
|
+
name: 'outputFilename',
|
|
164
|
+
type: 'string',
|
|
165
|
+
default: '',
|
|
166
|
+
description: 'Custom filename for the PDF (leave empty to use input filename)',
|
|
167
|
+
placeholder: 'document.pdf',
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
},
|
|
47
171
|
],
|
|
48
172
|
};
|
|
49
173
|
}
|
|
@@ -56,6 +180,7 @@ class MakePdf {
|
|
|
56
180
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', itemIndex);
|
|
57
181
|
const outputBinaryPropertyName = this.getNodeParameter('outputBinaryPropertyName', itemIndex);
|
|
58
182
|
const gotenbergUrl = this.getNodeParameter('gotenbergUrl', itemIndex);
|
|
183
|
+
const options = this.getNodeParameter('options', itemIndex, {});
|
|
59
184
|
const binaryData = (_a = items[itemIndex].binary) === null || _a === void 0 ? void 0 : _a[binaryPropertyName];
|
|
60
185
|
if (!binaryData) {
|
|
61
186
|
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `No binary data found in property "${binaryPropertyName}"`, { itemIndex });
|
|
@@ -65,22 +190,83 @@ class MakePdf {
|
|
|
65
190
|
}
|
|
66
191
|
// Convert base64 to Buffer
|
|
67
192
|
const htmlBuffer = Buffer.from(binaryData.data, 'base64');
|
|
193
|
+
// Prepare form data for Gotenberg
|
|
194
|
+
const FormData = require('form-data');
|
|
195
|
+
const formData = new FormData();
|
|
196
|
+
// Add HTML file
|
|
197
|
+
formData.append('files', htmlBuffer, {
|
|
198
|
+
filename: 'index.html',
|
|
199
|
+
contentType: 'text/html',
|
|
200
|
+
});
|
|
201
|
+
// Add Gotenberg options if specified
|
|
202
|
+
if (options.paperFormat) {
|
|
203
|
+
const paperSizes = {
|
|
204
|
+
'A3': { width: '11.7in', height: '16.5in' },
|
|
205
|
+
'A4': { width: '8.27in', height: '11.7in' },
|
|
206
|
+
'A5': { width: '5.83in', height: '8.27in' },
|
|
207
|
+
'A6': { width: '4.13in', height: '5.83in' },
|
|
208
|
+
'Letter': { width: '8.5in', height: '11in' },
|
|
209
|
+
'Legal': { width: '8.5in', height: '14in' },
|
|
210
|
+
'Tabloid': { width: '11in', height: '17in' },
|
|
211
|
+
};
|
|
212
|
+
const format = options.paperFormat;
|
|
213
|
+
if (paperSizes[format]) {
|
|
214
|
+
formData.append('paperWidth', paperSizes[format].width);
|
|
215
|
+
formData.append('paperHeight', paperSizes[format].height);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (options.landscape !== undefined) {
|
|
219
|
+
formData.append('landscape', options.landscape.toString());
|
|
220
|
+
}
|
|
221
|
+
if (options.printBackground !== undefined) {
|
|
222
|
+
formData.append('printBackground', options.printBackground.toString());
|
|
223
|
+
}
|
|
224
|
+
if (options.scale !== undefined) {
|
|
225
|
+
formData.append('scale', options.scale.toString());
|
|
226
|
+
}
|
|
227
|
+
// Add margins
|
|
228
|
+
if (options.margins && typeof options.margins === 'object') {
|
|
229
|
+
const margins = options.margins.marginValues;
|
|
230
|
+
if (margins) {
|
|
231
|
+
if (margins.top)
|
|
232
|
+
formData.append('marginTop', margins.top);
|
|
233
|
+
if (margins.bottom)
|
|
234
|
+
formData.append('marginBottom', margins.bottom);
|
|
235
|
+
if (margins.left)
|
|
236
|
+
formData.append('marginLeft', margins.left);
|
|
237
|
+
if (margins.right)
|
|
238
|
+
formData.append('marginRight', margins.right);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (options.waitDelay !== undefined && options.waitDelay !== 0) {
|
|
242
|
+
formData.append('waitDelay', `${options.waitDelay}s`);
|
|
243
|
+
}
|
|
68
244
|
// Make request to Gotenberg
|
|
245
|
+
const timeout = (options.timeout || 30) * 1000;
|
|
69
246
|
const response = await this.helpers.httpRequest({
|
|
70
247
|
method: 'POST',
|
|
71
248
|
url: gotenbergUrl,
|
|
72
|
-
body:
|
|
73
|
-
headers:
|
|
74
|
-
'Content-Type': 'text/html',
|
|
75
|
-
},
|
|
249
|
+
body: formData,
|
|
250
|
+
headers: formData.getHeaders(),
|
|
76
251
|
encoding: 'arraybuffer',
|
|
77
252
|
returnFullResponse: false,
|
|
253
|
+
timeout,
|
|
78
254
|
});
|
|
255
|
+
// Determine output filename
|
|
256
|
+
let outputFilename = options.outputFilename || '';
|
|
257
|
+
if (!outputFilename) {
|
|
258
|
+
outputFilename = binaryData.fileName
|
|
259
|
+
? binaryData.fileName.replace(/\.[^.]+$/, '.pdf')
|
|
260
|
+
: 'output.pdf';
|
|
261
|
+
}
|
|
262
|
+
if (!outputFilename.endsWith('.pdf')) {
|
|
263
|
+
outputFilename += '.pdf';
|
|
264
|
+
}
|
|
79
265
|
// Create new binary data for PDF
|
|
80
266
|
const newBinaryData = {
|
|
81
267
|
data: Buffer.from(response).toString('base64'),
|
|
82
268
|
mimeType: 'application/pdf',
|
|
83
|
-
fileName:
|
|
269
|
+
fileName: outputFilename,
|
|
84
270
|
};
|
|
85
271
|
// Prepare output item
|
|
86
272
|
const newItem = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "n8n-nodes-make-pdf",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "n8n node to generate PDFs via Gotenberg - Convert HTML to PDF with ease",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"n8n",
|
|
@@ -30,13 +30,14 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"scripts": {
|
|
33
|
-
"build": "tsc -p tsconfig.json && mkdir -p dist/nodes/MakePdf && cp src/nodes/MakePdf/
|
|
33
|
+
"build": "tsc -p tsconfig.json && mkdir -p dist/nodes/MakePdf && cp src/nodes/MakePdf/MakePdf.svg dist/nodes/MakePdf/MakePdf.svg",
|
|
34
34
|
"prepare": "npm run build",
|
|
35
35
|
"dev": "npm run build -- --watch",
|
|
36
36
|
"lint": "tsc --noEmit"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"n8n-workflow": "^1.0.0 || ^2.0.0"
|
|
39
|
+
"n8n-workflow": "^1.0.0 || ^2.0.0",
|
|
40
|
+
"form-data": "^4.0.0"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/node": "^25.0.3",
|
|
File without changes
|