File can be converted to PDF using GUI but not with cmd

WSL2 Ubuntu 24.04

LibreOffice 24.2.7.2 ee3885777aa7032db5a9b65deec9457448a91162

There are some Word files, if I open them with LibreOffice GUI, click “Export Directly as PDF”, and specify output directory, the conversion works just fine.

If I try to do the exactly thing with cmd, aka.

import subprocess

cmd = [
    'soffice',
    '--headless',
    '--convert-to', 
    'pdf',
    '--outdir', str(file.parent),
    str(file)
]
process = subprocess.run(cmd)

This will suck at the conversion, where ~.lock file and .tmp file both visible but latter not accessible (Permission denied).

FYI, I installed LibreOffice through cmd and manually installed GUI myself. I added GUI just to test if the file itself is corrupt/broken and ideally I don’t want to use GUI by all means. I guess reinstalling LibreOffice with GUI in the first place is the best approach but since I need to make sure this conversion works for my non-graphical servers, I am more inclined to solve it through code/cmd.

Any idea why is this happening? Any help will be appreciated.

assuming your »file« is actually a valid »pathlib.Path«? It works for me … it doesnt matter if the file in question is already opened by whatever instance of Libreoffice

## no need for »--headless« !
run(['soffice', '--convert-to',  'pdf',
     '--outdir', f'{fp.parent}', f'{fp}'])

Could you clarify what does that mean? Given that you mentioned WSL2, could cmd mean Windows’ cmd.exe? is “GUI” different from the LibreOffice installed “through cmd”?

first, try from command line :
soffice --convert-to pdf your.docx

your.pdf should be produced in the same directory as your.docx

Please avoid posting nonsense. The commend puts the result to the current directory, not where you imagine that. --outdir controls that.

1 Like

COMMEND Definition & Meaning - Merriam-Webster :face_with_thermometer:

and to get your (non)sense right, please note “your” doesn’t contain any “/”
yeah, current = “same” for this first diagnostic.

get your common sense back.