n8n-nodes-pdfbro 0.1.3 → 0.1.5

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.
@@ -56,14 +56,71 @@ class PdfBro {
56
56
  ],
57
57
  default: 'merge',
58
58
  },
59
+ /*
60
+ displayName: 'Input Binary Field',
61
+ name: 'binaryPropertyName',
62
+ type: 'string',
63
+ default: 'data',
64
+ required: true,
65
+ description: 'The name of the binary field containing the PDF',
66
+ */
67
+ // Replaced with fixedCollection for merge, simple string for others
68
+ {
69
+ displayName: 'Input Binary Fields',
70
+ name: 'binaryProperties',
71
+ type: 'fixedCollection',
72
+ typeOptions: {
73
+ multipleValues: true,
74
+ },
75
+ displayOptions: {
76
+ show: {
77
+ operation: ['merge'],
78
+ },
79
+ },
80
+ default: {},
81
+ options: [
82
+ {
83
+ name: 'properties',
84
+ displayName: 'Binary Property',
85
+ values: [
86
+ {
87
+ displayName: 'Property Name',
88
+ name: 'property',
89
+ type: 'string',
90
+ default: 'data',
91
+ description: 'Name of the binary property to merge',
92
+ },
93
+ ],
94
+ },
95
+ ],
96
+ description: 'List of binary properties to merge (in order)',
97
+ },
59
98
  {
60
99
  displayName: 'Input Binary Field',
61
100
  name: 'binaryPropertyName',
62
101
  type: 'string',
63
102
  default: 'data',
64
103
  required: true,
104
+ displayOptions: {
105
+ hide: {
106
+ operation: ['merge'],
107
+ },
108
+ },
65
109
  description: 'The name of the binary field containing the PDF',
66
110
  },
111
+ {
112
+ displayName: 'Output Binary Field',
113
+ name: 'outputPropertyName',
114
+ type: 'string',
115
+ default: 'merged',
116
+ required: true,
117
+ displayOptions: {
118
+ show: {
119
+ operation: ['merge'],
120
+ },
121
+ },
122
+ description: 'The name of the binary field to put the merged PDF in',
123
+ },
67
124
  {
68
125
  displayName: 'Rotation Degrees',
69
126
  name: 'rotationDegrees',
@@ -83,17 +140,26 @@ class PdfBro {
83
140
  const items = this.getInputData();
84
141
  const returnData = [];
85
142
  const operation = this.getNodeParameter('operation', 0);
86
- const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
87
143
  if (operation === 'merge') {
88
- // Merge all inputs into one PDF
144
+ // Merge multiple binary properties FROM ALL ITEMS into ONE SINGLE PDF
145
+ const outputPropertyName = this.getNodeParameter('outputPropertyName', 0);
89
146
  const mergedPdf = await pdf_lib_1.PDFDocument.create();
90
147
  for (let i = 0; i < items.length; i++) {
91
148
  try {
92
- const binaryData = this.helpers.assertBinaryData(i, binaryPropertyName);
93
- const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
94
- const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
95
- const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
96
- copiedPages.forEach((page) => mergedPdf.addPage(page));
149
+ const binaryProps = this.getNodeParameter('binaryProperties', i);
150
+ if (binaryProps && binaryProps.properties) {
151
+ for (const propItem of binaryProps.properties) {
152
+ const propName = propItem.property;
153
+ // Check if binary data exists
154
+ if (!items[i].binary || !items[i].binary[propName]) {
155
+ continue;
156
+ }
157
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, propName);
158
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
159
+ const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
160
+ copiedPages.forEach((page) => mergedPdf.addPage(page));
161
+ }
162
+ }
97
163
  }
98
164
  catch (error) {
99
165
  if (this.continueOnFail()) {
@@ -102,87 +168,96 @@ class PdfBro {
102
168
  throw error;
103
169
  }
104
170
  }
171
+ // Return single item
105
172
  const mergedPdfBuffer = await mergedPdf.save();
173
+ // Use the first item's JSON as a base, or empty if no items
174
+ const jsonOutput = items.length > 0 ? items[0].json : {};
175
+ const binaryOutput = items.length > 0 && items[0].binary ? items[0].binary : {};
106
176
  returnData.push({
107
- json: { success: true, pageCount: mergedPdf.getPageCount() },
177
+ json: { ...jsonOutput, success: true, pageCount: mergedPdf.getPageCount() },
108
178
  binary: {
109
- [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(mergedPdfBuffer), 'merged.pdf', 'application/pdf'),
179
+ ...binaryOutput,
180
+ [outputPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(mergedPdfBuffer), 'merged.pdf', 'application/pdf'),
110
181
  },
111
182
  });
112
183
  }
113
- else if (operation === 'split') {
114
- // Split each input PDF into single pages
115
- for (let i = 0; i < items.length; i++) {
116
- const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
117
- const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
118
- const numberOfPages = pdf.getPageCount();
119
- for (let j = 0; j < numberOfPages; j++) {
120
- const newPdf = await pdf_lib_1.PDFDocument.create();
121
- const [copiedPage] = await newPdf.copyPages(pdf, [j]);
122
- newPdf.addPage(copiedPage);
123
- const newPdfBuffer = await newPdf.save();
184
+ else {
185
+ // For other operations, get the single binaryPropertyName
186
+ const binaryPropertyName = this.getNodeParameter('binaryPropertyName', 0);
187
+ if (operation === 'split') {
188
+ // Split each input PDF into single pages
189
+ for (let i = 0; i < items.length; i++) {
190
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
191
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
192
+ const numberOfPages = pdf.getPageCount();
193
+ for (let j = 0; j < numberOfPages; j++) {
194
+ const newPdf = await pdf_lib_1.PDFDocument.create();
195
+ const [copiedPage] = await newPdf.copyPages(pdf, [j]);
196
+ newPdf.addPage(copiedPage);
197
+ const newPdfBuffer = await newPdf.save();
198
+ returnData.push({
199
+ json: { ...items[i].json, pageNumber: j + 1, totalPages: numberOfPages },
200
+ binary: {
201
+ [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(newPdfBuffer), `page_${j + 1}.pdf`, 'application/pdf'),
202
+ },
203
+ });
204
+ }
205
+ }
206
+ }
207
+ else if (operation === 'rotate') {
208
+ const degreesVal = this.getNodeParameter('rotationDegrees', 0);
209
+ for (let i = 0; i < items.length; i++) {
210
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
211
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
212
+ const pages = pdf.getPages();
213
+ pages.forEach(page => {
214
+ const currentRotation = page.getRotation().angle;
215
+ page.setRotation((0, pdf_lib_1.degrees)(currentRotation + degreesVal));
216
+ });
217
+ const rotatedPdfBuffer = await pdf.save();
124
218
  returnData.push({
125
- json: { ...items[i].json, pageNumber: j + 1, totalPages: numberOfPages },
219
+ json: items[i].json,
126
220
  binary: {
127
- [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(newPdfBuffer), `page_${j + 1}.pdf`, 'application/pdf'),
221
+ [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(rotatedPdfBuffer), 'rotated.pdf', 'application/pdf'),
128
222
  },
129
223
  });
130
224
  }
131
225
  }
132
- }
133
- else if (operation === 'rotate') {
134
- const degreesVal = this.getNodeParameter('rotationDegrees', 0);
135
- for (let i = 0; i < items.length; i++) {
136
- const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
137
- const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
138
- const pages = pdf.getPages();
139
- pages.forEach(page => {
140
- const currentRotation = page.getRotation().angle;
141
- page.setRotation((0, pdf_lib_1.degrees)(currentRotation + degreesVal));
142
- });
143
- const rotatedPdfBuffer = await pdf.save();
144
- returnData.push({
145
- json: items[i].json,
146
- binary: {
147
- [binaryPropertyName]: await this.helpers.prepareBinaryData(Buffer.from(rotatedPdfBuffer), 'rotated.pdf', 'application/pdf'),
148
- },
149
- });
150
- }
151
- }
152
- else if (operation === 'extractText') {
153
- for (let i = 0; i < items.length; i++) {
154
- const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
155
- const data = await (0, pdf_parse_1.default)(validBuffer);
156
- returnData.push({
157
- json: {
158
- ...items[i].json,
159
- text: data.text,
160
- numpages: data.numpages,
161
- info: data.info,
162
- },
163
- binary: items[i].binary,
164
- });
226
+ else if (operation === 'extractText') {
227
+ for (let i = 0; i < items.length; i++) {
228
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
229
+ const data = await (0, pdf_parse_1.default)(validBuffer);
230
+ returnData.push({
231
+ json: {
232
+ ...items[i].json,
233
+ text: data.text,
234
+ numpages: data.numpages,
235
+ info: data.info,
236
+ },
237
+ binary: items[i].binary,
238
+ });
239
+ }
165
240
  }
166
- }
167
- else if (operation === 'metadata') {
168
- for (let i = 0; i < items.length; i++) {
169
- const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
170
- const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
171
- returnData.push({
172
- json: {
173
- ...items[i].json,
174
- title: pdf.getTitle(),
175
- author: pdf.getAuthor(),
176
- subject: pdf.getSubject(),
177
- creator: pdf.getCreator(),
178
- producer: pdf.getProducer(),
179
- keywords: pdf.getKeywords(),
180
- pageCount: pdf.getPageCount(),
181
- creationDate: pdf.getCreationDate(),
182
- modificationDate: pdf.getModificationDate(),
183
- },
184
- binary: items[i].binary,
185
- });
241
+ else if (operation === 'metadata') {
242
+ for (let i = 0; i < items.length; i++) {
243
+ const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
244
+ const pdf = await pdf_lib_1.PDFDocument.load(validBuffer);
245
+ returnData.push({
246
+ json: {
247
+ ...items[i].json,
248
+ title: pdf.getTitle(),
249
+ author: pdf.getAuthor(),
250
+ subject: pdf.getSubject(),
251
+ creator: pdf.getCreator(),
252
+ producer: pdf.getProducer(),
253
+ keywords: pdf.getKeywords(),
254
+ pageCount: pdf.getPageCount(),
255
+ creationDate: pdf.getCreationDate(),
256
+ modificationDate: pdf.getModificationDate(),
257
+ },
258
+ binary: items[i].binary,
259
+ });
260
+ }
186
261
  }
187
262
  }
188
263
  return [returnData];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-pdfbro",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Offline PDF utility node for n8n",
5
5
  "keywords": [
6
6
  "n8n-community-node"