Converting odt files to pdf

I have a small script, which converts odt to pdf files:

find /home/armin/Dokumente/Briefepdf/ -name "*.odt"  -exec ./odt2pdf.sh "{}"  \;
exit

and

#! /bin/bash
libreoffice --headless --convert-to pdf --outdir $(dirname "$1") "$1"
exit

During operatio, the output of the script is:

Could not find Java Runtime enviroment

How to solve this ?

Install it?

sudo pacman -Syu jre-openjdk

1 Like

Why install it explicitly when it’s always a dependency?

❯ pacman -Si libreoffice-{fresh,still} | grep java-
Optional Deps   : java-runtime: adds java support
                  java-environment>=17: required by extension-wiki-publisher and extension-nlpsolver
Optional Deps   : java-runtime: adds java support
                  java-environment>=17: required by extension-wiki-publisher and extension-nlpsolver

By the way, in case one did not know, jre-openjdk / jreXX-openjdk provides java-runtime.

It really should be done this way:

sudo pacman -Syu  #  Always make sure one is up to date
sudo pacman -S --asdeps  java-runtime  # Choose preferred version

An alternative solution for converting odt to *pdf using pandoc. This could be scripted as needed, however, the downside is that latex would also need to be installed for .pdf output:

1. Install pandoc:

sudo pacman -S pandoc

2. Convert .odt to .pdf (example):

pandoc -s HelloWorld.odt -o HelloWorld.pdf
pandoc -s "Hello World.odt" -o "Hello World.pdf"

More examples here.

Cheers.

Libreoffice is also a java-free solution if users disable the JRE in libreoffice.
(as shown above its not actually a required dependency … its an optional one)

You can change this in the LO interface under Settings > Advanced.

You can also augment the configuration file in your HOME.

~/.config/libreoffice/[0-9]/user/config/javasettings_Linux_X86_64.xml

[...]
<enabled xsi:nil="false">false</enabled>
[...]

I also checked after ripping out java and the headless conversion works fine.

$ sudo pacman -Rdd jre-openjdk-headless 

Packages (1) jre-openjdk-headless-22.0.2.u9-1

Total Removed Size:  145.31 MiB

:: Do you want to remove these packages? [Y/n] 
:: Processing package changes...
No Java environment is set as default anymore
(1/1) removing jre-openjdk-headless                                                                           [##################################################################] 100%
:: Running post-transaction hooks...
(1/1) Arming ConditionNeedsUpdate...

$ libreoffice --headless --convert-to pdf testdoc.odt 
convert ~/Documents/testdoc.odt as a Writer document -> ~/Documents/testdoc.pdf using filter : writer_pdf_Export

I know we are talking about the function of a script here, but no java is needed to export an .odt file as pdf in LibreOffice. File-Export As-Export as pdf.

I don’t get the point of a script. Is it to batch convert?

Yes, it is.

Indeed. User has java runtime environment enabled for libreoffice … while not having a jre installed.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.