From 06a4b6cd39085c690246bc26bea05c1635f585a4 Mon Sep 17 00:00:00 2001 From: Alex Puiu Date: Fri, 18 Feb 2022 16:51:20 +0200 Subject: [PATCH] Solve list items indentation --- app/Ingest/PDFConvertor.php | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/app/Ingest/PDFConvertor.php b/app/Ingest/PDFConvertor.php index c17d695..cc47221 100644 --- a/app/Ingest/PDFConvertor.php +++ b/app/Ingest/PDFConvertor.php @@ -95,7 +95,8 @@ class PDFConvertor extends AbstractConvertor foreach ($page as $items) { $continuousP = ''; - + $firstOfText = true; + foreach ($items as $key => $p) { if ($p->getName() == 'image') { $imageInFooter = false; @@ -141,14 +142,15 @@ class PDFConvertor extends AbstractConvertor if($p == '·') { continue; } - + $addition = null; if(isset($items[$key-1]) && $items[$key-1] == '·') { $addition = '· '; } - - $continuousP = $continuousP . $this->handleText($p, $fonts, $addition); - + + $continuousP = $continuousP . $this->handleText($p, $fonts, $addition, $firstOfText); + + $firstOfText = false; $hasText = true; } } @@ -198,10 +200,21 @@ class PDFConvertor extends AbstractConvertor return $html; } - protected function handleText($p, $fonts, $addition = null) + protected function handleText($p, $fonts, $addition = null, $firstOfText = false) { $id = (int) $p['font']; $font_size = $fonts[$id]['size']; + $font_color = $fonts[$id]['color']; + $font_family = $fonts[$id]['family']; + + $style = ''; + $style = $style . 'position: relative;'; + $style = $style . "color: $font_color;"; + $style = $style . "font-family: $font_family;"; + $style = $style . "height: " . $p['height'] . "px;"; + if($firstOfText) + $style = $style . "padding-left: " . (intval($p['left']) - 90) . "px;"; + // $style = $style . "font-size: $font_size" . "px;"; if ($p->i) { $content = '' . $p->i . ''; @@ -219,7 +232,7 @@ class PDFConvertor extends AbstractConvertor $tag = $this->getTag($font_size); - return '<' . $tag . '>' . $content . ''; + return '<' . $tag . ' style="' . $style . '">' . $content . ''; } protected function getTag($size)