n8n-nodes-pdfbro 0.1.21 → 0.1.22
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 +17 -12
- package/package.json +1 -1
|
@@ -312,11 +312,11 @@ class PdfBro {
|
|
|
312
312
|
const htmlToPdfmake = require('html-to-pdfmake');
|
|
313
313
|
const PdfPrinter = require('pdfmake');
|
|
314
314
|
const juice = require('juice');
|
|
315
|
-
// Strip
|
|
316
|
-
//
|
|
315
|
+
// Strip font-family declarations from CSS (more careful regex)
|
|
316
|
+
// Matches: font-family: value; or font-family: value (end of style)
|
|
317
317
|
const htmlWithoutFonts = htmlContent
|
|
318
|
-
.replace(/font-family\s
|
|
319
|
-
.replace(
|
|
318
|
+
.replace(/font-family\s*:[^;}"']*;/gi, '') // font-family: ...; (with semicolon)
|
|
319
|
+
.replace(/;\s*font-family\s*:[^;}"']*/gi, ''); // ; font-family: ... (at end)
|
|
320
320
|
// Use juice to inline all CSS (from <style> tags and classes) into style attributes
|
|
321
321
|
const inlinedHtml = juice(htmlWithoutFonts, {
|
|
322
322
|
removeStyleTags: true,
|
|
@@ -336,31 +336,36 @@ class PdfBro {
|
|
|
336
336
|
// Convert inlined HTML to pdfmake format (requires window)
|
|
337
337
|
const { window } = new JSDOM('');
|
|
338
338
|
const docDefContent = htmlToPdfmake(inlinedHtml, { window });
|
|
339
|
-
// Recursively
|
|
340
|
-
const
|
|
339
|
+
// Recursively sanitize pdfmake content: remove fonts and fix NaN values
|
|
340
|
+
const sanitizeContent = (obj) => {
|
|
341
341
|
if (Array.isArray(obj)) {
|
|
342
|
-
return obj.map(
|
|
342
|
+
return obj.map(sanitizeContent);
|
|
343
343
|
}
|
|
344
344
|
if (obj && typeof obj === 'object') {
|
|
345
345
|
const result = {};
|
|
346
346
|
for (const key of Object.keys(obj)) {
|
|
347
347
|
if (key === 'font') {
|
|
348
|
-
// Skip font property
|
|
348
|
+
// Skip font property - defaultStyle handles it
|
|
349
349
|
continue;
|
|
350
350
|
}
|
|
351
|
-
|
|
351
|
+
const val = obj[key];
|
|
352
|
+
// Fix NaN numeric values (width, height, margin, etc.)
|
|
353
|
+
if (typeof val === 'number' && isNaN(val)) {
|
|
354
|
+
continue; // Skip NaN values
|
|
355
|
+
}
|
|
356
|
+
if (key === 'style' && typeof val === 'string') {
|
|
352
357
|
// Remove font-family from inline style strings
|
|
353
|
-
result[key] =
|
|
358
|
+
result[key] = val.replace(/font-family\s*:[^;]*;?/gi, '');
|
|
354
359
|
}
|
|
355
360
|
else {
|
|
356
|
-
result[key] =
|
|
361
|
+
result[key] = sanitizeContent(val);
|
|
357
362
|
}
|
|
358
363
|
}
|
|
359
364
|
return result;
|
|
360
365
|
}
|
|
361
366
|
return obj;
|
|
362
367
|
};
|
|
363
|
-
const sanitizedContent =
|
|
368
|
+
const sanitizedContent = sanitizeContent(docDefContent);
|
|
364
369
|
const docDefinition = {
|
|
365
370
|
content: sanitizedContent,
|
|
366
371
|
defaultStyle: {
|