n8n-nodes-pdfbro 0.1.13 → 0.1.15
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/dist/nodes/PdfBro/PdfBro.node.js +82 -25
- package/package.json +1 -1
|
@@ -198,34 +198,78 @@ class PdfBro {
|
|
|
198
198
|
}
|
|
199
199
|
return Array.from(pages).sort((a, b) => a - b);
|
|
200
200
|
};
|
|
201
|
-
|
|
201
|
+
// Handle merge operation separately - it needs all items at once
|
|
202
|
+
if (operation === 'merge') {
|
|
202
203
|
try {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
204
|
+
const mergedPdf = await PDFDocument.create();
|
|
205
|
+
// Get fixed collection from first item
|
|
206
|
+
// @ts-ignore
|
|
207
|
+
const binaries = ((_a = this.getNodeParameter('inputBinaries', 0)) === null || _a === void 0 ? void 0 : _a.files) || [];
|
|
208
|
+
// Collect all PDFs from all input items
|
|
209
|
+
let pdfCount = 0;
|
|
210
|
+
// First, try to get PDFs from the specified binary property names across ALL items
|
|
211
|
+
for (let i = 0; i < items.length; i++) {
|
|
212
|
+
const itemBinary = items[i].binary;
|
|
213
|
+
if (!itemBinary)
|
|
210
214
|
continue;
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
// If binaries array is specified, look for those specific properties
|
|
216
|
+
if (binaries.length > 0) {
|
|
217
|
+
for (const entry of binaries) {
|
|
218
|
+
const propName = entry.binaryPropertyName;
|
|
219
|
+
if (itemBinary[propName]) {
|
|
220
|
+
try {
|
|
221
|
+
const validBuffer = await this.helpers.getBinaryDataBuffer(i, propName);
|
|
222
|
+
const pdf = await PDFDocument.load(validBuffer);
|
|
223
|
+
const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
|
|
224
|
+
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
|
225
|
+
pdfCount++;
|
|
226
|
+
}
|
|
227
|
+
catch (e) {
|
|
228
|
+
// Skip invalid PDFs
|
|
229
|
+
}
|
|
230
|
+
}
|
|
218
231
|
}
|
|
219
232
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
233
|
+
else {
|
|
234
|
+
// If no specific binaries specified, try all binary properties in the item
|
|
235
|
+
for (const propName of Object.keys(itemBinary)) {
|
|
236
|
+
try {
|
|
237
|
+
const validBuffer = await this.helpers.getBinaryDataBuffer(i, propName);
|
|
238
|
+
const pdf = await PDFDocument.load(validBuffer);
|
|
239
|
+
const copiedPages = await mergedPdf.copyPages(pdf, pdf.getPageIndices());
|
|
240
|
+
copiedPages.forEach((page) => mergedPdf.addPage(page));
|
|
241
|
+
pdfCount++;
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
// Skip invalid PDFs
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (pdfCount === 0) {
|
|
250
|
+
throw new Error('No valid PDF files found in input items');
|
|
227
251
|
}
|
|
228
|
-
|
|
252
|
+
const mergedPdfBuffer = await mergedPdf.save();
|
|
253
|
+
returnData.push({
|
|
254
|
+
json: { success: true, pageCount: mergedPdf.getPageCount(), mergedFiles: pdfCount },
|
|
255
|
+
binary: {
|
|
256
|
+
data: await this.helpers.prepareBinaryData(Buffer.from(mergedPdfBuffer), 'merged.pdf', 'application/pdf'),
|
|
257
|
+
},
|
|
258
|
+
});
|
|
259
|
+
return [returnData];
|
|
260
|
+
}
|
|
261
|
+
catch (error) {
|
|
262
|
+
if (this.continueOnFail()) {
|
|
263
|
+
returnData.push({ json: { error: error.message } });
|
|
264
|
+
return [returnData];
|
|
265
|
+
}
|
|
266
|
+
throw error;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
// Handle other operations per-item
|
|
270
|
+
for (let i = 0; i < items.length; i++) {
|
|
271
|
+
try {
|
|
272
|
+
if (operation === 'split') {
|
|
229
273
|
const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i);
|
|
230
274
|
const rangeStr = this.getNodeParameter('splitRange', i);
|
|
231
275
|
const validBuffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName);
|
|
@@ -269,9 +313,22 @@ class PdfBro {
|
|
|
269
313
|
const htmlToPdfmake = require('html-to-pdfmake');
|
|
270
314
|
const pdfMake = require('pdfmake/build/pdfmake');
|
|
271
315
|
const pdfFonts = require('pdfmake/build/vfs_fonts');
|
|
272
|
-
// Initialize fonts
|
|
316
|
+
// Initialize fonts - handle different module structures
|
|
273
317
|
if (!pdfMake.vfs) {
|
|
274
|
-
|
|
318
|
+
// Try different possible structures of vfs_fonts module
|
|
319
|
+
if (pdfFonts && pdfFonts.pdfMake && pdfFonts.pdfMake.vfs) {
|
|
320
|
+
pdfMake.vfs = pdfFonts.pdfMake.vfs;
|
|
321
|
+
}
|
|
322
|
+
else if (pdfFonts && pdfFonts.vfs) {
|
|
323
|
+
pdfMake.vfs = pdfFonts.vfs;
|
|
324
|
+
}
|
|
325
|
+
else if (pdfFonts && typeof pdfFonts === 'object') {
|
|
326
|
+
// Some versions export vfs directly
|
|
327
|
+
pdfMake.vfs = pdfFonts;
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
throw new Error('Could not load PDF fonts. Please ensure pdfmake is properly installed.');
|
|
331
|
+
}
|
|
275
332
|
}
|
|
276
333
|
// convert html to pdfmake format (requires window)
|
|
277
334
|
const { window } = new JSDOM('');
|