From 01bcb8286af80a5f369d5a436870514da78bf351 Mon Sep 17 00:00:00 2001 From: Rom1-B <8530352+Rom1-B@users.noreply.github.com> Date: Thu, 28 May 2026 15:41:29 +0200 Subject: [PATCH] Fix: formatted text rendered as visible HTML tags in PDF exports --- CHANGELOG.md | 1 + inc/simplepdf.class.php | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5c01d9..342a43e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fixed PHP warnings flood when exporting Changes with linked items lacking serial/inventory fields - Fixed Change and Problem description exported as a single unstructured text block - Fixed Change analysis and plan fields rendering as raw HTML in PDF +- Fixed rich text content rendered as visible HTML tags and unformatted text in PDF exports ## [4.0.2] - 2025-09-30 diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 252d59f..f9fbc14 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -344,11 +344,12 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100) $save = [$this->cols, $this->colsx, $this->colsw, $this->align]; $this->setColumnsSize(100); - $text = $name . ' ' . $content; - $content = Glpi\RichText\RichText::getEnhancedHtml($text, ['text_maxsize' => 0]); + // Decode $content alone: mixing literal HTML from $name breaks isHtmlEncoded(), leaving GLPI entities (<) un-decoded and visible as text in TCPDF. + $decoded = Glpi\RichText\RichText::getEnhancedHtml($content ?? '', ['text_maxsize' => 0]); + $text = preg_replace('/]*>.*?<\/script>/is', '', $name . ' ' . $decoded); // Split content by tables, keeping tables in the result - $segments = preg_split('/(]*>.*?<\/table>)/is', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + $segments = preg_split('/(]*>.*?<\/table>)/is', $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); // Process segments and rebuild content $formatted_content = '';