Conversion to PDF from Linux cron or from non X-window session

Hi all.

I have a problem with the conversion of ods documents to pdf through a shell script.

I use LibreOffice 3.4.5 on a linux workstation (CentOS 6.4).

I found the following solution:

libreoffice --headless --invisible --convert-to pdf file.ods 1>/dev/null 2>&1

which works flawlessly WHEN I USE A GRAPHICAL ENVIRONMENT.

If I try to use the script in (for example) crontab or if I connect to the workstation through ssh (without -X option)
the result of the script is as follows:

/usr/lib64/libreoffice/program/soffice.bin X11 error: Can’t open display:
Set DISPLAY environment variable, use -display option
or check permissions of your X-Server
(See “man X” resp. “man xhost” for details)

Is there any other procedure in order to convert to pdf even if the DISPLAY environment variable cannot be set?

Thank you in advance

I haven’t tried this, don’t have a Linux box at home to test this, but you problem looks like a X-Server security problem.

Execute this command in “your” user terminal (settings permissions):

    xhost +local:user_that_you_can_run_libre_office_without_a_problem

Then go to “user_that_you_can_run_libre_office_without_a_problem” user terminal, and type:

    export DISPLAY=:0

and then LibreOffice to PDF converting command.

Please report back any success or problem…
P.S. Running a script using cron it executes its own shell, so probably not working because of this.