Browse Source

Insert links and image style in downloaded document.

dev
Alex Puiu 2 years ago
parent
commit
43a50249cf
  1. 4
      app/Ingest/DocumentHandler.php
  2. 26
      app/Ingest/PDFConvertor.php

4
app/Ingest/DocumentHandler.php

@ -56,9 +56,9 @@ class DocumentHandler
$type = $this->supportedFiles[$this->mimeType];
$id = str_replace(' ', '_', $this->id);
// $id = str_replace(' ', '_', $this->id);
$path = $storage->putFileAs("contracts/$id", $this->document, "document.$type");
$path = $storage->putFileAs("contracts/{$this->id}", $this->document, "document.$type");
IngestDocuments::dispatch(
$this->id,

26
app/Ingest/PDFConvertor.php

@ -190,7 +190,7 @@ class PDFConvertor extends AbstractConvertor
$src = './contracts-images/' . pathinfo($this->directoryPath, PATHINFO_BASENAME) . '/' . pathinfo($p['src'], PATHINFO_BASENAME);
$html = $html . '<br>';
$html = $html . '<img style="position: relative; width:' . $p['width'] . 'px; height:' . $p['height'] . 'px;" src="' . $src . '" alt="' . $caption . '" title="' . $caption . '">';
$html = $html . '<img width=' . $p['width'] . ' ' . 'height=' . $p['height'] . ' src="' . $src . '" alt="' . $caption . '" title="' . $caption . '">';
$html = $html . '<br>';
$html = $html . '<br>';
@ -201,26 +201,13 @@ class PDFConvertor extends AbstractConvertor
{
$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 . "font-weight: 900;";
$style = $style . "width: " . $p['width'] . "px;";
$style = $style . "height: " . $p['height'] . "px;";
$style = $style . "top: " . $p['top'] . "px;";
$style = $style . "left: " . $p['left'] . "px;";
$style = $style . "font-size: $font_size" . "px;";
if ($p->i) {
$content = '<i>' . $p->i . '</i>';
} else if ($p->b) {
$content = '<b>' . $p->b . '</b>';
} else if ($p->a) {
$content = $p . '<a>' . $p->a . '</a>';
$content = $p . '<a href="' . $p->a . '">' . $p->a . '</a>';
} else {
$content = $p;
}
@ -231,7 +218,7 @@ class PDFConvertor extends AbstractConvertor
$tag = $this->getTag($font_size);
return '<' . $tag . ' style="' . $style . '">' . $content . '</' . $tag . '>';
return '<' . $tag . '>' . $content . '</' . $tag . '>';
}
protected function getTag($size)
@ -250,7 +237,7 @@ class PDFConvertor extends AbstractConvertor
return 'h3';
}
return 'p';
return 'span';
}
protected function applyOCR($path)
@ -278,11 +265,12 @@ class PDFConvertor extends AbstractConvertor
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
unlink($filepath . '/document.html');
return $process->getOutput();
}

Loading…
Cancel
Save