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 diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 5c06d71..556437b 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>)/is', $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); + + // Process segments and rebuild content + $formatted_content = ''; + foreach ($segments as $segment) { + if (str_contains($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,