- Wed Jun 12, 2019 2:21 pm
#824856
Hi.
I am hoping someone can assist me .
This is my first time posting, however I have been a frequent visitor of these forums for the last two years.
Usually I can always figure out a solution to any of my problems from existing posts, however it seems I am stuck for once.
I have a process where the users have .docx files and I want to convert them into .pdf.
Now I never expected ProcessMaker to have this functionality built in but I decided to look into PHP and command-line solutions
Originally I looked at other options, but they all had conversion issues where the formatting and style would be lost from the original docx. Eventually I came across LibreOffice's headless mode where via the command line it could do the conversion. It is slower than I would like, but the results are good.
I am running ProcessMaker on top of FreeBSD (open-source Unix-like operating system) and in the FreeBSD environment I can use this command to do the conversion:
This works flawlessly, however when I try to run it through PHP in ProcessMaker using the exec() command it doesn't work:
I have tried many variations including the 'unoconv' port in command-line which anyway requires Libreoffice to be installed.
I tried debugging through ProcessMaker to see what it runs the code under. the 'env' command yields the following array:
And the 'whoami' command yields this.
This led me to the assumption that this had to do with the php code executing the exec() command as the Apache user 'www' in my operating system.
Looking at other forums people have mentioned issues running this command from PHP through Apache due to their either being no home or temporary directory for the conversion to take place.
I tried these fixes such as setting the HOME environment variable to a tmp directory of my choosing, however I can't seem to figure out if they are taking affect as the arrays returned are generally empty.
Does anyone know if they can run this command from ProcessMaker, and if so how?
Or perhaps another solution to this problem?
I apologise for the length of this post, but I didn't want to leave out any possibly important details. I am still new to UNIX systems so I have had to learn a lot in the past few weeks.
Any help would be greatly appreciated.
I am hoping someone can assist me .
This is my first time posting, however I have been a frequent visitor of these forums for the last two years.
Usually I can always figure out a solution to any of my problems from existing posts, however it seems I am stuck for once.
I have a process where the users have .docx files and I want to convert them into .pdf.
Now I never expected ProcessMaker to have this functionality built in but I decided to look into PHP and command-line solutions
Originally I looked at other options, but they all had conversion issues where the formatting and style would be lost from the original docx. Eventually I came across LibreOffice's headless mode where via the command line it could do the conversion. It is slower than I would like, but the results are good.
I am running ProcessMaker on top of FreeBSD (open-source Unix-like operating system) and in the FreeBSD environment I can use this command to do the conversion:
Code: Select all
// libreoffice --headless --convert-to pdf --outdir $outputDirHere $docxFullPath
libreoffice --headless --convert-to pdf --outdir /usr/home/pmvm/pdf_temp /usr/home/pmvm/pdf_temp/testDoc.docx
This works flawlessly, however when I try to run it through PHP in ProcessMaker using the exec() command it doesn't work:
Code: Select all
$command = 'libreoffice --headless --convert-to pdf --outdir /usr/home/pmvm/pdf_temp /usr/home/pmvm/pdf_temp /testDoc.docx';
$output = exec($command, @@test);
I have tried many variations including the 'unoconv' port in command-line which anyway requires Libreoffice to be installed.
I tried debugging through ProcessMaker to see what it runs the code under. the 'env' command yields the following array:
Array (
[0] => PATH=/sbin:/bin:/usr/sbin:/usr/bin
[1] => LD_LIBRARY_PATH=/usr/local/lib
[2] => PWD=/usr/local/processmaker/workflow/public_html
[3] => HOME=/ [4] => RC_PID=22 )
And the 'whoami' command yields this.
Array ( [0] => www)
This led me to the assumption that this had to do with the php code executing the exec() command as the Apache user 'www' in my operating system.
Looking at other forums people have mentioned issues running this command from PHP through Apache due to their either being no home or temporary directory for the conversion to take place.
I tried these fixes such as setting the HOME environment variable to a tmp directory of my choosing, however I can't seem to figure out if they are taking affect as the arrays returned are generally empty.
Code: Select all
$command = 'setenv HOME tmp && libreoffice --headless --convert-to pdf --outdir /usr/home/pmvm/pdf_temp /usr/home/pmvm/pdf_temp /testDoc.docx';
$output = exec($command, @@test);
Does anyone know if they can run this command from ProcessMaker, and if so how?
Or perhaps another solution to this problem?
I apologise for the length of this post, but I didn't want to leave out any possibly important details. I am still new to UNIX systems so I have had to learn a lot in the past few weeks.
Any help would be greatly appreciated.