ncjoes / office-converter

PHP Wrapper for LibreOffice
MIT License
208 stars 77 forks source link

Convertion Failure! Contact Server Admin #29

Open LeiraT opened 3 years ago

LeiraT commented 3 years ago

Hello, Im using laravel 8. I already install libre office 7.0.5 in centos 7. I also already update public function __construct($filename, $tempPath = null, $bin = ' ', $prefixExecWithExportHome = true) { if ($this->open($filename)) { $this->setup($tempPath, $bin, $prefixExecWithExportHome); } }

and protected function makeCommand($outputDirectory, $outputExtension) { $oriFile = escapeshellarg($this->file); $outputDirectory = escapeshellarg($outputDirectory);

    if (pathinfo($this->file,PATHINFO_EXTENSION) == 'docx' || pathinfo($this->file,PATHINFO_EXTENSION) == 'doc' || pathinfo($this->file,PATH_EXTENSION) == 'DOCX' 
    || pathinfo($this->file,PATHINFO_EXTENSION) == 'DOC') { return "soffice --headless --convert-to {$outputExtension} {$oriFile} --outdir {$outputDirectory}";}
    else if(pathinfo($this->file,PATHINFO_EXTENSION) == 'xlsx' || pathinfo($this->file,PATHINFO_EXTENSION) == 'xls' || pathinfo($this->file,PATHINFO_EXTENSION) == 'XLSX'
    || pathinfo($this->file,PATHINFO_EXTENSION) == 'XLS'){ 
       return "scalc --headless --convert-to {$outputExtension} {$oriFile} --outdir {$outputDirectory}";
    }
}

but it still return the Convertion failure. Contact Admin

fd6130 commented 2 years ago

I believe it is because the command fail to execute.

Try go to public function convertTo($filename) in OfficeConverter.php and locate $shell = $this->exec($this->makeCommand($outdir, $outputExtension));

You can try to debug that command output in your terminal.

PoojaJadav commented 2 years ago

I got same issue. that execute command is libreoffice --headless --convert-to pdf inputpath outputdir from this package. if I'm trying to execute command in system /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf inputpath outputdir in terminal. it's working fine.

Can you guide us on where we need to add exe path in laravel project?

fd6130 commented 2 years ago

The issue is cause by the constructor default bin value:

 public function __construct($filename, $tempPath = null, $bin = 'libreoffice', $prefixExecWithExportHome = true)

Try change it to the path where libreoffice located in your system:

$bin = '/Applications/LibreOffice.app/Contents/MacOS/soffice';
$converter = new OfficeConverter('test-file.docx', 'path-to-outdir', $bin);

I got same issue. that execute command is libreoffice --headless --convert-to pdf inputpath outputdir from this package. if I'm trying to execute command in system /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf inputpath outputdir in terminal. it's working fine.

Can you guide us on where we need to add exe path in laravel project?

gtcesar commented 4 months ago

In Ubuntu 22.04 I solved it by giving permission to the /var/www directory for the user www-data sudo chown -R www-data:www-data /var/www/

carlosmolano commented 8 minutes ago

In Ubuntu 22.04 I solved it by giving permission to the /var/www directory for the user www-data sudo chown -R www-data:www-data /var/www/

in Ubuntu 20 , It worked for me too, thanks @gtcesar