Asiye
Asiye

Reputation: 33

How to change paragraph text size working with itext

i am generating a pdf file. Everything works fine. Now I want to increase the paragraph text size in my pdf document but don't know how.

Here is my code

Font f = new Font(Font.FontFamily.TIMES_ROMAN, 25.0f, Font.BOLD, BaseColor.BLACK);
Chunk c = new Chunk("Ergebnisse");
c.setBackground(BaseColor.RED);
Paragraph p1 = new Paragraph(c);
document.add(p1);
p1.setAlignment(Paragraph.ALIGN_CENTER);

I want the text "Ergebnisse" to get bigger and centered in the middle.

Upvotes: 1

Views: 3128

Answers (1)

Bruno Lowagie
Bruno Lowagie

Reputation: 77528

Your code was almost correct:

Font f = new Font(Font.FontFamily.TIMES_ROMAN, 25.0f, Font.BOLD, BaseColor.BLACK);
// you created a font, but you never used it:
Chunk c = new Chunk("Ergebnisse", f);
c.setBackground(BaseColor.RED);
Paragraph p1 = new Paragraph(c);
// you changed the alignment AFTER adding p1 to the document
p1.setAlignment(Paragraph.ALIGN_CENTER);
document.add(p1);

So:

  1. use f when creating the Chunk.
  2. switch the last two lines in your code snippet.

Upvotes: 1

Related Questions