Table cell font in RTF with lowagie document

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

I am using the com.lowagie.text.rtf.* Package in java.

font for empty cells - all Times New Roman size 12.

How to set the font of empty cells to another font ?

I used RtfCell cellSpacer = new RtfCell(new Phrase("", new RtfFont("Arial", 9, RtfFont.NORMAL))); , but since the string "" empty, the font does not take effect. When "" filled with something other than space , the font takes effect.

Thanks.

+4
source share
2 answers

The solution to this problem is that the space should be defined as disjoint space for the Phrase constructor!

String nbs = "\u00A0";

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

+3
source

I think the problem is checking in line 198 on Phrase.java , which is called from the Phrase(String string, Font font) constructor Phrase(String string, Font font) . Basically, it checks that the string is not empty, otherwise it will not create a piece containing the specified text and font.

It seems that you should:

  • Pass a space to the constructor:

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

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

+1
source

Source: https://habr.com/ru/post/1469016/


All Articles