Indeed. RTFM, in other words…
Just hoping someone had done this task already and save my valuable time! 
I modified the following, using code from @fpy
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import argparse
import sys
from os.path import basename, abspath
import uno
import unohelper
from com.sun.star.beans import PropertyValue
from com.sun.star.connection import NoConnectException
"""
The purpose of this example is to open a specified text document and save this
file to a specified URL. The type of the saved file is "writer8".
"""
PROG = "$OFFICE_PROGRAM_PATH/python {}".format(basename(sys.argv[0]))
SOFFICE_CONNECTION_URI = "uno:socket,host=localhost,port=54321;urp;StarOffice.ComponentContext"
def connect_soffice():
"""Connect to remote running LibreOffice
:return: an object representing the remote LibreOffice instance.
"""
local_context = uno.getComponentContext()
resolver = local_context.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", local_context
)
try:
remote_context = resolver.resolve(SOFFICE_CONNECTION_URI)
except NoConnectException:
raise Exception("Cannot establish a connection to LibreOffice.")
return remote_context.ServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", remote_context
)
def save_doc(src, dest, pages):
src_url = "file://{}".format(abspath(src)).replace("\\", "/")
dest_url = "file://{}".format(abspath(dest)).replace("\\", "/")
soffice = connect_soffice()
doc = soffice.loadComponentFromURL(
src_url, "_blank", 0, (PropertyValue(Name="Hidden", Value=True),)
)
doc = soffice.loadComponentFromURL(src_url, "_blank", 0, tuple([]))
filterProps = PropertyValue(Name="PageRange", Value=pages)
save_opts = (
PropertyValue(Name="Overwrite", Value=True),
PropertyValue(Name="FilterName", Value="writer_pdf_Export"),
PropertyValue(Name="FilterData", Value=filterProps),
)
try:
doc.storeAsURL(dest_url, save_opts)
print("Document", src, "saved under", dest)
finally:
doc.dispose()
print("Document closed!")
def main():
parser = argparse.ArgumentParser(description="Document Saver", prog=PROG)
parser.add_argument("src", help="Path to a Word document to be saved, e.g. path/to/hello.odt")
parser.add_argument("dest", help="Save the document to here, e.g. path/to/hello.pdf")
parser.add_argument("pages", help="Page range to be printed, e.g. 1-3")
args = parser.parse_args()
save_doc(args.src, args.dest, args.pages)
if __name__ == "__main__":
main()
This fails with ErrorCodeIOException (but see comment below).
Version: 7.4.7.2 / LibreOffice Community
Build ID: 40(Build:2)
CPU threads: 8; OS: Linux 6.1; UI render: default; VCL: gtk3
Locale: en-NZ (en_NZ.UTF-8); UI: en-US
Debian package version: 4:7.4.7-1+deb12u8
Calc: threaded