0

Please can you give an advise to make part of the text to make the bold in my code given below. How to make Bold he text 'Left' and 'right'

FileStream fs = new FileStream("Chapter1_Example1.pdf",
    FileMode.Create, FileAccess.Write, FileShare.None);
Document doc = new Document();
PdfWriter writer = PdfWriter.GetInstance(doc, fs);
doc.Open();
Chunk glue = new Chunk(new VerticalPositionMark());
Paragraph p = new Paragraph("Text to the left");
p.Add(new Chunk(glue));
p.Add("Text to the right");
doc.Add(p);
doc.Close();
Kainix
  • 1,186
  • 3
  • 21
  • 33
androidpol
  • 65
  • 1
  • 1
  • 9

1 Answers1

0

You didn't define a font, hence the default font Helvetica is used. If you want to use a Bold font, you need to create a Font object for the Paragraph.

For instance:

Font boldFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 12);
Paragraph p = new Paragraph("Text to the left", boldFont);

If you want to make only a couple of words bold, you need to split up the Paragraph in different Chunk objects with different fonts. This is explained on the official web site: How can I use regular and bold in a single String?

This is a simple example (notice that there are different ways to create a Font object):

Font regular = new Font(FontFamily.HELVETICA, 12);
Font bold = Font font = new Font(FontFamily.HELVETICA, 12, Font.BOLD);
Paragraph p = new Paragraph("NAME: ", bold);
p.Add(new Chunk("Pol", regular));
Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165