I'm trying to build a bash script in Cygwin that will convert HTML files to RTF. In OS X this is trivial with textutils, but that doesn't exist for regular Linux or Cygwin. Instead I'm trying to use OpenOffice from the command line.

I've read elsewhere that OpenOffice can run headlessly with a program normally installed as /usr/bin/ooffice, but in Cygwin under Windows this obviously doesn't work—the OpenOffice installer doesn't built native Cygwin symlinks and might not even install the Windows equivalent of ooffice.

How can I use OpenOffice from the command line in Cygwin to convert HTML files to RTF files?


There is a really handy shell script called unoconv that handles conversion of any files from and to any file format that OpenOffice/LibreOffice supports. You can read up about it on its site and be sure to check out the man page. Many distros have packages for it that you can install easily, including, I believe, cygwin.

Once you have it installed, usage in your case would mean specifying an input html file and an output rtf file like this:

unoconv file.html file.rtf

All done :)

Of course this could be scripted to handle multiple file situations as well. If you are using zsh, you could run something like this to convert a whole folder of html files:

for file in *html; do
    unoconv "$file" "${file/html/rtf}"
  • @Andrew I hope you find it useful, but it's not exactly new. The project's git repository dates back to 2007, and that was an import from some over version control system that they migrated from. – Caleb Sep 24 '12 at 7:31
  • Hmm. I missed that when looking. I assumed that it was new since it mentioned working with zero configuration on OS X on LO 3.6.x, which just came out recently. Regardless, it's awesome :) – Andrew Sep 25 '12 at 2:52

I would suggest the JODConverter. It is a java wrapper around the OpenDoc Api for conversion. Allows you to convert files like this:

java -jar jodconverter-cli-2.2.0.jar foo.html foo.rtf

It's also available in python.

instead of using the openoffice SDK DocumentSaver class like this:

java -classpath .;./bin;\
                $OO/program/classes/juh.jar  \
    DocumentSaver uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager  file:///C:/test/foo.html file:///C:/test/foo.rtf
  • 1
    I went ahead with a variation of this. At first I went with Python and kept OpenOffice running as a background server, but then I found Pyth (pypi.python.org/pypi/pyth) a purely Python-based converter. It's minimalistic, but it works great. – Andrew Aug 9 '10 at 21:02
  • Are you still required to actually install OOo, or do the "wrapper" libraries include everything needed? I see no explicit mention. Thanks. – humble_coder Sep 19 '11 at 16:01

I can help with the first part of your question. Here's an example of running OpenOffice from the Cygwin command line:

/cygdrive/c/Program\ Files/OpenOffice.org\ 3/program/soffice.exe -help

That will give you a list of command line arguments. I didn't see any that would convert file types or even "Save As", but I didn't research the API. Perhaps you can fill in that part. I have OpenOffice.org 3.2 320m12(Build:9483).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.