convertToPdfWithLibreOffice(); $pdfFilePath = "$this->directoryPath/document.pdf"; if ( ! $this->storage->exists($pdfFilePath)) { throw new \Exception('Failed to convert to PDF: ' . $pdfFilePath); } $convertor = new PDFConvertor($this->storage, $pdfFilePath); $convertor->execute(); } protected function convertToPDF() { (new Process(['export HOME=' . env('USER_HOME_PATH')]))->run(); $process = new Process([ 'unoconv', '-f', 'pdf', // '-c=socket,host=localhost,port=' . (2000 + rand(2, 7)) . ';urp;StarOffice.ComponentContext', $this->storage->path($this->path), ]); $process->setTimeout(10); $process->run(); if (!$process->isSuccessful()) { throw new ProcessFailedException($process); } $this->deleteOriginalDocument(); } /** * * @throws \Exception */ protected function convertToPdfWithLibreOffice() { $office = new Office(); $success = $office->run( 'pdf', $this->storage->path($this->path), $this->storage->path($this->directoryPath) ); if (! $success) { throw new \Exception('Failed when converting from DOCX to PDF for file: ' . $this->path); } $this->deleteOriginalDocument(); } }