n8n-nodes-pdfbro 0.1.14 → 0.1.16
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 +20 -22
- package/package.json +1 -1
|
@@ -311,36 +311,34 @@ class PdfBro {
|
|
|
311
311
|
// Lazy load Invoice dependencies
|
|
312
312
|
const { JSDOM } = require('jsdom');
|
|
313
313
|
const htmlToPdfmake = require('html-to-pdfmake');
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
314
|
+
const PdfPrinter = require('pdfmake');
|
|
315
|
+
// Define fonts for pdfmake (using built-in Roboto fonts)
|
|
316
|
+
const fonts = {
|
|
317
|
+
Roboto: {
|
|
318
|
+
normal: Buffer.from(require('pdfmake/build/vfs_fonts')['Roboto-Regular.ttf'], 'base64'),
|
|
319
|
+
bold: Buffer.from(require('pdfmake/build/vfs_fonts')['Roboto-Medium.ttf'], 'base64'),
|
|
320
|
+
italics: Buffer.from(require('pdfmake/build/vfs_fonts')['Roboto-Italic.ttf'], 'base64'),
|
|
321
|
+
bolditalics: Buffer.from(require('pdfmake/build/vfs_fonts')['Roboto-MediumItalic.ttf'], 'base64'),
|
|
321
322
|
}
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
}
|
|
332
|
-
}
|
|
323
|
+
};
|
|
324
|
+
const printer = new PdfPrinter(fonts);
|
|
333
325
|
// convert html to pdfmake format (requires window)
|
|
334
326
|
const { window } = new JSDOM('');
|
|
335
327
|
const docDefContent = htmlToPdfmake(htmlContent, { window });
|
|
336
328
|
const docDefinition = {
|
|
337
329
|
content: docDefContent,
|
|
330
|
+
defaultStyle: {
|
|
331
|
+
font: 'Roboto'
|
|
332
|
+
}
|
|
338
333
|
};
|
|
339
|
-
const
|
|
334
|
+
const pdfDoc = printer.createPdfKitDocument(docDefinition);
|
|
335
|
+
// Collect PDF buffer using streams
|
|
336
|
+
const chunks = [];
|
|
340
337
|
const buffer = await new Promise((resolve, reject) => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
338
|
+
pdfDoc.on('data', (chunk) => chunks.push(chunk));
|
|
339
|
+
pdfDoc.on('end', () => resolve(Buffer.concat(chunks)));
|
|
340
|
+
pdfDoc.on('error', reject);
|
|
341
|
+
pdfDoc.end();
|
|
344
342
|
});
|
|
345
343
|
returnData.push({
|
|
346
344
|
json: { success: true },
|