Create ODF documents without OpenOffice.org

While you can create and save documents in the OpenDocument format using OpenOffice.org, KWord, or AbiWord, there are other ways to generate ODF files. odtwriter, for example, can help you to quickly convert plain text files formatted using reStructured Text markup into odt (OpenOffice.org Writer-compatible ODF) documents. You might wonder why you’d want to create ODF documents this way, but odtwriter does offer a few important advantages:

  • odtwriter is part of docutils, a set of tools for converting plain text files into other formats such as HTML, XML, and LaTeX. This means that you can output the formatted text file into other formats besides ODF. This is a more efficient approach than creating an odt document in Writer and then jump through hoops to turn it into, for example, a clean HTML file.
  • Using odtwriter, you can generate ODF files on machines that don’t have OpenOffice.org or other ODF-compatible word processors installed (e.g. you are running a lightweight Linux distro).
  • You can use whatever text editor you like as your distraction-free writing environment, leaving the task of producing the properly formatted document to odtwriter.
  • odtwriter has a few features that are not available in OpenOffice.org. For example, OpenOffice.org doesn’t support syntax highlighting, so making code blocks in a Writer document more legible and pretty is a non-trivial task. odfwriter, in turn, can apply syntax highlighting to the code blocks in the final odt document.

The main drawback of using odtwriter to produce ODF documents is that you need to learn a new markup language. This is, however, not as bad as it might sound. Markup used in reStructured Text looks a lot like wiki markup, so you can pick up the basics in no time. The markup is also well-documented, with reStrecutured Text Primer, Quick Reference, and a cheat sheet available for your reading pleasure.

To make odtwriter work on your machine, you have to install two packages: docutils and pygments. The latter is required only if you want the syntax highlighting functionality. On Ubuntu, installing both packages is as easy as running the sudo apt-get install python-docutils python-pygments command. To install odtwriter, download its latest release, unpack it, and run the following commands:

python setup.py build
sudo python setup.py install

Using odtwriter is equally straightforward: the rst2odt.py command converts the specified source text file into an odt document:

rst2odt.py text.txt document.odt

Like any command-line tool, odtwriter supports flags; and at least two of them can come in rather handy. By default, the syntax highlight feature in odtwriter is disabled, and you need to use the –add-syntax-highlighting flag to turn it on:

rst2odt.py --add-syntax-highlighting text.txt document.odt

This applies Python syntax highlighting to the code blocks (marked as literal blocks) in the source text. For code blocks in other programming languages, you have to add so-called directives to the source text that activate alternative language (or lexer) highlighting:

.. sourcecode:: on
.. sourcecode:: Java

Since odtwriter relies on Pygments for syntax highlighting, you can use any language supported by this software. You can find a list of all supported languages and their short names on the Pygments Web site.

Related articles:

Create ODF documents without OpenOffice.org 2009/03/14 16:24 Dmitri Popov

AddThis Social Bookmark Button

 
articles/odfwriter.txt · Last modified: 2010/03/10 19:45 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Need high-quality compatible Avery labels? Get them at WorldLabel.
Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki