I am creating a pdf with iTextSharp c# and am having a problem when a piece of text runs over to a new page. The following works fine until, for example section 2, runs over to the next page.
private Font _smallFont = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
private Font _smallBoldFont = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 10, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
AddParagraph(doc, Element.ALIGN_LEFT, _smallBoldFont, new Paragraph("\nSection 1\n"));
AddParagraph(doc, Element.ALIGN_LEFT, _smallFont, new Paragraph(textBox2.Text));
AddParagraph(doc, Element.ALIGN_LEFT, _smallBoldFont, new Paragraph("\nSection 2\n"));
AddParagraph(doc, Element.ALIGN_LEFT, _smallFont, new Paragraph(textBox3.Text));
In the over-ridden base.OnStartPage I add a logo and a header text.
Image logoImage = Image.GetInstance(appPath + "\\logo.jpg");
logoImage.ScaleAbsolute(newWidth: 141f, newHeight: 65f);
logoImage.Alignment = Element.ALIGN_CENTER;
document.Add(logoImage);
var headerText = "\nReport Header " + "\n";
Paragraph subText = new Paragraph(headerText, new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 12, iTextSharp.text.Font.BOLD, BaseColor.BLACK));
document.Add(subText);
cb.AddTemplate(templateH, pageSize.GetLeft(document.LeftMargin), pageSize.GetTop(document.TopMargin - 5));
This works except for the fact that the line spacing is increased to about 1.5 (default?) until a new AddParagraph. This happens even if the header text is the same font and size. I have an extremely dirty workaround where I add a second line to the header with a font size of Helvetica 8. This ensures the same leading as the previous page. Why 8 I don’t know as the sections are Helvetica 10. I have tried setting the leading in the AddParagraph but this doesn't help. What am I doing wrong?