ncjoes / office-converter

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

Convertion Failure! Contact Server Admin. #13

Closed CtrlShiftN closed 4 years ago

CtrlShiftN commented 5 years ago

Here is my code:

// this way is using LibreOffice
    $converter = new OfficeConverter($filename);
    $nameFile = pathinfo($filename, PATHINFO_FILENAME) . ".html";
    $content = "";
    try {
        $converter->convertTo($nameFile); //generates pdf file in same directory as test-file.docx
        $content = file_get_contents(dirname($filename)."\\".$nameFile);
        return $content;

    } catch (\NcJoes\OfficeConverter\OfficeConverterException $e) {
        return $e->getMessage();
    }

And when I run, It return message: Convertion Failure! Contact Server Admin. I am using Yii2 PHP Framework to convert .doc to .html then to plain text. Please help me!

ChavaBerman commented 5 years ago

having the same issue, please help.

ChavaBerman commented 5 years ago

getting this error back: 'export' is not recognized as an internal or external command, operable program or batch file.

carlos00027 commented 4 years ago

Hi, I also have the same problem I have WHM and Centos 7 installed. I use Laravel. which may be

asdasdsdsdd commented 4 years ago

"Convertion Failure! Contact Server Admin." Problem. I use windows 7 and wamp. Libreoffice is already installed. How can I solve the problem?

ehsanmohebbi commented 4 years ago

@ChavaBerman @tayfunyazici1 This wrapper generates command and execute that. I am using the LibreOffice 6.4 which doesn't have the 'libreoffice' command instead it has the 'soffice'(for .doc and .docx), 'scalc (for xls & xlsx) ', 'sbase', 'sdraw' and 'simpress'. at the same time I think that the code is written for linux not for windows. I did brought some change for example, i set the $bin attribute to 'soffice' in constructor instead of 'libreoffice' line 27, and at line 233 i changed the 'export' to 'set' it converts now the docx to pdf and html perfectly. Also add the 'C:\Program Files\LibreOffice\program' to the System environment path.

shihabudheenf commented 4 years ago

@ehsanmohebbi it is not working in my case... i am using libreOffice 6.4.1 :(

Jaynarak commented 4 years ago

@ChavaBerman @tayfunyazici1 This wrapper generates command and execute that. I am using the LibreOffice 6.4 which doesn't have the 'libreoffice' command instead it has the 'soffice'(for .doc and .docx), 'scalc (for xls & xlsx) ', 'sbase', 'sdraw' and 'simpress'. at the same time I think that the code is written for linux not for windows. I did brought some change for example, i set the $bin attribute to 'soffice' in constructor instead of 'libreoffice' line 27, and at line 233 i changed the 'export' to 'set' it converts now the docx to pdf and html perfectly. Also add the 'C:\Program Files\LibreOffice\program' to the System environment path.

Thank you. It work for me.

Saketsuraj commented 4 years ago

I am using windows and your solution didn't make any difference. Any other idea? @ehsanmohebbi .

upnext21 commented 4 years ago

any solution here? Thank you. I already did the @ehsanmohebbi solution. It doesn't work for me.

agumaxwellforcode commented 4 years ago

Please has any one found a solution to this? please help.

ehsanmohebbi commented 4 years ago

Update @shihabudheenf , @Saketsuraj , @upnext21 , @agumaxwellforcode As I saw many notifications in my email! too late, but it might help someone else who faces this issue. LibreOffice 6.4.0.3(x64). set $bin = ' ' in constructor. replace the makeCommand method with: protected function makeCommand($outputDirectory, $outputExtension,$filename) { $oriFile = escapeshellarg($this->file); $outputDirectory = escapeshellarg($outputDirectory); if (pathinfo($this->file,PATHINFO_EXTENSION) == 'docx' || pathinfo($this->file,PATHINFO_EXTENSION) == 'doc' || pathinfo($this->file,PATHINFO_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}:calc_pdf_Export {$oriFile} --outdir {$outputDirectory}"; } } Dont forget to add the LibreOffice path to system environment variable.

marie1st commented 3 years ago

Well, I could not find LibreOffice Path in my macOS, could it simply cd Applications/LibreOffice.app ? I could not find any further content after the Applications

ppavezh commented 3 years ago

Any solution?

i followed all step and it keeps saying "Convertion Failure! Contact Server Admin." on W10, LibreOffice 6.4

Saketsuraj commented 3 years ago

It works on ubuntu. It is tough to make it work on windows because it is not made to work on windows. I don't remember the exact steps to make it work on windows but you will have to create an environment variable and then you will have to make some changes in the source code of this library.

On Sat, 8 May, 2021, 4:59 am ppavezh, @.***> wrote:

Any solution?

i followed all step and it keeps saying "Convertion Failure! Contact Server Admin." on W10, LibreOffice 6.4

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ncjoes/office-converter/issues/13#issuecomment-834860103, or unsubscribe https://github.com/notifications/unsubscribe-auth/AISKWHJMI7T73H4MRHHH4JDTMRZXBANCNFSM4ISIOJOQ .

DonBoscoMushi commented 2 years ago

All methods and steps dont work in LibreOffice 7.2.2 ... Installed as snap package

heymerridew commented 1 year ago

Hello everyone.

It's a bit late but I hope it helps someone. I am using Windows 11 with LibreOffice 7.4.

For windows you must pass the $bin parameter as 'soffice' since this version of LibreOffice does not contain the 'libreoffice' executable. The last parameter must be false to execute the command without the HOME prefix

$converter = new OfficeConverter($filename, null, 'soffice', false);

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/

linnddaaaa commented 3 months ago

Hi! i know i'm too late to ask, but can you help me guys? english my second language, i'm sorry if you don't get it. so, i'm doing same work to convert phpword to pdf using converter, i have install and add use NcJoes\OfficeConverter\OfficeConverter; this is the part of the code:

$phpWord->saveAs('certificate.docx');
        $converter = new OfficeConverter('certificate.docx');
        $converter->convertTo('certificate.pdf');
        $converter = new OfficeConverter('certificateTemp.docx', null, 'soffice', false);

        return Response::download('certificate.pdf')->deleteFileAfterSend(true);

and output that i get is:

{ "error": true, "data": null, "code": 500, "message": "Convertion Failure! Contact Server Admin." }

can someone help me please, anw, i'm using laravel lumen. Thank you.

heymerridew commented 3 months ago

Hi! i know i'm too late to ask, but can you help me guys? english my second language, i'm sorry if you don't get it. so, i'm doing same work to convert phpword to pdf using converter, i have install and add use NcJoes\OfficeConverter\OfficeConverter; this is the part of the code:

$phpWord->saveAs('certificate.docx');
        $converter = new OfficeConverter('certificate.docx');
        $converter->convertTo('certificate.pdf');
        $converter = new OfficeConverter('certificateTemp.docx', null, 'soffice', false);

        return Response::download('certificate.pdf')->deleteFileAfterSend(true);

and output that i get is:

{ "error": true, "data": null, "code": 500, "message": "Convertion Failure! Contact Server Admin." }

can someone help me please, anw, i'm using laravel lumen. Thank you.

Hi!

The problem may be the first instance of OfficeConverter that doesn't receive the proper parameters and attempts to convert the file with the default parameters. You can remove it and use only the second instance:

$phpWord->saveAs('certificate.docx');
$converter = new OfficeConverter('certificate.docx', null, 'soffice', false);
$converter->convertTo('certificate.pdf');

return Response::download('certificate.pdf')->deleteFileAfterSend(true);

I don't know much about Laravel Lumen but for example in Laravel we can use Storage Facade to access files and disks, I recommend using it if possible to generate the absolute path to your file so that OfficeConverter can correctly access your file.

$phpWord->saveAs('certificate.docx');

$filename = 'certificate.pdf';
$input = Storage::path('certificate.docx');
$output = Storage::path($filename);

$converter = new OfficeConverter($input, null, 'soffice', false);
$converter->convertTo($filename);

return Response::download($output)->deleteFileAfterSend(true);
linnddaaaa commented 3 months ago

first instance of OfficeConverter that doesn't receive the proper parameters

Thank you so much for u help, i'm still struggle because the file (certificate.docx) not read i get the output like this: { "error": true, "data": null, "code": 500, "message": "File does not exist --C:\Users\Lenovo\ms11.certificate\storage\app\certificate.docx" }

and still if i use the second code, the output: { "error": true, "data": null, "code": 500, "message": "Convertion Failure! Contact Server Admin." }

heymerridew commented 3 months ago

and still if i use the second code, the output: { "error": true, "data": null, "code": 500, "message": "Convertion Failure! Contact Server Admin." }

Do you have LibreOffice installed?

linnddaaaa commented 3 months ago

i did, but still same. but now is clear, thank you so much for u help!