3

I'm currently working on a PDF but I am facing issues trying to increase the line-height of a Paragraph, this is the code that I have now:

var tempTable = new PdfPTable(1);

cell = new PdfPCell(new Paragraph("My Account", GetInformationalTitle()));
cell.Border = Rectangle.NO_BORDER;
tempTable.AddCell(cell);

cell = new PdfPCell(new Paragraph("http://www.google.com/", GetInformationalOblique()));
cell.Border = Rectangle.NO_BORDER;
cell.PaddingBottom = 10f;
tempTable.AddCell(cell);

var para = new Paragraph("Login to 'My Account' to access detailed information about this order. " +
"You can also change your email address, payment settings, print invoices & much more.", GetInformationalContent());
 para.SetLeading(0f, 2f);

 cell = new PdfPCell(para);
 cell.Border = Rectangle.NO_BORDER;
 tempTable.AddCell(cell);

As you can see from above, I'm trying to increase the line-height of para, I've tried para.SetLeading(0f, 2f) but it is still not increasing the line-height or leading, as it is called.

What could be the problem here?

Dan
  • 971
  • 1
  • 8
  • 22
  • This question is not an exact duplicate of [iText: maintain identing if paragraph takes new line in PdfPCell](http://stackoverflow.com/questions/28073190/itext-maintain-identing-if-paragraph-takes-new-line-in-pdfpcell), but the answer is the same: you are adding the `Paragraph` in *text mode* instead of adding it in *composite mode*. In your case, the leading of the `PdfPCell` gets preference over the leading of the `Paragraph` (as you have noticed that leading is ignored in *text mode*). – Bruno Lowagie Feb 05 '15 at 07:26
  • Awesome! I've fixed it by using `AddElement(para)` instead of initializing it in the constructor. You might want to post it in an answer so I can mark it as answered, once again, thanks! – Dan Feb 05 '15 at 07:34

1 Answers1

7

You are adding para in text mode instead of adding it in composite mode. Text mode means that the leading of the PdfPCell will get preference over the leading defined for the Paragraph. With composite mode, it's the other way around.

You can fix this with a small change:

cell = new PdfPCell();
cell.addElement(para);
tempTable.AddCell(cell);

Using the addElement() method makes cell switch from text mode to composite mode.

Bruno Lowagie
  • 75,994
  • 9
  • 109
  • 165