This simple command should help:
soffice --headless --convert-to pdf ./* --outdir /path/to/target
Or:
soffice --headless --convert-to pdf /path/to/files/folder --outdir /path/to/target
The format is:
soffice --headless --convert-to <TargetFileExtension>[:NameOfFilter] file_to_convert.xxx
Where:
- filter: specific format of file to convert
- headless: Starts in "headless mode" which allows using the
application without GUI. This special mode can be used
when the application is controlled by external clients
via the API.
Then to "output" the converted files I used this command:
ls -p | grep -v / | xargs -d "\n" soffice --headless --convert-to pdf --outdir /tmp/convert/target 2> /dev/null | grep -Eo "/.*\.doc[x]?"
Info:
ls -p: Append indicators to folders.
grep -v /: Only return files.
xargs -d "\n": Used to pass the output to the soffice command, takes care of white spaces in filenames.
2> /dev/null: Hide errors.
grep -Eo "/.*\.doc[x]?": Return only affected files. And the [x]? catches both .docx and .doc files as used on my end and can be left out.
Let me add an anwser using the example OP gave:
ls *.docx | xargs -d "\n" soffice --headless --convert-to pdf --outdir /tmp/container/target
see: https://ask.libreoffice.org/en/question/2641/convert-to-command-line-parameter/
User soffice --help to see more options to that command.