Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate RTF from Java?

Tags:

java

xml

xslt

rtf

I work on a web-based tool where we offer customized prints.

Currently we build an XML structure with Java, feed it to the XMLmind XSL-FO Converter along with customized XSL-FO, which then produces an RTF document.

This works fine on simple layouts, but there's some problem areas where I'd like greater control, or where I can't do what I want at all. F.ex: tables in header, footers (e.g., page numbers), columns, having a separate column setup or different page number info on the first page, etc.

Do any of you know of better alternatives, either to XMLmind or to the way we get from data to RTF, i.e., Java-> XML, XML+XSL-> RTF? (The only practical limitation for us is the JVM.)

like image 372
Ingvald Avatar asked Jan 08 '09 12:01

Ingvald


People also ask

How create RTF file in Java?

Following source code shows how to create a Word RTF file using Java. Document rtf = new Document(); DocumentBuilder builder = new DocumentBuilder(rtf); builder. write("hello world"); rtf. save("created_file.

What software creates RTF files?

Because WordPad comes pre-installed on Windows, it's the simplest way to access an RTF file. Other word processors and text editors, such as LibreOffice, OpenOffice, AbiWord, Jarte, AbiWord, WPS Office, and SoftMaker FreeOffice, work similarly.

How do I find the RTF code?

In TextEdit, you can see RTF directives as plain text. An RTF directive is information in a document that formats the contents of the document. In the TextEdit app on your Mac, choose TextEdit > Preferences, then click Open and Save. Select “Display RTF files as RTF code instead of formatted text.”


2 Answers

You can take a look at a new library called jRTF. It allows you to create new RTF documents and to fill RTF templates.

like image 173
Christian Ullenboom Avatar answered Oct 25 '22 08:10

Christian Ullenboom


Have you had a look at the iText library? It's touted primarily as a PDF generator, though it can also generate RTF. I haven't had cause to use it personally, but the general feeling I get is that it's good, and the interface looks comprehensive and easy to work to in the abstract. Whether it would fit in well with your existing data model is another question.

like image 27
Andrzej Doyle Avatar answered Oct 25 '22 08:10

Andrzej Doyle