23

I'm trying to convert documents from html,txt to pdf,odt and vice versa.. But only odt to pdf seems to work.. No other file formats are converted

Here are my commands

libreoffice --headless --convert-to pdf test.html [Not working]
libreoffice --headless --convert-to odt test.html [Not working]
libreoffice --headless --convert-to pdf test.docx [Not working]
libreoffice --headless --convert-to pdf test.odt  [Working]
Braiam
  • 1
  • 11
  • 47
  • 78
casper123
  • 1,736
  • 4
  • 21
  • 39
  • 1
    Please add the version number of libreoffice you are using. – z-- Mar 06 '14 at 14:45
  • I've read in other places that `--headless` must come after `--convert-to` (but I'm still struggling to get this to work) – Ronnie Overby Apr 02 '15 at 12:01
  • 1
    @RonnieOverby since version 4.5 [`--convert-to` implies `--headless`](http://unix.stackexchange.com/a/354054/44425) so you don't need to specify it anymore – phuclv Mar 28 '17 at 05:38

10 Answers10

30

Try closing all running instances of LibreOffice before executing the command. This was the root cause of my pain.

Frank Yin
  • 1,920
  • 1
  • 17
  • 12
  • I am facing same issue, how to close all running instances of LO?. – Satishakumar Awati Sep 29 '15 at 18:21
  • In my case, I had the LibreOffice app open on my Mac, so simply select Quit from the UI menu. Alternatively, you could look up the process on whatever system you're on and kill it that way. – Frank Yin Oct 16 '15 at 18:30
  • 3
    With the UI running, convert-to just returned without doing anything (no error message, no output). Closing all instances at least got me to the next error message... – chooks Dec 30 '15 at 13:37
  • I would upvote this three times if I could… Ok, so command-line LibreOffice can have a different behaviour than expected, but no warning at all, if another instance is running… Good to know! – Clément Jan 03 '17 at 17:45
  • Same problem on Linux Mint 18.1 (Ubuntu 16.40), and solved by killing all running libreoffice instances. – TurtleIzzy Mar 30 '17 at 11:25
  • 1
    Same here, still a problem. Having running instance makes it do nothing – Siim Kallari May 21 '18 at 11:01
18

This is a known issue in LibreOffice that was fixed in version 5.3.0. Before this fix when an instance of LibreOffice is running --convert-to or any other command would silently terminate without doing anything.

If your version is older than that you could consider the solution suggested by Frank Yin here. That is close all open LibreOffice documents before running the conversion.

If you cannot close all open LibreOffice documents to run the conversion, or if you find it inconvenient, you could try a solution suggested in the comments to the original bug.

If you have LibreOffice version before 4.5 run

soffice -env:UserInstallation=file:///$HOME/.libreoffice-headless/ \
--headless --convert-to pdf test.docx

If you are running LibreOffice version between 4.5 and 5.3 run

soffice -env:UserInstallation=file:///$HOME/.libreoffice-headless/ \
--convert-to pdf test.docx

Here $HOME/.libreoffice-headless is a new profile directory different from your main LibreOffice profile.

Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
  • 2
    I could kiss you right now xD You just solved a severe issue that raised up in production from apparently nowehere several hours ago. Probably some intern made a headless apt upgrade or so..., our Tomcat server just stopped converting PDF silently. It knew it failed because no file was created, but other than that "lowritter" was totally silent. – DGoiko Jan 16 '19 at 11:57
  • i have tried soffice --headless -env:UserInstallation=file:///$HOME/.libreoffice-headless/ \ --convert-to pdf sample.txt Its generating .lock file but no output getting generated after so much time, i am trying this on libreoffice 4.3.7.2 On Cent OS 6.10 – Jay Acharya May 06 '19 at 05:35
  • Could you please explain this solution more. – rahim.nagori Jul 28 '20 at 10:16
  • WOW I have been researching this for hours and this was the fix. Thank you!! – Mr. T Sep 13 '21 at 05:25
11

The real problem is that the libreoffice/soffice command line doesn't provide any error message or debugging information, so it's all guesswork. If you are up to it, then try strace for hints.

In my case (Linux), I didn't have the correct packages installed - for example, to convert spreadsheets, libreoffice-calc is needed (duh), and also libreoffice-headless (double-duh). But the command line won't tell you that - it just hangs, or runs and doesn't do anything.

Arnon Weinberg
  • 871
  • 8
  • 20
  • 4
    Same here with Ubuntu 14.04: Did install libreoffice-common without libreoffice-writer, because I didn't knwo about it yet, and things didn't work, saw libreoffice-writer by chance, installed that, -common is a dependency, and the conversion worked immediately. How do LibreOffice-devs work without any logs? :-) – Thorsten Schöning Nov 04 '15 at 14:48
  • 1
    This fixed it for me too. I was missing package dependencies. Specifically `libobasis6.1-en-US` and `libobasis6.1-writer`. – aNoble Sep 07 '18 at 00:29
7

The following works

libreoffice  --invisible -convert-to pdf myFile.html

libreoffice --invisible -convert-to docx myFile.odt

The option --invisible does not start up the GUI but gives some clues on the command line what is happening.

Tested on Linux Mint 13.

z--
  • 2,186
  • 17
  • 33
2

This worked for me on LibreOffice 4.2 / Linux:

soffice --headless --convert-to txt:Text /path_to/document_to_convert.odt

Credit: http://ask.libreoffice.org/en/question/14130/how-do-i-install-filters-for-the-soffice-command/

markling
  • 1,232
  • 1
  • 15
  • 28
2

For me. The problem I had was that --headless does not work, AT ALL (just returns in 15 milli-seconds), if a local libreoffice process already has the document open.

Make sure you only do headless operations on a document that is NOT already open in LibreOffice.

Wayne Walker
  • 2,316
  • 3
  • 23
  • 25
1

For me, the following two packages were the minimum needed to get headless docx to pdf conversion working on CentOS 7 :

yum install libreoffice-headless  libreoffice-writer
CompuLingus
  • 161
  • 1
  • 3
0

One of the problems that I encountered with libreoffice was the problem with empty spaces. After I slugged the name ("test-document.docx" instead of test "documnet.docx") it worked perfectly. From version 4.2.8.2 - 5.3.

Maky
  • 521
  • 5
  • 21
0

On Windows I encountered the following problem: I tried to convert all DOC files to PDF using the following command:

soffice --invisible --convert-to pdf *.doc

It failed without any error message. But it worked when I put a filename of one of the files instead of *.doc. So apparently it was a problem with resolving wildcard in *.doc. What I did is execute exactly the same command as above but from Git Bash instead of normal command prompt (cmd.exe). It worked. What is more: in Git Bash it displayed progress information and informative messages!

So my advice is: if you're running soffice.exe on Windows and don't get any output, run the command from Git Bash (you can get Git Bash by installing Git for Windows)

JustAC0der
  • 2,871
  • 3
  • 32
  • 35
-1

I had to install the xvfb package (yum install xorg-x11-server-Xvfb), it is the xserver dummy.

Julian
  • 33,915
  • 22
  • 119
  • 174