问题描述
我正在设计一个使用itext库的pdf报告。我已经实现了一个段落。现在按照我的要求,我必须在背景颜色的矩形框内设置这个段落,但我不能这样做。这是我在Java中的Itext代码...
字体f =新的字体(FontFamily.TIMES_ROMAN,25.0f,Font.BOLD,BaseColor.CYAN);
段落p =新段落(总费用:+ dbsumcallcost,f);
document.add(p);
请大家帮帮我。
在此先感谢..
您需要一个 Chunk
要做到这一点:
Font f = new Font(FontFamily.TIMES_ROMAN,25.0f,Font.BOLD,BaseColor.WHITE) ;
大块c =新大块(总成本:+ dbsumcallcost,f);
c.setBackground(BaseColor.RED);
第p段=新增段落(c);
document.add(p);
请参阅示例和 。
您可以使用稍微不同的 setBackground()
方法来微调矩形:
I am designing a pdf report using itext library.I have implemented a paragraph in it.Now as per my requirement i have to set this paragraph inside rectangular box with background color but i am not able to do it..
Here is my Itext code in java...
Font f = new Font(FontFamily.TIMES_ROMAN, 25.0f, Font.BOLD, BaseColor.CYAN);
Paragraph p = new Paragraph("Total Cost:" + dbsumcallcost, f);
document.add(p);
Please guys help me.Thanks in advance..
You need a Chunk
to do that:
Font f = new Font(FontFamily.TIMES_ROMAN, 25.0f, Font.BOLD, BaseColor.WHITE);
Chunk c = new Chunk("Total Cost:" + dbsumcallcost, f);
c.setBackground(BaseColor.RED);
Paragraph p = new Paragraph(c);
document.add(p);
See the ChunkBackground example and the resulting PDF document.
You can fine-tune the rectangle by using a slightly different setBackground()
method: http://api.itextpdf.com/itext/com/itextpdf/text/Chunk.html#setBackground%28com.itextpdf.text.BaseColor,%20float,%20float,%20float,%20float%29
这篇关于如何在Java中将itext pdf文件的段落设置为带有背景色的矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!