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.
@@ -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 pdfMake = require('pdfmake/build/pdfmake');
315
- const pdfFonts = require('pdfmake/build/vfs_fonts');
316
- // Initialize fonts - handle different module structures
317
- if (!pdfMake.vfs) {
318
- // Try different possible structures of vfs_fonts module
319
- if (pdfFonts && pdfFonts.pdfMake && pdfFonts.pdfMake.vfs) {
320
- pdfMake.vfs = pdfFonts.pdfMake.vfs;
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
- 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
- }
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 pdfDocGenerator = pdfMake.createPdf(docDefinition);
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
- pdfDocGenerator.getBuffer((buffer) => {
342
- resolve(buffer);
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 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-pdfbro",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Offline PDF utility node for n8n",
5
5
  "keywords": [
6
6
  "n8n-community-node"