Skip to content

Commit 78e7b0d

Browse files
authored
Merge pull request #28 from MyvTsv/ticket37471
fix(export): images missing in exported Knowledge Base PDF
2 parents d7daa0d + d78db98 commit 78e7b0d

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [UNRELEASE]
99

10+
- Fix missing images in exported Knowledge Base PDFs
11+
1012
## [4.0.1] - 2025-03-10
1113

1214
### Added

inc/knowbaseitem.class.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,23 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, KnowbaseItem $item)
7777
'UTF-8',
7878
)));
7979

80-
$answer
81-
= Toolbox::stripTags(Glpi\Toolbox\Sanitizer::unsanitize(html_entity_decode(
82-
$item->getField('answer'),
83-
ENT_QUOTES,
84-
'UTF-8',
85-
)));
80+
$answer = Glpi\Toolbox\Sanitizer::unsanitize(Html::entity_decode_deep($item->getField('answer')));
81+
$answer = preg_replace('#data:image/[^;]+;base64,#', '@', $answer);
82+
83+
preg_match_all('/<img [^>]*src=[\'"]([^\'"]*docid=([0-9]*))[^>]*>/', $answer, $res, PREG_SET_ORDER);
84+
85+
foreach ($res as $img) {
86+
$docimg = new Document();
87+
$docimg->getFromDB((int) $img[2]);
88+
$width = null;
89+
90+
if (preg_match('/\bwidth=["\']?(\d+)/i', $img[0], $match_width)) {
91+
$width = $match_width[1];
92+
}
93+
94+
$path = '<img src="file://' . GLPI_DOC_DIR . '/' . $docimg->fields['filepath'] . '" width="' . $width . '"/>';
95+
$answer = str_replace($img[0], $path, $answer);
96+
}
8697

8798
$pdf->setColumnsSize(100);
8899

0 commit comments

Comments
 (0)