diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4850b94..403b0e8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
+- Fix images display in PDF: Make them display at their original position instead of at the end of the document.
- Fix image rendering in Change/Problem descriptions and Problem task PDF exports
## [4.1.3] - 2026-06-24
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..ef1bed5
--- /dev/null
+++ b/Makefile
@@ -0,0 +1 @@
+include ../../PluginsMakefile.mk
diff --git a/inc/knowbaseitem.class.php b/inc/knowbaseitem.class.php
index d32fe46..e01d23d 100644
--- a/inc/knowbaseitem.class.php
+++ b/inc/knowbaseitem.class.php
@@ -107,7 +107,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item)
);
$pdf->displayLine(
$dbu->getUserName($item->fields['users_id']),
- Html::convDateTime($item->fields['date']),
+ Html::convDateTime($item->fields['date_creation']),
Html::convDateTime($item->fields['date_mod']),
Dropdown::getYesNo($item->fields['is_faq']),
$item->fields['view'],
diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php
index 6b9d322..3012fa9 100644
--- a/inc/simplepdf.class.php
+++ b/inc/simplepdf.class.php
@@ -152,6 +152,7 @@ public function render()
**/
public function output($name = false)
{
+ ob_clean();
if (!$name) {
return $this->pdf->Output('glpi.pdf', 'S');
}
@@ -351,21 +352,19 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100)
// Decode HTML entities BEFORE searching for images
$content = html_entity_decode($content, ENT_QUOTES, 'UTF-8');
- // Extract images and remove from HTML - TCPDF will render them separately
preg_match_all(
- '/
]*src=["\']([^"\']*docid=(\d+)[^"\']*)["\'][^>]*>/i',
+ '/]*>.*?(
]*src=["\']([^"\']*docid=(\d+)[^"\']*)["\'][^>]*>).*?<\/a>/is',
$content,
$matches,
PREG_SET_ORDER,
);
- $images_to_display = [];
if ($matches !== []) {
$document = new Document();
foreach ($matches as $match) {
- $full_img_tag = $match[0];
- $original_url = $match[1];
- $docid = (int) $match[2];
+ $full_a_tag = $match[0];
+ $full_img_tag = $match[1];
+ $docid = (int) $match[3];
if ($document->getFromDB($docid) && isset($document->fields['filepath'])) {
$file_path = GLPI_DOC_DIR . '/' . $document->fields['filepath'];
@@ -410,15 +409,9 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100)
$display_height = (int) ($display_height * $ratio);
}
- // Store image info for later insertion
- $images_to_display[] = [
- 'tag' => $full_img_tag,
- 'path' => $file_path,
- 'width' => $display_width,
- 'height' => $display_height,
- ];
- // Remove the img tag from HTML - we'll add images separately
- $content = str_replace($full_img_tag, '', $content);
+ // Replace the original image by a properly resized one + remove the a tag
+ $display_image_tag = '
';
+ $content = str_replace($full_a_tag, $display_image_tag, $content);
}
}
}
@@ -445,13 +438,6 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100)
$this->displayInternal(240, 0.5, self::LEFT, $minline * 5, [$formatted_content]);
- // Now add extracted images after the text with their original dimensions
- foreach ($images_to_display as $img_info) {
- if (file_exists($img_info['path'])) {
- $this->addPngFromFile($img_info['path'], $img_info['width'], $img_info['height']);
- }
- }
-
/* Restore */
[$this->cols, $this->colsx, $this->colsw, $this->align, ] = $save;
}
diff --git a/phpstan.neon b/phpstan.neon
index 3b12c3a..3f4ca49 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -2,6 +2,7 @@ parameters:
parallel:
maximumNumberOfProcesses: 2
level: 5
+ treatPhpDocTypesAsCertain: false
bootstrapFiles:
- ../../stubs/glpi_constants.php
- ../../vendor/autoload.php