简体   繁体   中英

Multiple Phrases in one PdfPCell

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.

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?

Create a cell, and add as many Phrase as needed :

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

You could also consider adding Chunk instead of Phrase .

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

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM