From aa2ac460c81643e96d45c54149bc9aea7412c638 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Tue, 28 Jul 2026 15:54:50 +0200 Subject: [PATCH 1/4] fix(45471): Images in exports were displaying at the end of the file + some errors in the logs --- inc/knowbaseitem.class.php | 2 +- inc/simplepdf.class.php | 32 ++++++++++---------------------- 2 files changed, 11 insertions(+), 23 deletions(-) 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..76edf39 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,11 @@ 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 + if(file_exists($file_path)){ + $display_image_tag = ''; + $content = str_replace($full_a_tag, $display_image_tag, $content); + } } } } @@ -445,13 +440,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; } From a10eb9bb65225d11de1fd15bd1f1225f76148dba Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Tue, 28 Jul 2026 15:56:27 +0200 Subject: [PATCH 2/4] feat(45471): add makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ef1bed5 --- /dev/null +++ b/Makefile @@ -0,0 +1 @@ +include ../../PluginsMakefile.mk From 29799a9a431f2949c6292ef7ed7979f5d2885389 Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Tue, 28 Jul 2026 16:12:11 +0200 Subject: [PATCH 3/4] fix(45471): phpstan errors --- inc/simplepdf.class.php | 6 ++---- phpstan.neon | 1 + 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/inc/simplepdf.class.php b/inc/simplepdf.class.php index 76edf39..3012fa9 100644 --- a/inc/simplepdf.class.php +++ b/inc/simplepdf.class.php @@ -410,10 +410,8 @@ public function displayText($name, $content = '', $minline = 3, $maxline = 100) } // Replace the original image by a properly resized one + remove the a tag - if(file_exists($file_path)){ - $display_image_tag = ''; - $content = str_replace($full_a_tag, $display_image_tag, $content); - } + $display_image_tag = ''; + $content = str_replace($full_a_tag, $display_image_tag, $content); } } } 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 From 94514db455121861e01dee111264fd7a57bd4b5d Mon Sep 17 00:00:00 2001 From: Julien Durand Date: Tue, 28 Jul 2026 16:16:30 +0200 Subject: [PATCH 4/4] chore(45471): Updated changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ad7b5ef..799063a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [unreleased] + +### Fixed + +- Fix images display in PDF: Make them display at their original position instead of at the end of the document. + ## [4.1.3] - 2026-06-24 ### Fixed