In some situations the height of the first table row is wrongly calculated after a page break (see attached screenshot or output.pdf).
We use the following code to produce the PDF:
Pdf document = new Pdf();
document.PageSetup.PageWidth = PageSize.A4Height;
document.PageSetup.PageHeight = PageSize.A4Width;
document.PageSetup.Margin = new MarginInfo();
TextInfo defaultTextInfo = new TextInfo();
defaultTextInfo.FontName = DefaultFontName;
defaultTextInfo.IsUnicode = true;
defaultTextInfo.IsFontEmbedded = true;
defaultTextInfo.FontSize = DefaultFontSizeStandard;
document.TextInfo = defaultTextInfo;
Section contentSection = document.Sections.Add();
contentSection.PageInfo.Margin = new MarginInfo() { Left = 30, Top = 72, Right = 30, Bottom = 72 };
TextInfo headTextInfo = (TextInfo)contentSection.TextInfo.Clone();
headTextInfo.Color = TitleColor;
TextInfo tableTextInfo = (TextInfo)contentSection.TextInfo.Clone();
tableTextInfo.FontSize = DefaultFontSizeStandard;
// HEAD
TextInfo dateHeadTextInfo = (TextInfo)contentSection.TextInfo.Clone();
dateHeadTextInfo.IsTrueTypeFontBold = true;
Text dateHeadText = new Text(DateTime.Now.ToString("D", System.Globalization.CultureInfo.InvariantCulture));
dateHeadText.TextInfo = dateHeadTextInfo;
dateHeadText.Margin = new MarginInfo() { Top = 72 };
contentSection.Paragraphs.Add(dateHeadText);
// PRODUCTS
Table table = new Table();
table.ColumnWidths = "190 65 103 30 30 25 40 50 60 40 40 40 70";
table.DefaultCellTextInfo = tableTextInfo;
table.IsFirstRowRepeated = true;
table.RepeatingRows = 2;
table.DefaultCellPadding = new MarginInfo() { Left = 2, Top = 2, Bottom = 2, Right = 2 };
table.DefaultCellBorder = new BorderInfo() { Top = new GraphInfo() { LineWidth = 0.5f, LineJoinMode = 1 }, Bottom = new GraphInfo() { LineWidth = 0.5f, LineJoinMode = 1 } };
TextInfo headerTextInfo = (TextInfo)tableTextInfo.Clone();
headerTextInfo.IsTrueTypeFontBold = false;
headerTextInfo.Color = new Color("white");
TextInfo rightAlignedHeaderTextInfo = (TextInfo)headerTextInfo.Clone();
rightAlignedHeaderTextInfo.Alignment = AlignmentType.Right;
//
Row headerRow1 = table.Rows.Add();
headerRow1.BackgroundColor = TitleBackgroundColor;
headerRow1.DefaultCellTextInfo = headerTextInfo;
//headerRow1.DefaultRowCellPadding = new MarginInfo() { Left = 2, Top = 2, Right = 2, Bottom = 1 };
headerRow1.DefaultCellBorder = new BorderInfo();
headerRow1.Cells.Add("Fund Name");
headerRow1.Cells.Add("ISIN");
headerRow1.Cells.Add("Julius Baer");
headerRow1.Cells.Add("Type");
headerRow1.Cells.Add("CCY");
headerRow1.Cells.Add("Distr.", rightAlignedHeaderTextInfo);
headerRow1.Cells.Add("NAV", rightAlignedHeaderTextInfo);
headerRow1.Cells.Add("NAV Date", rightAlignedHeaderTextInfo);
headerRow1.Cells.Add("Year to Date", rightAlignedHeaderTextInfo);
Cell annualisedReturn = headerRow1.Cells.Add("Annualised Return");
annualisedReturn.ColumnsSpan = 3;
TextInfo annualisedReturnTextInfo = (TextInfo)headerTextInfo.Clone();
annualisedReturnTextInfo.Alignment = AlignmentType.Center;
annualisedReturn.DefaultCellTextInfo = annualisedReturnTextInfo;
headerRow1.Cells.Add("Volatility", rightAlignedHeaderTextInfo);
//
Row headerRow2 = table.Rows.Add();
headerRow2.BackgroundColor = TitleBackgroundColor;
headerRow2.DefaultCellTextInfo = headerTextInfo;
//headerRow2.DefaultRowCellPadding = new MarginInfo() { Left = 2, Top = 1, Right = 2, Bottom = 1 };
headerRow2.DefaultCellBorder = new BorderInfo();
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add("Recommendation");
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add(string.Empty);
headerRow2.Cells.Add("1 Year", rightAlignedHeaderTextInfo);
headerRow2.Cells.Add("3 Years*", rightAlignedHeaderTextInfo);
headerRow2.Cells.Add("5 Years*", rightAlignedHeaderTextInfo);
headerRow2.Cells.Add("3 Years**", rightAlignedHeaderTextInfo);
TextInfo titleRowTextInfo = (TextInfo)tableTextInfo.Clone();
titleRowTextInfo.IsTrueTypeFontBold = true;
if (classifications != null)
{
foreach (FundCategory classification in classifications)
{
Row titleRow = table.Rows.Add();
titleRow.DefaultCellTextInfo = titleRowTextInfo;
titleRow.BackgroundColor = SubtitleBackgroundColor;
Cell titleCell = titleRow.Cells.Add(string.Format("Asset Class: {0} / Region: {1} / Share Class Currency: {2}", classification.AssetClass, classification.Region, classification.Currency));
titleCell.ColumnsSpan = 13;
foreach (Fund product in classification.Products)
{
Row productRow = table.Rows.Add();
productRow.DefaultCellBorder = new BorderInfo() { Bottom = new GraphInfo() { LineWidth = 0.5f } };
productRow.Cells.Add(product.Name);
productRow.Cells.Add(product.Isin);
productRow.Cells.Add(product.Recommendation.Length == 0 ? "-" : product.Recommendation).IsWordWrapped = true;
productRow.Cells.Add(product.FundType);
productRow.Cells.Add(product.Currency);
productRow.Cells.Add(product.Distribution);
productRow.Cells.Add(string.Empty);
productRow.Cells.Add(string.Empty);
productRow.Cells.Add(string.Empty);
productRow.Cells.Add(string.Empty);
productRow.Cells.Add(string.Empty);
productRow.Cells.Add(string.Empty);
productRow.Cells.Add(string.Empty);
}
}
}
contentSection.Paragraphs.Add(table);
document.Save(stream);