20.0.4 on Debian, converting odt to pdf is slow

SOLUTION to the slow convert:

  • Install unoconf with apt install unoconv

  • Create soffice systemd script:

[Unit]
Description=LibreOffice service
After=syslog.target

[Service]
                ExecStart=soffice --nologo --headless --nofirststartwizard --accept='socket,host=127.0.0.1,port=2220,tcpNoDelay=1;urp;StarOffice.Service'
Restart=always
KillSignal=SIGQUIT
Type=simple
StandardError=syslog
User=www-data
#User=ctsroot

[Install]
WantedBy=multi-user.target

Change in includes/odtpdf.php

+++ odf.php	2025-10-01 21:55:45.052000000 +0200
@@ -844,7 +844,8 @@
 			// using linux/mac libreoffice that must be in path
 			// Note PHP Config "fastcgi.impersonate=0" must set to 0 - Default is 1
 			$command ='soffice --headless -env:UserInstallation=file:'.(getDolGlobalString('MAIN_ODT_ADD_SLASH_FOR_WINDOWS') ? '///' : '').'\''.$conf->user->dir_temp.'/odtaspdf\' --convert-to pdf --outdir '. escapeshellarg(dirname($name)). " ".escapeshellarg($name);
-		} elseif (preg_match('/unoconv/', getDolGlobalString('MAIN_ODT_AS_PDF'))) {
+		//} elseif (preg_match('/unoconv/', getDolGlobalString('MAIN_ODT_AS_PDF'))) {
+                } elseif (getDolGlobalString('MAIN_ODT_AS_PDF') == 'unoconv') {
 			// If issue with unoconv, see https://github.com/dagwieers/unoconv/issues/87
 
 			// MAIN_ODT_AS_PDF should be   "sudo -u unoconv /usr/bin/unoconv" and userunoconv must have sudo to be root by adding file /etc/sudoers.d/unoconv with content  www-data ALL=(unoconv) NOPASSWD: /usr/bin/unoconv .
@@ -869,8 +870,9 @@
 			// - set shell of user to bash instead of nologin.
 			// - set permission to read/write to user on home directory /var/www so user can create the libreoffice , dconf and .cache dir and files then set permission back
 
-			$command = getDolGlobalString('MAIN_ODT_AS_PDF').' '.escapeshellcmd($name);
+			//$command = getDolGlobalString('MAIN_ODT_AS_PDF').' '.escapeshellcmd($name);
 			//$command = '/usr/bin/unoconv -vvv '.escapeshellcmd($name);
+			$command = '/usr/bin/unoconv -vvvv -n --connection "socket,host=127.0.0.1,port=2220,tcpNoDelay=1;urp;StarOffice.ComponentContext" '.escapeshellcmd($name);
 		} else {
 			// deprecated old method using odt2pdf.sh (native, jodconverter, ...)
 			$tmpname=preg_replace('/\.odt/i', '', $name);

Now ODT2PDF is more or less same speed as pdf template.

NOTE: The /var/www homedir of the www-data user must be chowned to www-data so the .config and .cache dirs can be created.

1 Like