Browse Source

Convert DOCX to PDF so we will handle DOCX files the same way

hidden_tags_with_bookmarks
Orzu Ionut 3 years ago
parent
commit
3a4e470cc6
  1. 3
      README.md
  2. 35
      app/Ingest/DocxConvertor.php

3
README.md

@ -77,6 +77,9 @@ pip3 install -r requirements.txt
pip3 install mat2
apt-get install gir1.2-poppler-0.18
# DOCX to PDF Convertor
apt-get install unoconv
```
## Local Usage

35
app/Ingest/DocxConvertor.php

@ -9,18 +9,19 @@ class DocxConvertor extends AbstractConvertor
{
public function execute()
{
$this->convertToText();
// $this->convertToText();
//
// $convertor = new TextConvertor($this->storage, "$this->directoryPath/document.txt");
//
// $convertor->execute();
$convertor = new TextConvertor($this->storage, "$this->directoryPath/document.txt");
$this->convertToPDF();
$convertor = new PDFConvertor($this->storage, "$this->directoryPath/document.pdf");
$convertor->execute();
}
/**
* Convert docx file to text
*
* @return void
*/
protected function convertToText()
{
(new Process(['export HOME=' . env('USER_HOME_PATH')]))->run();
@ -43,4 +44,24 @@ class DocxConvertor extends AbstractConvertor
$this->deleteOriginalDocument();
}
protected function convertToPDF()
{
(new Process(['export HOME=' . env('USER_HOME_PATH')]))->run();
$process = new Process([
'unoconv',
'-f',
'pdf',
$this->storage->path($this->path),
]);
$process->run();
if (!$process->isSuccessful()) {
throw new ProcessFailedException($process);
}
$this->deleteOriginalDocument();
}
}
Loading…
Cancel
Save