2

I need your help in applying different font styles to both Paragraph and Chunk in a PDFCell. My code is as below:

BaseFont bf = BaseFont.createFont("c://windows//fonts//arial.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Font font = new Font(bf, 16);
Font welcomeFont = new Font(Font.TIMES_ROMAN, 20,Font.UNDERLINE | Font.BOLD);
Chunk welcomeText = new Chunk("WelCome ", welcomeFont);
PdfPTable table = new PdfPTable(1);
PdfPCell cell =
  new PdfPCell(new Paragraph("\u0625\u0644\u0649 \u0645\u0646 \u064a\u0647\u0645\u0647 \u0627\u0644\u0623\u0645\u0631"+welcomeText,
                                           font));
table.setRunDirection(PdfWriter.RUN_DIRECTION_RTL);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
cell.setBorder(Rectangle.NO_BORDER);
table.addCell(cell);
doc.add(table);

The above code is not applying the different font sizes and styles

99maas
  • 1,239
  • 12
  • 34
  • 59
  • This is a possible duplicate of [C# iTextSharp multi fonts in a single cell](http://stackoverflow.com/questions/21750597/c-sharp-itextsharp-multi-fonts-in-a-single-cell). Granted, that question is about iTextSharp, but the same principle applies. – Bruno Lowagie Jul 24 '15 at 16:08

1 Answers1

4

Add the chunks or phrases to the Paragraph.

Paragraph p = new Paragraph();
p.add(chunk1);
p.add(chunk2);
PdfPCell cell = new PdfPCell(p);

It's also possible (and desirable) to use PdfPCell in composite mode and add the objects directy there.

Paulo Soares
  • 1,896
  • 8
  • 21
  • 19