From fbbf6234089ff1f656225a60ed178a2fe016e59a Mon Sep 17 00:00:00 2001 From: Alex Puiu Date: Thu, 17 Feb 2022 17:11:38 +0200 Subject: [PATCH] Keep images position in document --- app/Ingest/PDFConvertor.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/Ingest/PDFConvertor.php b/app/Ingest/PDFConvertor.php index 17a3725..c17d695 100644 --- a/app/Ingest/PDFConvertor.php +++ b/app/Ingest/PDFConvertor.php @@ -84,7 +84,6 @@ class PDFConvertor extends AbstractConvertor $hasText = false; $imagesCount = 0; - $imagesInFooter = true; $mdContents = ''; $htmlContents = ''; @@ -99,12 +98,14 @@ class PDFConvertor extends AbstractConvertor foreach ($items as $key => $p) { if ($p->getName() == 'image') { + $imageInFooter = false; $basePath = $this->storage->path(''); $imageFilePath = str_replace($basePath, '', $p['src']); $textContents = $this->applyOCR($imageFilePath); if ($textContents) { + $imageInFooter = true; if ($html) { $mdContents = $mdContents . $this->convertHtmlToMD($html) . "\n\n"; $htmlContents = $htmlContents . $html; @@ -126,7 +127,7 @@ class PDFConvertor extends AbstractConvertor $imageHTML = $this->handleImage($p, $caption); - if ( ! $imagesInFooter) { + if (!$imageInFooter) { $html = $html . $imageHTML; } else { $html = $html . "

$caption

"; @@ -155,8 +156,8 @@ class PDFConvertor extends AbstractConvertor $html = $html . '

' . $continuousP . '

'; } - if ($imagesInFooter) { - foreach ($footerImages as $index => $footerImage) { + if (!empty($footerImages) > 0) { + foreach ($footerImages as $footerImage) { $html = $html . '

' . $footerImage . '

'; } }