Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libreoffice convert-to not working

Tags:

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]
like image 805
casper123 Avatar asked Feb 27 '14 08:02

casper123


People also ask

How do you convert to LibreOffice?

LibreOffice has a built-in document converter that makes it easy to convert various file types to the Open Document Type file (. odt) format that both OpenOffice and LibreOffice use. We'll use this converter to convert our Word file into LibreOffice format. Click on File > Wizards > Document Converter.

Can LibreOffice Convert PDF to Word?

No, LibreOffice will not convert a PDF to a DOC (or ODT) or so. What you can do is that if you create a Writer document (ODT or DOC), from it you can create a PDF that embeds the source file. Therefore from that PDF you should be able to go back to the DOC (or better the ODT).

What is Soffice command?

If you installed using the download on the Apache OpenOffice website, you can start Writer by typing at the command line: soffice -writer. or. swriter. Writer will start and create a new document.

What is LibreOffice headless?

The solution is the --headless option, which executes LibreOffice processes without launching the graphical user interface. For example, converting a document to EPUB is a pretty simple task in LibreOffice—but it's even easier with the libreoffice command: $ libreoffice --headless --convert-to epub example.odt.

How to convert a LibreOffice document to another file?

It is even simpler to use the built-in LibreOffice Document converter Assistant. You can start it by navigating the menus: File ▸ Wizards ▸ Document Converter Note that a user has previously reported that he had to divide his files into bunches of 200 because the process sometimes crashed. The long description of the problem

Why is the LibreOffice GUI command not working?

Next, the command will not work if there is already a LibreOffice GUI instance up and running on your system. It is caused by bug known since 2011. Add this additional parameter to your command: "-env:UserInstallation=file:///tmp/LibreOffice_Conversion_$ {USER}"

Why can't Libreoffice Open *Doc* files?

Thisis what LibreOffice sees. Windows' cmd.exe does not do that, and sends the path/to/*.docto LibreOffice unmodified. LibreOffice simply tries to open the file named *.doc, and fails. That's all.

Why doesn't LibreOffice--convert-to work with wildcards?

It's simply that LibreOffice's --convert-toin fact does not support using wildcardsitself, and only works on non-Windows systems because they process the wildcards in their shells (and of course, these shells also work on Windows, like with Cygwin or WSL). What does this mean?


3 Answers

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

like image 160
Frank Yin Avatar answered Oct 26 '22 21:10

Frank Yin


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.

like image 41
Dmitri Chubarov Avatar answered Oct 26 '22 19:10

Dmitri Chubarov


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.

like image 32
Arnon Weinberg Avatar answered Oct 26 '22 19:10

Arnon Weinberg