I have attached the PDF print outs of the report I want to generate. I would like to have a line separating each test result (bottom border). I have found that when the results span multiple pages, the last border on the page gets duplicated at the top of the next page.
**EDIT: Just uploaded the PDFs as a ZIP**One report shows how it looks if I remove the last row bottom border for each category's results. The code below has this logic commented out... (count < itemCount).
I did a test to make sure it is actually this chunk of code that is causing the bottom border to be rendered. I replaced the (if (count < itemCount) with this:
Code:
if (r.QuestionName != "Vitamin B12")
{
hRow.Borders.Bottom.Color = Colors.Black;
hRow.Borders.Bottom.Width = "0.05cm";
}
This removed the bottom border right below the Vitamin B12 on the first page, and there was no duplicate either...
Here is the full chunk of code that is generating the table:
Code:
var section = doc.LastSection;
section.AddParagraph("Health Profile", "Heading3");
//create table header and column definitions
var tableHeader = section.AddTable();
//add columns, plus extra at begining for result name
var column = tableHeader.AddColumn("5cm");
column.Format.Alignment = ParagraphAlignment.Left;
column = tableHeader.AddColumn("2.75cm");
column.LeftPadding = "0.2cm";
column.RightPadding = "0.2cm";
column.Format.Alignment = ParagraphAlignment.Center;
column = tableHeader.AddColumn("2.75cm");
column.LeftPadding = "0.2cm";
column.RightPadding = "0.2cm";
column.Format.Alignment = ParagraphAlignment.Center;
column = tableHeader.AddColumn("2.75cm");
column.LeftPadding = "0.2cm";
column.RightPadding = "0.2cm";
column.Format.Alignment = ParagraphAlignment.Center;
column = tableHeader.AddColumn("2.75cm");
column.LeftPadding = "0.2cm";
column.RightPadding = "0.2cm";
column.Format.Alignment = ParagraphAlignment.Center;
column = tableHeader.AddColumn("2.5cm");
column.LeftPadding = "0.2cm";
column.RightPadding = "0.2cm";
column.Format.Alignment = ParagraphAlignment.Center;
column = tableHeader.AddColumn("1.2cm");
column.LeftPadding = "0.2cm";
column.RightPadding = "0.2cm";
column.Format.Alignment = ParagraphAlignment.Center;
//add dynamic column headers
var hRow = tableHeader.AddRow();
int count = 1;
foreach (var e in _events)
{
var colHeader = String.IsNullOrEmpty(e.Name) ? " " : e.Name;
//var para = hRow.Cells[count].AddParagraph();
Paragraph p = AddTextToCell(colHeader, hRow.Cells[count], "Verdana", Unit.FromPoint(8));
count++;
}
//add static column headers
var para2 = hRow.Cells[5].AddParagraph();
para2.AddFormattedText("PNSF Optimal Healthy Score", "TextLabel");
para2 = hRow.Cells[6].AddParagraph();
para2.AddFormattedText("Units", "TextLabel");
//add header row of table to every page
hRow.HeadingFormat = true;
//add dynamic column dates
hRow = tableHeader.AddRow();
count = 1;
foreach (var e in _events)
{
var p = hRow.Cells[count].AddParagraph();
p.AddFormattedText(e.Date.Year < 1900 ? String.Empty : "(" + e.Date.ToString("yyyy/MM/dd") + ")", "DateLabel");
count++;
}
//add dates row to heading of every page.
hRow.HeadingFormat = true;
//add categories and results
var itemsToIterate = _results.OrderBy(x => x.CategoryOrder).ThenBy(x => x.QuestionOrder);
var currentCategory = itemsToIterate.ToList()[0].Category;
//add first category header
hRow = tableHeader.AddRow();
var categoryHeader = hRow.Cells[0].AddParagraph();
categoryHeader.AddFormattedText(currentCategory, "CategoryLabel");
//hRow.Format.SpaceAfter = "0.1cm";
hRow.Format.SpaceBefore = "0.5cm";
int itemCount = itemsToIterate.Count(x => x.Category == currentCategory);
count = 1;
foreach (var r in itemsToIterate)
{
//set category header
if (r.Category != currentCategory)
{
////add space after last row
//hRow.Format.SpaceAfter = "0.5cm";
hRow = tableHeader.AddRow();
categoryHeader = hRow.Cells[0].AddParagraph();
categoryHeader.AddFormattedText(r.Category, "CategoryLabel");
//hRow.Format.SpaceAfter = "0.2cm";
hRow.Format.SpaceBefore = "0.5cm";
//set the KeepWith property to keep sections together if they span multiple pages
hRow.KeepWith = itemsToIterate.Count(x => x.Category == r.Category);
//reset item count for this category
itemCount = itemsToIterate.Count(x => x.Category == r.Category);
count = 1;
}
//add result
hRow = tableHeader.AddRow();
var para3 = hRow.Cells[0].AddParagraph();
para3.AddFormattedText(r.QuestionName, "ResultsText");
para3 = hRow.Cells[1].AddParagraph();
para3.AddFormattedText(r.Response1, "ResultsText");
para3 = hRow.Cells[2].AddParagraph();
para3.AddFormattedText(r.Response2, "ResultsText");
para3 = hRow.Cells[3].AddParagraph();
para3.AddFormattedText(r.Response3, "ResultsText");
para3 = hRow.Cells[4].AddParagraph();
para3.AddFormattedText(r.Response4, "ResultsText");
para3 = hRow.Cells[5].AddParagraph();
para3.AddFormattedText(r.OptimalScore, "ResultsText");
para3 = hRow.Cells[6].AddParagraph();
para3.AddFormattedText(r.Unit, "ResultsText");
//if (count < itemCount)
//{
hRow.Borders.Bottom.Color = Colors.Black;
hRow.Borders.Bottom.Width = "0.05cm";
//}
//set vertical alignment
hRow.VerticalAlignment = VerticalAlignment.Center;
hRow.TopPadding = "0.1cm";
hRow.BottomPadding = "0.1cm";
//add highlighting
HighlightCell(hRow, 1, r.Highlighting1);
HighlightCell(hRow, 2, r.Highlighting2);
HighlightCell(hRow, 3, r.Highlighting3);
HighlightCell(hRow, 4, r.Highlighting4);
//update category
currentCategory = r.Category;
count++;
}