Having unoconv issues - won't convert files

Having unoconv issues - won't convert files

by Evan Donovan -
Number of replies: 4

I'm having issues with the Annotate PDF feature that is new on Moodle 3.1. I can get it to work with PDF files, but the other files come across as just a blank white page. When I run the test script for unoconv that is included as part of Moodle, it says that it is not able

I am running Moodle 3.1+ on CentOS 7.2 (x86_64), Apache 2.4.6, PHP 5.4.16, and MariaDB (MySQL drop-in replacement) 5.5.47.

I installed LibreOffice 5.1.4 from RPM and cloned unoconv from the Github repository, so I am running the latest version of it. I followed the advice in the readme file to change the script's shebang line to reference the Python that is included as part of LibreOffice. After doing that, the script worked fine from command line using:

unoconv -f pdf filename.doc

or the like, when I was the root user or the regular user under which I log in. However, it got a permissions error exit 77 when trying to spawn the LibreOffice listener instance when I tried running it as the user under which the web server runs (apache).

I was able to resolve this error on the command line as the apache user by running:

export HOME=/tmp

before running unoconv. See http://superuser.com/questions/627266/convert-file-to-pdf-using-libreoffice-under-user-apache-i-e-when-using-php.

However, I think that the home directory may not be getting set when I try to create a file for unoconv in Moodle itself. I tried modifying file_storage.php to have the following:

shell_exec('export HOME=' . $tmp);
        $cmd = escapeshellcmd(trim($CFG->pathtounoconv)) . ' ' .
               escapeshellarg('-f') . ' ' .
               escapeshellarg($format) . ' ' .
               escapeshellarg('-o') . ' ' .
               escapeshellarg($newtmpfile) . ' ' .
               escapeshellarg($filename);

However, that did not make a difference. The test pdf file that unoconv is supposed to create is still 0 bytes in size.

Average of ratings: -
In reply to Evan Donovan

Re: Having unoconv issues - won't convert files

by Ken Task -
Picture of Particularly helpful Moodlers

Dag's notes suggested changing the shebang only IF having issues using apache.   So with the path set in Moodle to /usr/bin/unoconv and the shebang set to:

#!/usr/bin/env python

It didn't work?

Reason I ask ... CentOS 6 PHP 5.5.38 with minimal LbreOffice installed via CLI rpm Moodle 3.1.1+ (Build: 20160714) with no hacks/changes to code, the test works just fine.

'spirit of sharing', Ken

In reply to Ken Task

Re: Having unoconv issues - won't convert files

by Anis Jradah -

Dear All,

I have the same problem, below is my environment:

unoconv
/usr/bin/unoconv

Python 3.4.3
/usr/bin/python

unoconv --version
unoconv 0.7
Written by Dag Wieers <dag@wieers.com>
Homepage at http://dag.wieers.com/home-made/unoconv/

platform posix/linux
python 3.4.3 (default, Jul 11 2016, 11:30:44)
[GCC 5.3.1 20160406 (Red Hat 5.3.1-6)]
LibreOffice 5.0.6.2

  • By the way, unoconv is converting properly file in the command line.


Previously I always got a zero size PDF file when use the link:

../m311/mod/assign/feedback/editpdf/testunoconv.php?sendpdf=1&sesskey=WP4fVyYNh2

I rechecked the installation instructions of unoconv and I have created a home folder called www-data for the apache user and gave it full access to this folder using this command
  chown -R apache:apache /home/www-data/
  chmod 755 /home/www-data/


  • Now the test file size is 132 bytes instead of 0 bytes, but it cannot be open with PDF, then I open it with notepad++ and below text is added. Attached is the unoconv PDF test file.


<br />
<b>Warning</b>:  readfile(): Filename cannot be empty in <b>/var/www/html/m311/lib/filelib.php</b> on line <b>1832</b><br />


The test server I have:

Linux version 4.6.5-200.fc23.x86_64 (mockbuild@bkernel01.phx2.fedoraproject.org) (gcc version 5.3.1 20160406 (Red Hat 5.3.1-6) (GCC) ) #1 SMP Thu Jul 28 01:10:25 UTC 2016


Moodle 3.1.1+ (Build: 20160721)


Thank you always for all your help.


Best regards,

Anis




In reply to Anis Jradah

Re: Having unoconv issues - won't convert files

by Ken Task -
Picture of Particularly helpful Moodlers

Think about the only way is to compare notes ... and know exactly what you have.

@Evan has a higher version of LibreOffice ... compat with CentOS 7.
@Anis using Fedora 23

this to say while there is similarity, there's also difference.

On a CentOS 6 box, I don't care if I have the latest/greatest libreoffice or not ... just something compat:
From yum package manager:
Available Packages
libreoffice.x86_64 1:4.3.7.2-2.el6


But it was installed via RPM's ...

via yum to acquire only what was needed ... therein the file I used:

yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-xsltfilter.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-headless.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-impress.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-calc.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-impress.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-langpack-en.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-writer.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-draw.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-ure.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-testtools.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-filters.x86_64
yum install --downloadonly --downloaddir=/root/libreoffice/ libreoffice-pyuno.x86_64

What I wanted to avoid was all the language packs ... just needed english
The above when installed via yum -Uvh *.rpm did acquire some dependencies.

**** KEY IS HEADLESS ****
[root@visdmoodle libreoffice]# rpm -qpil libreoffice-headless-4.3.7.2-2.el6.x86_64.rpm
Name        : libreoffice-headless         Relocations: (not relocatable)
Version     : 4.3.7.2                           Vendor: CentOS
Release     : 2.el6                         Build Date: Wed 11 May 2016 01:43:30 PM CDT
Install Date: (not installed)               Build Host: worker1.bsys.centos.org
Group       : Development/Libraries         Source RPM: libreoffice-4.3.7.2-2.el6.src.rpm
Size        : 1906008                          License: (MPLv1.1 or LGPLv3+) and LGPLv3 and LGPLv2+ and BSD and (MPLv1.1 or GPLv2 or LGPLv2 or Netscape) and Public Domain and ASL 2.0 and Artistic and MPLv2.0 and CC0
Signature   : RSA/SHA1, Thu 12 May 2016 05:45:58 AM CDT, Key ID 0946fca2c105b9de
Packager    : CentOS BuildSystem <http://bugs.centos.org>
URL         : http://www.libreoffice.org/
Summary     : LibreOffice Headless plug-in
Description :
A plug-in for LibreOffice that enables it to function without an X server.
It implements the -headless command line option and allows LibreOffice to be
used as a backend server for e.g. document conversion.
/usr/lib64/libreoffice/program/libbasebmplo.so
/usr/lib64/libreoffice/program/libvclplug_svplo.so


Section on Python and pyuno incompatibilities

There are some trouble shooting tips.

Python and pyuno incompatibilities

Beware that the pyuno python module needs to be compiled with the exact same version of python that you are using to load it. A lot of people that run into problems loading pyuno are actually using a precompiled LibreOffice that they downloaded somewhere and is incompatible with the python version on their system.

CentOS 6.highest box ... I copied the unoconv to /usr/bin/ and made it executable ... plus tinkered with the shebang line.   Below works on CentOS 6 ... may not work on CentOS 7 nor on Fedora 23.

[root@server]# cd /usr/bin/
[root@server bin]# ls -l unoconv
-rwxr-xr-x. 1 root root 68527 Jun 12 11:41 unoconv

[root@visdmoodle bin]# head unoconv
#!/usr/bin/env python
### !/usr/lib64/libreoffice/share/Scripts/python
### original !/usr/bin/env python

Can't say for sure on CentOS 7 with the higher version of LibreOffice ... and can't say for sure on Fedora 23 either.

Hopefully, by sharing info, we'll discover that little things that make a difference in using unoconv.

'spirit of sharing', Ken

In reply to Ken Task

Re: Having unoconv issues - won't convert files

by Mathew Gancarz -
Picture of Core developers

My steps, for setup from scratch on CentOS 7, with selinux enabled, assuming you have git installed.

Unoconv 7 installation:

  1. Make sure no existing version currently installed: yum remove libreoffice*
  2. Grab a copy of LibreOffice 5.2.2: wget http://download.documentfoundation.org/libreoffice/stable/5.2.2/rpm/x86_64/LibreOffice_5.2.2_Linux_x86-64_rpm.tar.gz
  3. Extract: tar -xvf LibreOffice_5.2.2_Linux_x86-64_rpm.tar.gz
  4. Install by navigating to the extracted folder / RPMS folder, and run yum localinstall *.rpm
  5. Install required Cairo2d library: yum install cairo

Get the unoconv script:

  1. git clone https://github.com/dagwieers/unoconv.git
  2. cp unoconv/unoconv /usr/bin
  3. Edit first line of it in /usr/bin/unoconv to be: #!/opt/libreoffice5.2/program/python

Configure it to run in listener mode in background via systemctl service: See Installing_unoconv#Run_a_unoconv_listener and follow specific directions bellow

  1. vi /etc/systemd/system/unoconv.service
  2. And then copy and paste the following configuration into it:
    1. [Unit]
    2. Description=Unoconv listener for document conversions
    3. Documentation=https://github.com/dagwieers/unoconv
    4. After=network.target remote-fs.target nss-lookup.target
    5. [Service]
    6. Type=simple
    7. Environment="UNO_PATH=/opt/libreoffice5.2/program"
    8. ExecStart=/usr/bin/unoconv --listener
    9. [Install]
    10. WantedBy=multi-user.target
  3. Enable and start the above service:

    1. systemctl enable unoconv.service

    2. systemctl start unoconv.service

  4. It should now be configured for command line use, test via command line: sudo -u apache unoconv -vvv -f pdf /tmp/testdoc.docx

The next step is setting home folder of the apache user. Edit /etc/passwd and change in the apache user line the string "/usr/share/httpd" to be "/var/www/moodledata/temp", or some other temporary directory that apache has write access to

Then finally SELinux policy tweaks:

  1. You will also need to generate and install a policy module. After trying to upload a file, run the following commands:
    1. grep python.bin /var/log/audit/audit.log | audit2allow -M unconv-python-policy
    2. semodule -i unconv-python-policy.pp
  2. Make sure it is properly configured: /admin/search.php?query=unoconv (this will almost always fail unfortunately in my experience) And also on the UI /mod/assign/feedback/editpdf/testunoconv.php
  3. Then finally try to upload assignments, and watch the httpd logs for errors (It will almost always seem to generate a PHP Warning:  touch(): Utime failed: Permission denied in ...) even if selinux is set to permissive. Seems to work anyways though.

Average of ratings: Useful (1)