# convert-to command line parameter

Anonymous

Hello, I'm trying to convert a Microsoft Word document to text using the convert-to command-line parameter using LibreOffice 3.4.5, OOO340m1 (Build:1505), on OpenSuse 12.1. I tried these two commands.

soffice --convert-to txt filename.doc


Nothing happened.

soffice --headless --convert-to txt filename.doc


Produced a PDF file.

Why do I need --headless? If this is mandatory, the documentation should state this. Can LibreOffice convert Word Perfect documents?

The format for "convert-to" parameter is:

--convert-to output_file_extension[:output_filter_name] [--outdir output_dir]


What are the valid output_file_extension values? What are the valid output_filter_name values?

For the documentation, the soffice --help showed the --convert-to parameter. The help->LibreOffice Help does not show this parameter.

Thank you

edit retag close merge delete

Sort by » oldest newest most voted

Here are a few more pointers for anybody else struggling with this.

This is the general format of convert-to (noting that on windows the parameter is -convert-to not --convert-to):

soffice --headless --convert-to <TargetFileExtension>:<NameOfFilter> file_to_convert.xxx


Use the link above (http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/config/fragments/filters) to look for the filter names in the .xcu files.

For example, I wanted to convert to Excel 95 format so I found the MS_Excel_95.xcu filter and inside it has a name:

<node oor:name="MS Excel 95" oor:op="replace">
...


I could then try it out:

soffice --headless --convert-to xls:"MS Excel 95" filename.xlsx


(I needed this to get a non-xml version of an excel file)

more

for me --headless worked only when given after --convert-to.

soffice --convert-to pdf filename.doc  --headless


works while

soffice  --headless --convert-to pdf filename.doc


does not.

( 2015-01-12 08:08:33 +0200 )edit

Running on CentOS 6.5 with LibreOffice 4.0.4 and logging in only via ssh onto a server with no display whatsoever (ie, serial console), I get an error X11 error: Can't open display: which is what I would expect --headless to prevent. I needed to prefix the command with /usr/bin/xvfb-run. It doesn't matter where in the command string I put --headless.

( 2015-05-26 18:12:13 +0200 )edit

How do you set the range of pages?

( 2016-05-21 11:32:12 +0200 )edit
1

Since long time, under Windows correct syntax is also --convert-to (with two dashes). Headless is now implied for --convert-to, and it's completely not necessary to use it explicitly here.

( 2017-02-19 16:09:19 +0200 )edit

Im getting error while executing command soffice

## LibreOffice 5.2 - Fatal Error

The application cannot be started. [context="user"] caught unexpected com.sun.star.ucb.ContentCreationException: Cannot create folder (invalid path): C:

( 2018-01-04 08:38:19 +0200 )edit

--headless is not strictly mandatory, but you want it.
Without it, the document is still converted (note "convert /.../filename.doc -> /.../filename.txt using text" message on stdout) but an empty GUI is also started (and the command blocks until you close the GUI).

More importantly, headless conversion silently does nothing if any LO is already open; see http://ask.libreoffice.org/en/question/1686 for a solution.

more

1

Thanks, that is a useful caveat about headless conversion only working when no other LOis open, by default. Sure explains why I had trouble before; now I am using the -env trick.

( 2013-07-24 20:31:28 +0200 )edit
1

Headless is now implied for --convert-to, and it's completely not necessary to use it explicitly here.

( 2017-02-19 16:09:25 +0200 )edit

Having another instance open in a minimized window on another desktop had me baffled for an hour :-) It really ought to issue a warning to stderr about this.

( 2018-03-15 16:51:16 +0200 )edit

Probably --convert-to should imply --headless, but if you want this, please open a bugreport.

Regarding the filters available, you can poke around at http://cgit.freedesktop.org/libreoffice/core/tree/filter/source/config/fragments/filters (sure, a more user-friendly wiki page would be better), for example if you want to convert to odt, try '--convert-to odt:writer8'.

more

This syntax worked for LO 3.4.6

soffice --headless --convert-to txt:text file_to_convert.doc


But only if no other instances of LO are open.

more

For windows machines, I have found that on some files the conversion needs a start /wait. Example

start /wait soffice --headless --convert-to txt file_to_convert.doc


It seems the shell collapses before soffice can complete the conversion is some cases.

more

Thank you for this - on Windows 7 I was getting unhelpful crash dialogs until I added the "start /wait" to the command. As a note the first quoted parameter for 'start' is the window name, so if you try to call the above from a script with a space in the path you may need to do it like: start /wait "" "C:\program files\libreoffice 4\program\soffice"

( 2014-12-10 01:03:35 +0200 )edit

One more addendum: It is possible to read - for example here: http://www.computerhope.com/starthlp.htm , www.microsoft.com is silent about that - that “When executing an application that is a 32-bit GUI application, CMD.EXE does not wait for the application to terminate before returning to the command prompt. This new behavior does NOT occur if executing within a command script.”; so it should imply that when executing soffice.exe from a batch script,

( 2015-05-20 19:24:34 +0200 )edit

[continued] it is not necessary to call it via start /wait command. Unfortunately, it is NOT true. At least on Windows Vista (I know, horrible OS - but it was not on my computer) it is necessary to use start /wait even in a batch, otherwise the conversion collapses. Update: Primary source for the incorrect information about the start command (Microsoft's site). LO version: 4.3.6.

( 2015-05-20 19:27:27 +0200 )edit

Been testing with 5.0 64bit and found the --outdir cannot be quotes. Example good: --outdir c:\temp bad: --outdir "c:\temp"

( 2015-09-08 18:13:54 +0200 )edit

If you are still having problems I would recommend using the portable version of LO: download page

( 2015-09-08 20:22:25 +0200 )edit

Combining all the info given in this page, the following code allowed me to batch convert ppt files using LO in Windows 7:

for %f in (*.ppt) do (
start /wait "" "C:\Program Files\LibreOffice 4\program\soffice.exe" --headless --convert-to pdf --outdir C:\tmp %f
)


(Got a lot of errors before I found that an empty quote was required if the path contain spaces)

( 2015-10-11 00:19:05 +0200 )edit

For anyone trying to do this in powerscript, you can use link:this workaround to get powershell to wait for the conversion process to finish:

My code looked like this:

soffice --headless --invisible --convert-to html:HTML $filename --outdir$outputDir | Out-Null

( 2018-06-21 20:38:16 +0200 )edit

On win7, using LO 4.1 I had to do the following (from command line, you probably need to change %f to %%f if running in a cmd script):

set path=%path%;C:\Program Files (x86)\LibreOffice 4\program
for %f in (*.odg) do (
soffice.exe --headless --convert-to pdf --outdir "C:\tmp" %f
)


Notes:

• it will NOT work if any instance of LO is open!
• outdir IS required
• wildcards for input files are NOT supported (hence the for loop)
more

Thank you very much.

Just a few notes for WIN7 x64 LO 4.1.1.2 build ID 7e4286b58adc75a14f6d83f53a03b6c11fa2903

• outdir IS NOT reqired (strange?)
• NOT AT ALL instances of LO are opend, even LO Quick Start

Bear in mind to disable loading LO quick start on operating system startup. Otherwise it will be loaded on first convert and nothing will be coverted after it.

( 2013-09-16 14:03:26 +0200 )edit

Couple of noob questions incoming. 1. that is two separate commands? 2. the first command, that looks like it is telling windows where to look for soffice.exe, or is it also looking for the files you want to convert? 3. Do I need to have command prompt open to the directory the files are in for this to work, I am guessing so. 4. If this is all entered in at the same time, do I need to separate the commands in any way?

( 2014-07-23 20:58:27 +0200 )edit

FWIW: 1. Yes. 2. IMO, setting the path concerns executable files only (but I am not an guru for MS-DOS/Windows shell) 3. Yes (as an implication of 2.) 4. Very probably yes but I can't tell you how - MS-DOS shell manual should say more. But executing at first the set command and afterwards the for command solves the situation in any case (the path you set is definitely valid at least until the command prompt session terminates). Or you can create a .bat file and separate commands by newline.

( 2015-05-20 19:48:08 +0200 )edit

P.S. In a .bat file (script) you need to change %f to %%f.

( 2015-05-20 19:58:30 +0200 )edit

@w_whalley's answser was close, but didn't work for my version: LibreOffice 4.2.8.2

This worked:

soffice --headless --convert-to txt:"Text" file_to_convert.odt


(I happened to do it with an odt. haven't tried .doc yet).

(thanks to: @quibit here: http://ask.libreoffice.org/en/questio... )

more

Hallo,

I tried multiple things with LibreOffice 4.2.8.2-11.el6_7 (my company's default version).

This one worked for me to convert calc file in .ods format to HTML:

 libreoffice --headless -env:UserInstallation=file://${tmp} --convert-to html${myfile}


--outdir was not required in my experiments, but it works if you use it.

The --convert-to command does not work for password-protected files, and there seems to be no option to pass a password. It simply fails silently with no hint to the user what went wrong. There are some other interesting commandline options, depending on your local env and requirements.

--norestore    suppress restart/restore after fatal errors.
--quickstart   starts the quickstart service
--nologo       don't show startup screen.
--nolockcheck  don't check for remote instances using the installation


It did not work for me to explicitly write the filter as html:HTML. This resulted in the error message

Error: Please reverify input parameters...

more

Thank you, that simpler command
soffice --headless --convert-to html --outdir ./ input.odt
also worked for me.

But these did too:
... html:HTML ....
... htm:HTML ....
... htm ....

and all gave during conversion:
convert /home/user/Desktop/input.odt -> /home/user/Desktop//input.htm using HTML (StarWriter)

Only "htm:HTM" failed, with
convert ... using HTM

( 2017-04-03 00:08:38 +0200 )edit

I'm using LibreOffice Version: 4.3.7.2, running on Ubuntu 14.10. Using the above and other questions and answers I've gotten the following command to work. The headless option is discussed above. The env parameter allows the command to run even if libreoffice is already running.

soffice -env:UserInstallation=file:///tmp/tempprofile --headless --convert-to csv FileName

I do have an additional problem. The spreadsheets I'm converting to csv have a libreoffice basic function. When I use the GUI to convert to csv, the values as displayed go into the csv file. When I use the command line, all I get is #VALUE!.

Is there a way to get the correct, calculated value, into the csv file?