9

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.)

Ingvald
  • 443
  • 1
  • 4
  • 12
  • Both Aspose.Words and iText looks promising after a quick look. I might test both of them when I've got the time... – Ingvald Jan 14 '09 at 19:20
  • 1
    In the end we went with Aspose, using templates, giving us good control over format and style – Ingvald Jul 15 '10 at 14:12

5 Answers5

8

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

Buhake Sindi
  • 87,898
  • 29
  • 167
  • 228
Christian Ullenboom
  • 1,388
  • 3
  • 24
  • 20
  • Thanks! Interesting, even if it seems to lack a few things that I need. (Ref "What's not supported" in http://code.google.com/p/jrtf/ - nice table handling, gifs, good style/formatting control) – Ingvald Jul 15 '10 at 14:02
4

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.

Andrzej Doyle
  • 102,507
  • 33
  • 189
  • 228
  • 2
    did itext stop supporting rtf? On their homepage I can't find anything about RTF - only PDF! – räph Jul 23 '10 at 07:52
2

If you could afford spending some money, you could use Aspose.Words, a professional library for creating Word and RTF documents for Java and .NET.

splattne
  • 102,760
  • 52
  • 202
  • 249
  • 1
    Thanks for the tip - it doesn't have to be free. After all, you have to spend money (cash or time) to earn money... – Ingvald Jan 09 '09 at 10:20
0
import com.lowagie.text.*;
import com.lowagie.text.html.simpleparser.HTMLWorker;
import com.lowagie.text.html.simpleparser.StyleSheet;
import com.lowagie.text.rtf.*;

import java.io.*;
import java.util.ArrayList;

public class HTMLtoRTF {
    public static void main(String[] args) throws DocumentException {
        Document document = new Document();

        try {
            Reader htmlreader = new BufferedReader((new InputStreamReader((new FileInputStream("C:\\Users\\asrikantan\\Desktop\\sample.htm")))));

            RtfWriter2 rtfWriter = RtfWriter2.getInstance(document, new FileOutputStream(("C:\\Users\\asrikantan\\Desktop\\sample12.rtf")));
            document.open();
            document.add(new Paragraph("Testing simple paragraph addition."));
            //ByteArrayOutputStream out = new ByteArrayOutputStream();

            StyleSheet styles = new StyleSheet();
            styles.loadTagStyle("body", "font", "Bitstream Vera Sans");
            ArrayList htmlParser = HTMLWorker.parseToList(htmlreader, styles);
            //fetch HTML line by line

            for (int htmlDatacntr = 0; htmlDatacntr < htmlParser.size(); htmlDatacntr++) {
                Element htmlDataElement = (Element) htmlParser.get(htmlDatacntr);
                document.add((htmlDataElement));
            }
            htmlreader.close();
            document.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
  • Your answer seems interesting, care to add some comments? How does it works? Maybe a link with some working project? – Yaroslav Oct 11 '12 at 06:50
  • This (http://stackoverflow.com/questions/13515210/difference-between-lowagie-and-itext) at least anwser who or what is lowagie – mkdev Oct 10 '14 at 10:59
0

iText supports RTF.

joel.neely
  • 30,725
  • 9
  • 56
  • 64