Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 23 additions & 3 deletions inc/simplepdf.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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("/<br\s?\/?>/", $content) && !preg_match('/<p>/', $content)) {
$content = nl2br($content);

// Split content by tables, keeping tables in the result
$segments = preg_split('/(<table\b[^>]*>.*?<\/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, '<table')) {
// Add border to tables if missing
if (!preg_match('/border\s*=\s*["\']?[1-9]/i', $segment)) {
$segment = preg_replace('/<table/i', '<table border="1"', $segment);
}
$formatted_content .= $segment;
} else {
// Apply nl2br only to text segments
if (!str_contains($segment, '<br') && !str_contains($segment, '<p>')) {
$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,
Expand Down