Buscar este blog

Mostrando entradas con la etiqueta LibreOffice. Mostrar todas las entradas
Mostrando entradas con la etiqueta LibreOffice. Mostrar todas las entradas

sábado, 23 de diciembre de 2017

LibreOffice - Force PDF/A export

I was using LibreOffice to convert documents from disparate formats to PDF. This is done by using the following command:
libreoffice5.3 --headless --convert-to pdf prueba.txt

My problem was that the output file was not int PDF/A format.



LibreOffice, by working with it´s GUI interface, do supports PDF/A conversion, so the problem should be in some kind of default configuration.


There is configuration file called registrymodifications.xcu which contains all settings used by the programa, and during the exportation too. This file is located in  ~/.config/libreoffice/4/user/ directory. For example /root/.config/libreoffice/4/user/registrymodifications.xcu.

This is an xml based file with a lot of (poor/undocumented) preferences. In particular, in order to set PDF/A as default option, you have to insert the following config line:
<?xml version="1.0" encoding="UTF-8"?>
<oor:items xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
 (...)
 <item oor:path="/org.openoffice.Office.Common/Filter/PDF/Export">
  <prop oor:name="SelectPdfVersion" oor:op="fuse">
   <value>1</value>
  </prop>
 </item>
 (...)
</oor:items>

Now, if you launch the conversion again you will get a PDF/A-1A file.

Though registrymodifications.xcu file is quite obscure, you can get mor info by using the GUI version of the program. If you navigate to Tools > Options > LibreOffice > Advanced > Open Expert Configuration, you can check the whole list of settings.

sábado, 11 de febrero de 2017

CentOS 6 - Install LibreOffice - Offline installation

In the previous post CentOS 6 - Install LibreOffice as a service I installed libre office by using yum repositories. But if your client machine does not have access to the yum repository wich contains these packages, you have a problem.

In my local installation, I used my CentOS-Base.repo yum repo (check appendix I). This is the repo in /etc/yum.repos.d/CentOS-Base.repo file:
(...)
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
(...)

This mirror is resolved as http://mirrorlist.centos.org/?release=6&arch=x86_64&repo=os&infra=stock (check appendix II)

So, you can add this repo to the client machine or you can prepare a "bundle" which contains all packages needed to your installation. I tried this second one.

In my local machine I used yum downloadonly plugin in order to download the libreoffice packages and all their dependencies, and save them in a directory.
yum install yum-plugin-downloadonly

yum install --downloadonly --downloaddir=/tmp/libreoffice libreoffice-headless
yum install --downloadonly --downloaddir=/tmp/libreoffice libreoffice-writer

cd /tmp
tar -zcvf libreoffice-4.3.7.gz libreoffice

Once you have all the RPM files, you only need to put them in the client machine and make a local install.
tar -xvf libreoffice-4.3.7.gz
cd libreoffice

yum localinstall *.rpm

Appendix I - How to know which repo a package came from

I you have a package installed and you want to know where it came from, you can use repoquery. This is a utility of yum-utils:
yum install yum-utils

repoquery -i libreoffice-writer

Appendix II - How to resolve yum properties

Yum properties like "releasever", "basearch" and "infra" can be resolved by using a python script:
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["rleaseserver"]'
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["basearch "]'
/usr/bin/python -c 'import yum;yb=yum.YumBase();yb.doConfigSetup(init_plugins=False);print yb.conf.yumvar["infra"]'

Apendix III - Why I did not install the latest version of libreoffice

My Unix skills are quite meager. I tried to download and install the latest stable libreoffice RPMs by downloading them from the official site: https://es.libreoffice.org/descarga/libreoffice-estable/?type=rpm-x86_64&version=5.2 , but after the installation I got a lot of errors like:
/opt/libreoffice5.1/program/oosplash: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory

Each time I installed the missing library, another one missing library appeared. I think this is due to the fact that I was using a CentOS server installation, without Gnome or KDE...

sábado, 4 de febrero de 2017

CentOS 6 - Install LibreOffice as a service

The purpose of this post is to show how to install LibreOffice in CentOS 6, without GUI. My requirements were to use LibreOffice as a PDF converter.

Install LibreOffice by using yum:
yum install libreoffice-headless

yum install libreoffice-writer

libreoffice --version

The install directory will be /usr/lib64/libreoffice

In order to make a test, you can try convert a file:
echo 'hola' > prueba.txt

libreoffice --headless --convert-to pdf prueba.txt

If you want to install it as a service, just create the following file and save it in /etc/init.d (I copied this file from here):
#!/bin/sh
#
# ooffice       openoffice conversion service
#
#
# chkconfig: 345 50 25
# description: Startup script for the Open Office conversion process
# pidfile: /var/run/ooffice.pid

# Source function library.
. /etc/rc.d/init.d/functions

proc="/usr/lib64/libreoffice/program/soffice.bin"
options="--headless --accept=\"socket,host=0,port=8100,tcpNoDelay=1;urp\" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible &"
if [ ! -f $proc ]; then
        proc="/usr/lib64/openoffice.org3/program/soffice.bin"
        options="--headless --accept=\"socket,host=0,port=8100,tcpNoDelay=1;urp\" --nodefault --nofirststartwizard --nolockcheck --nologo --norestore --invisible &"
fi


prog=ooffice
PID_FILE=/var/run/ooffice.pid

LOG=/var/log/ooffice
if [ ! -f $LOG ]; then
        touch $LOG
        chmod 644 $LOG
fi


start() {
        echo -n $"Starting $prog: "
        umask 000
        daemon $prog $options
        RETVAL=$?
        echo
        sleep 1
        pidofproc $proc > $PID_FILE
        echo "`date +\"%Y-%m-%d %T\"`  Starting ooffice." >> $LOG
        return $RETVAL
}

stop() {
        echo -n $"Stopping $prog: "
        killproc -p $PID_FILE $prog
        RETVAL=$?
        echo
        echo "`date +\"%Y-%m-%d %T\"`  Stopping ooffice." >> $LOG
        return $RETVAL
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                sleep 1
                start
                ;;
        status)
                status -p $PID_FILE $prog
                ;;
        *)
                echo $"Usage: $prog {start | stop | restart | status}"
                exit 1
esac

exit $RETVAL

Finally configure this script as an executable and set the service as autostart:
chmod +x /etc/init.d/soffice
chkconfig --add soffice
chkconfig soffice on
service soffice start