4

I am trying to create RTF document with tables with empty cells.

I use the com.lowagie.text.rtf.* package in java.

The font of the empty cells are all Times New Roman size 12.

How can I set the font of the empty cells to a different Font?

I have used RtfCell cellSpacer = new RtfCell(new Phrase("", new RtfFont("Arial", 9, RtfFont.NORMAL))); but because the string "" is empty the font doesn't take effect. When the "" is filled with something except a space the font does take effect.

Thank you.

Amedee Van Gasse
  • 7,280
  • 5
  • 55
  • 101
mnish
  • 3,877
  • 12
  • 36
  • 54

2 Answers2

3

A solution to this problem is that the space must be given as a Non Breaking space to the Phrase constructor!

String nbs = "\u00A0";

RtfCell cellSpacer = new RtfCell(new Phrase(nbs, new RtfFont("Arial", 9, RtfFont.NORMAL)));

mnish
  • 3,877
  • 12
  • 36
  • 54
1

I think the issue is this validation on line 198 on Phrase.java, which is called from the constructor Phrase(String string, Font font). Basically, it checks that the string is not empty, otherwise it won't create a chunk containing the text and font you specify.

It seems that you should either:

  1. Pass a space to the constructor:

    new Phrase(" ", new RtfFont("Arial", 9, RtfFont.NORMAL))

  2. Create a new custom class (class AllowsEmptyPhrase extends Phrase), copy the constructors and remove the unwanted behaviour.

Denis Fuenzalida
  • 3,271
  • 1
  • 17
  • 22
  • Thank you for your answer. As you can see in my question I have tried passing a space to the constructor but didn't work. I haven't try to extend the Phrase class, yet. – mnish Mar 17 '13 at 16:30