java 一个 PdfPCell 中的多个短语

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26159478/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 09:24:11  来源:igfitidea点击:

Multiple Phrases in one PdfPCell

javaitext

提问by Lalit Bhudiya

I want to add multiple Phrase in one PdfPCell. My concern is, I want to display like "Created Date :" in gray font and than "Date" in black font in one cell.

我想在一个 PdfPCell 中添加多个 Phrase。我担心的是,我想在一个单元格中以灰色字体显示“创建日期:”,而不是以黑色字体显示“日期”。

So, is there anyway to do this ? Please help.

那么,有没有办法做到这一点?请帮忙。

Code is like,

代码就像,

PdfPCell cell = new PdfPCell(new Phrase("Created Date : ",grayFont));

Now, I want to add Date after that without adding new Cell. Is that possible?

现在,我想在不添加新单元格的情况下添加日期。那可能吗?

回答by Alexis Pigeon

Create a cell, and add as many Phraseas needed :

创建一个单元格,并Phrase根据需要添加多个:

PdfPCell cell = new PdfPCell();
cell.addElement(new Phrase("Created Date : ", grayFont));
cell.addElement(new Phrase(theDate, blackFont));

You could also consider adding Chunkinstead of Phrase.

您也可以考虑添加Chunk而不是Phrase.

回答by specializt

wrap multiple Phrases with different fonts in a Paragraph. Mind you : the Paragraph willcause siblings(not the content, of course) to wrap as long as you dont wrap them as well

Paragraph中用不同的字体包装多个Phrase。请注意:段落导致兄弟姐妹(当然不是内容)包装,只要你不包装它们

回答by Yogesh Prajapati

Use

利用

Phrase datePhrase = new Phrase(new Chunk("Created Date", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, BaseColor.GRAY)));
datePhrase.add(new Phrase(new Chunk("Your Date", FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD, BaseColor.BLACK))));
PdfPCell cell = new PdfPCell(datePhrase);