Convert docx to pdf via the commandline on Windows 10

I know this has been asked over and over… but I just can’t get it to work, no matter what recommended method I’ve tried. I’d like to convert a docx to a pdf via the command-line on windows 10.

This is what I’m punching into the cmd as a test:

soffice.exe --headless --convert-to pdf --outdir "C:\tmp" "ABCD.docx" 

I’m executing this from …\LibreOffice\program, and ABCD.docx is indeed in that folder. No output, nada. Is there a way to perhaps enable more verbose output so I can debug what I’m doing wrong?

Any help or pointers in the right direction would be greatly appreciated :slight_smile: I know there are several other ways to perform this task via the command-line, but they all involve the MS Suite being installed, which I’d like to avoid.

Version: 7.1.3.2 (x64) / LibreOffice Community

I’m executing this from …\OpenOffice4\program\

OpenOffice4? Which program do you use?

A hint: Apache OpenOffice (completely separate project, not covered by this Ask site which is about LibreOffice) does not use arguments starting with two dashes. It uses older single-dashed arguments, like -convert-to.

Oops, should be LibreOffice\program

Also what version of LibreOffice do you use? You didn’t include version info from Help|About.

Updated, thank-you for putting up with my ineptitude!

Starting from v.6.3, you should not use soffice.exe when working in terminal. You better just omit the extension (like soffice), or explicitly use soffice.com, to use a version specifically created for console, which would output the errors, if any, to the console, instead of silently discarding any output. Also note that you should make sure that LibreOffice is not running in the background when you are launching the command line, because otherwise your command would be redirected to the existing GUI process, and you may again not see the error messages.

Alternatively, specify a separate user profile when calling command line to allow separate processes - see -env command line parameter.

Ah thank-you! That fixed it, I thought I’d never figure this one out. Much appreciated, you saved me a lot of hassle :slight_smile:

Then please consider posting an answer here, stating what was the change that you needed to do to your command, so that the question and its answer could help others. Thanks!

Is there a way to perhaps enable more verbose output so I can debug what I’m doing wrong?

Answering this part of the question.

Starting with LibreOffice 6.3, there is now a proper console mode on Windows, which does not have the problems printing to console. To use the console mode, you should not use soffice.exe when using CLI, but instead use soffice.com, or simply omit the extension at all and use soffice in your command line (provided that your configuration of the command processor first searches for .com before trying .exe, which is the default for cmd.exe on Windows - see PATHEXT environment variable).

Also make sure that your launched process does not use the same user profile as any running instance of LibreOffice. If you do not set a dedicated user profile explicitly, by default your launched process would attempt to use the default user profile (%APPDATA%\LibreOffice\4\user), and if you have LibreOffice GUI running in parallel, the CLI process will pass the command to the GUI; so any errors in the process would happen in the GUI instance, and you may not see the output in the console. Either make sure that LibreOffice is not running, or specify a separate user profile - see -env command line parameter.

This would make sure that the output from the command will appear in your console, and not be silently discarded.