问题
I'm trying to generate a pdf from docx using soffice so i try it on apache linux and its works, but im trying in windows server 2012 and IIS 6.2.
If i run this command on CMD its works:
soffice --headless --convert-to pdf:writer_pdf_Export --outdir ../../storage/app/ACTIVO/2019-03/3404/docx/ ../../storage/app/ACTIVO/2019-03/3404/docx/documento_word.docx
So in PHP I try this:
$comando = 'soffice --headless --convert-to pdf:writer_pdf_Export --outdir ../../storage/app/ACTIVO/2019-03/3404/docx/ ../../storage/app/ACTIVO/2019-03/3404/docx/documento_word.docx';
$var = exec($comando);
var_dump($var);
And its give me "NULL"
The same happen when i try to use soffice --version in PHP.
I give full permission to IUSR in C:\Program Files\Libreoffice and storage/app have permission too. In IIS the Anonymous Authentication is enabled.
I run in php and its return " string(26) "iis apppool\defaultapppool" "
$var = exec('whoami');
var_dump($var);
I don't know how can i do to fix it.
回答1:
I solved it, creating a new user in Windows with low permission to run a command like that user. I nstall SysinternalsSuite to run psexec command, the zip is descompressed in C:\
So, the line that i change was:
$comando = 'soffice --headless --convert-to pdf:writer_pdf_Export --outdir ../../storage/app/ACTIVO/2019-03/3404/docx/ ../../storage/app/ACTIVO/2019-03/3404/docx/documento_word.docx';
to:
$comando = '"C:\SysinternalsSuite\psexec.exe" -u DOMAIN\USER -p PASSWORD "C:\Program Files\LibreOffice\program\soffice.exe" --headless --convert-to pdf:writer_pdf_Export --outdir C:\inetpub\wwwroot\storage\app\ACTIVO\2019-03\3404\docx\ C:\inetpub\wwwroot\storage\app\ACTIVO\2019-03\3404\docx\documento_word.docx';
来源:https://stackoverflow.com/questions/55244012/running-generate-pdf-soffice-libreoffice-on-windows-php-exec-doesnt-work