<package id="PDFsharp-MigraDoc-GDI" version="1.32.4334.0" targetFramework="net451" />
Code:
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
public Document CreateReport(BaseReportModel model, bool isPreview)
{
var document = new Document();
document.Info.Title = "{0} for {1}".FormatWith(model.ReportType, model.StudentName);
document.Info.Subject = model.ReportType.Name;
document.Info.Author = "xxxxxxxxxxxxxx";
SetUpMargins(document);
SetupReportStyles(document);
var mainSection = document.AddSection();
if (isPreview) AddDraftWatermarkToSection(mainSection);
AddFooter(mainSection, model.ReportType.Name, model.StudentName, model.StudentNumber);
AddReportHeader(mainSection, model);
AddGeneralInformationSection(mainSection, model);
AddProgramSection(mainSection, model);
var backGroundColor = ReportFormatting.BlueBackgroundColor;
if (isPreview) backGroundColor = ReportFormatting.BlueBackgroundColorWithTransparency;
var numberOfVisibleSections = 0;
if (model.ConditionsForSuccessItems.Count > 0)
{
AddConditionsForSuccessSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
numberOfVisibleSections++;
}
if (model.CurrentLearningsItems.Count > 0)
{
AddCurrentLearningSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
numberOfVisibleSections++;
}
if (model.PriorityLearningCyclesItems.Count > 0)
{
AddPriorityLearningAreasSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
numberOfVisibleSections++;
}
if (model.SpecializedAssessmentsItems.Count > 0)
{
AddSpecializedAssessmentsSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
numberOfVisibleSections++;
}
if (model.KeyUnderstandingsItems.Count > 0)
{
AddKeyUnderstandingsSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
numberOfVisibleSections++;
}
if (model.SupportsAndServicesItems.Count > 0)
{
AddSupportAndServicesSection(mainSection, model, numberOfVisibleSections % 2 == 0 ? backGroundColor : Color.Empty);
}
return document;
}
}
protected static void AddCurrentLearningSection(Section section, BaseReportModel reportData, Color backgroundColor)
{
var table = CreateLearnerProfileSectionTable(section, backgroundColor);
table.AddColumn("1.0cm");
table.AddColumn("1.0cm");
table.AddColumn("16.0cm");
AddLearnerProfileSectionHeader(table, "Current Learning");
if (reportData.CurrentLearningsItems.Count == 0)
{
AddNoContentMessage(table);
}
else
{
foreach (var model in reportData.CurrentLearningsItems.OfType<CurrentLearningModel>())
{
AddCurrentLearningModel(table, model);
}
}
AddSectionBorderRow(table);
}
private static Table CreateLearnerProfileSectionTable(Section section, Color backgroundColor)
{
var table = section.AddTable();
table.Shading.Color = backgroundColor;
table.Borders.Visible = false;
table.Borders.Width = 0;
table.Borders.Style = BorderStyle.None;
table.Format.KeepTogether = true;
table.BottomPadding = 0;
table.KeepTogether = true;
return table;
}
private static void AddLearnerProfileSectionHeader(Table table, string heading)
{
var row = table.AddRow();
row.Borders.Top.Color = ReportFormatting.BlueBorderColor;
row.Borders.Top.Visible = true;
row.Borders.Top.Width = 1;
row = table.AddRow();
var cell = row.Cells[0];
cell.MergeRight = cell.Table.Columns.Count - 1;
cell.Row.KeepWith = 2;
var paragraph = cell.AddParagraph();
paragraph.Format.KeepTogether = true;
paragraph.Format.KeepWithNext = true;
paragraph.AddFormattedText(heading, ReportFormatting.LargeBlueHeading);
}
private static void AddCurrentLearningModel(Table table, CurrentLearningModel model)
{
var row = GetDefaultHeadingRow(table, model.Content, TextFormat.NotBold);
row.Cells[1].MergeRight = 1;
if (!model.HideTags)
{
if (model.Tags.Count > 0)
{
foreach (var tag in model.Tags)
{
row = table.AddRow();
row.KeepWith = 1;
var paragraph = row.Cells[2].AddParagraph();
paragraph.AddFormattedText(tag.Text, ReportFormatting.CurrentLearningTagText);
}
}
}
row.BottomPadding = DefaultBottomPadding;
AddModifiedByLineToParagraph(table, 1, 1, model);
}
private static Row GetDefaultHeadingRow(Table table, string title, TextFormat textFormat = TextFormat.Bold)
{
var row = table.AddRow();
row.BottomPadding = DefaultBottomPadding;
row.TopPadding = DefaultTopPadding;
row.KeepWith = 1;
var paragraph = row.Cells[1].AddParagraph();
paragraph.AddFormattedText(title, textFormat);
return row;
}
private static void AddModifiedByLineToParagraph(Table table, int cellIndex, int numberOfCellsToMergeRight, BaseReportItemModel model)
{
if (model.HideAuthorAndDate)
{
table.Rows[table.Rows.Count - 1].KeepWith = 0;
return;
}
var row = table.AddRow();
var paragraph = row.Cells[cellIndex].AddParagraph();
row.Cells[cellIndex].MergeRight = numberOfCellsToMergeRight;
paragraph.AddFormattedText(string.Format("{0} | {1}", model.ModifiedDate, model.ModifiedBy), ReportFormatting.SmallPrint);
}
private static void AddSectionBorderRow(Table table)
{
var row = table.AddRow();
row.Borders.Bottom.Color = ReportFormatting.BlueBorderColor;
row.Borders.Bottom.Width = 1;
row.Borders.Bottom.Visible = true;
}