Is there an easy way to format an RTF file in code?

I am trying to have a method output an RTF file with simple formatting (italic, bold and so on). I know how to do this in HTML, but RTF seems quite hard to code. Is there an easy way to do that in Servoy?

Hi rioba

I’m doing my own plugins to make rtf reports with itext & rtf.
It’s very symple and powerful.

Best regards. Roberto Blasco.

Are you going to comercialize those plugins?

Hi jasantana

The plugin will be for free when finished. I want to add more features :-)

Best regards. Roberto Blasco.

Hi Roberto!
You know you are welcome on ServoyForge, don’t you? :)

I ptalbot.

Let me write some more code and I will publish it in ServoyForge :D

Best regards. Roberto Blasco.

PS
I’ve still to finish the pdf digital signature plugin … :oops:

You know you don’t have to polish your code to a beautifully finite state (if there is such a thing!).
You can also have others contribute/help if you publish early.

Adopt the Agile mantra: release early, realease often…

Ok, I’m going to prepare the code to publish it :-)

Hi Roberto,

very good news. I am looking forward to your plugin. I am sure it will be much appreciated by everybody. Unfortunately I won’t be able to contribute code (java is not my cup of tea).

Roberto Blasco:
Ok, I’m going to prepare the code to publish it :-)

Hi Roberto,

any news about your rtf-plugin?

I’m looking for an easy way to format plain text to rtf for reports.

Regards,

Hi tgs.

I’m still working in the plugin to generate rtf reports from easy xml templates + xml data.

As soon as I can, I’ll post the link in this forum. :D

Anyway, here you are a piece of code to generate a simple rtf doc from java in a few lines (I’m using iText to create the plugin)

import java.io.FileOutputStream;
import java.io.IOException;

import com.lowagie.text.Anchor;
import com.lowagie.text.Chunk;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Paragraph;
import com.lowagie.text.html.HtmlWriter;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.rtf.RtfWriter2;

public class HelloMultipleWorld {

  public static void main(String[] args) {

  System.out.println("Hello World in PDF, RTF and HTML");

  
  Document document = new Document();
  try {
  
  PdfWriter pdf = PdfWriter.getInstance(document,
  new FileOutputStream("differentWritersdPdf.pdf"));
  RtfWriter2 rtf = RtfWriter2.getInstance(document,
  new FileOutputStream("differentWritersRtf.rtf"));
  HtmlWriter html = HtmlWriter.getInstance(document,
  new FileOutputStream("differentWritersdHtml.html"));

  
  document.open();
  
  document.add(new Paragraph("Hello World"));
  
  Anchor pdfRef = new Anchor("see Hello World in PDF.");
  pdfRef.setReference("./HelloWorldPdf.pdf");
  Anchor rtfRef = new Anchor("see Hello World in RTF.");
  rtfRef.setReference("./HelloWorldRtf.rtf");
  
  
  
  pdf.pause();
  rtf.pause();
  document.add(pdfRef);
  document.add(Chunk.NEWLINE);
  document.add(rtfRef);
  pdf.resume();
  rtf.resume();
  
  } catch (DocumentException de) {
  System.err.println(de.getMessage());
  } catch (IOException ioe) {
  System.err.println(ioe.getMessage());
  }

  
  document.close();
  }
}

Best regards. Roberto Blasco.