From 08a4a97834ab395d569ef584682a177f2a584958 Mon Sep 17 00:00:00 2001 From: linusbrolin Date: Mon, 25 Sep 2023 21:12:39 +0200 Subject: [PATCH] properly find and replace "bold:" and "size*:" when calculating row height The previous method was errorprone, it could cause false positives and it also skipped replacing the number and colon after "size". --- index.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6344638..55d15bc 100644 --- a/index.js +++ b/index.js @@ -364,8 +364,17 @@ class PDFDocumentWithTables extends PDFDocument { cell.hasOwnProperty('options') && prepareRowOptions(cell); } - text = String(text).replace('bold:','').replace('size',''); - + // bold + if( String(text).indexOf('bold:') === 0 ){ + text = text.replace('bold:',''); + } + + // size + if( String(text).indexOf('size') === 0 ){ + let size = String(text).substr(4,2).replace(':','').replace('+','') >> 0; + text = text.replace(`size${size}:`,''); + } + // cell padding cellp = prepareCellPadding(table.headers[i].padding || options.padding || 0); // cellp = prepareCellPadding(options.padding || 0);