From a63ac45dd9877c673cae4706e744aee4ccf32ec3 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 2 Oct 2025 14:22:24 +0200 Subject: [PATCH 1/5] fix(pdf) Prevent nl2br from interfering with HTML table structure --- inc/simplepdf.class.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 5c06d71..f568370 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -346,10 +346,30 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100) $this->setColumnsSize(100); $text = $name . ' ' . $content; $content = Glpi\RichText\RichText::getEnhancedHtml($text); - if (!preg_match("//", $content) && !preg_match('/

/', $content)) { - $content = nl2br($content); + + // Split content by tables, keeping tables in the result + $segments = preg_split('/(]*>.*?<\/table>)/s', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + + // Process segments and rebuild content + $formatted_content = ''; + foreach ($segments as $segment) { + if (strpos($segment, '/", $segment) && !preg_match('/

/', $segment)) { + $segment = nl2br($segment); + } + $formatted_content .= $segment; + } } - $this->displayInternal(240, 0.5, self::LEFT, $minline * 5, [$content]); + + $this->displayInternal(240, 0.5, self::LEFT, $minline * 5, [$formatted_content]); + /* Restore */ list( $this->cols, From ca012ff662d86e7cc5193ff779cfe0005bdd0133 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Thu, 2 Oct 2025 15:36:54 +0200 Subject: [PATCH 2/5] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9004616..21210f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [UNRELEASE] +### Fixed + +- Fixed table formatting and border in PDF + ## [4.0.2] - 2025-09-30 - Fix missing images in exported Knowledge Base PDFs From 79ef5b087414cb2bedc2ca38cfb468cb803b4732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Langlois=20Ga=C3=ABtan?= <64356364+MyvTsv@users.noreply.github.com> Date: Fri, 3 Oct 2025 09:56:08 +0200 Subject: [PATCH 3/5] Update inc/simplepdf.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/simplepdf.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index f568370..73f5d3c 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -348,7 +348,7 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100) $content = Glpi\RichText\RichText::getEnhancedHtml($text); // Split content by tables, keeping tables in the result - $segments = preg_split('/(]*>.*?<\/table>)/s', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $segments = preg_split('/(]*>.*?<\/table>)/is', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); // Process segments and rebuild content $formatted_content = ''; From 995f445297e62cfd1ff71b0c9307c3f9326e876a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Langlois=20Ga=C3=ABtan?= <64356364+MyvTsv@users.noreply.github.com> Date: Fri, 3 Oct 2025 09:56:16 +0200 Subject: [PATCH 4/5] Update inc/simplepdf.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/simplepdf.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 73f5d3c..83daeab 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -353,7 +353,7 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100) // Process segments and rebuild content $formatted_content = ''; foreach ($segments as $segment) { - if (strpos($segment, ' Date: Fri, 3 Oct 2025 09:56:24 +0200 Subject: [PATCH 5/5] Update inc/simplepdf.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/simplepdf.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 83daeab..556437b 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -361,7 +361,7 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100) $formatted_content .= $segment; } else { // Apply nl2br only to text segments - if (!preg_match("//", $segment) && !preg_match('/

/', $segment)) { + if (!str_contains($segment, '')) { $segment = nl2br($segment); } $formatted_content .= $segment;