public byte[] GetProjectGroupsListReport(ProjectGroupsGeneralReportListViewModel request, DateTime startDate, DateTime dueDate) { var pdf = new PdfDocument(); var page = pdf.AddPage(); page.Orientation = PageOrientation.Landscape; page.Size = PageSize.A4; var pages = new List <PdfPage> { page }; //Create pdf content var doc = CreateDocument(nameof(this.GetProjectGeneralReport), string.Format("{1}, {0}", "Default", "Default")); var commonParameter = new CommonPdfParameter { Document = doc, Pdf = pdf, PdfPages = pages, StartDate = startDate, DueDate = dueDate }; PopulateForProjectGroupsGeneralReportListViewModel(commonParameter, request); //Create renderer for content var renderer = new DocumentRenderer(doc); renderer.PrepareDocument(); var pageSize = GetPageSizeInXRectUnits(page.Size); var pageNumber = 0; foreach (var item in pages) { var gfx = XGraphics.FromPdfPage(item); var container = gfx.BeginContainer(pageSize, pageSize, XGraphicsUnit.Point); gfx.DrawRectangle(XPens.LightGray, pageSize); renderer.RenderPage(gfx, ++pageNumber); gfx.EndContainer(container); } using (MemoryStream ms = new MemoryStream()) { pdf.Save(ms, true); return(ms.ToArray()); } }
public byte[] GetProjectGroupsListReport(ProjectGroupsGeneralReportListViewModel request, DateTime startDate, DateTime dueDate) { var result = new StringBuilder(); result.AppendFormat("{0}, {1}{2}", "Start date", $"{startDate:dddd, dd MMMM yyyy}", '\n'); result.AppendFormat("{0}, {1}{2}", "Due date", $"{dueDate:dddd, dd MMMM yyyy}", '\n'); result.Append('\n'); foreach (var projectGroup in request.ProjectGroups) { result.AppendFormat("{0}, {1}{2}", "Project Group: ", projectGroup.ProjectGroupName, '\n'); foreach (var project in projectGroup.Projects) { result.AppendFormat("{0}, {1}, {2}, {3}{4}", "#", "Project", "Est.", "Log.", '\n'); } result.AppendFormat("{0}, {1}, {2}{3}", "Total time", projectGroup.TotalEstimatedTime, projectGroup.TotalLoggedTime, '\n'); result.Append("\n\n\n"); } return(Encoding.Unicode.GetBytes(result.ToString())); }
private void PopulateForProjectGroupsGeneralReportListViewModel(CommonPdfParameter common, ProjectGroupsGeneralReportListViewModel request) { #region Header var section = common.Document.AddSection(); var header = section.Headers.Primary.AddParagraph(); header.Format.Font.Size = common.PdfTableHelper.HeaderSize; header.Format.Font.Color = Colors.DarkBlue; header.Format.Font.Bold = true; header.Format.Font.Italic = true; header.Format.Alignment = ParagraphAlignment.Center; #endregion #region Table var tableCells = common.HeaderNames; var table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells); var totalRows = 0; foreach (var projectGroup in request.ProjectGroups) { var iteration = 0; foreach (var project in projectGroup.Projects) { var row = table.AddRow(); row.Cells[0].AddParagraph((++iteration).ToString()); row.Cells[1].AddParagraph(projectGroup.ProjectGroupName); row.Cells[2].AddParagraph(project.ProjectName); row.Cells[3].AddParagraph(project.EstimatedTime.ToString("0.00")); row.Cells[4].AddParagraph(project.LoggedTime.ToString("0.00")); if (iteration % common.PdfTableHelper.ItemsPerPage == 0) { section = common.Document.AddSection(); header = section.Headers.Primary.AddParagraph(); header.AddText(string.Empty); var page = common.Pdf.AddPage(); page.Orientation = PageOrientation.Landscape; page.Size = common.PdfTableHelper.PageSize; common.PdfPages.Add(page); section.AddPageBreak(); table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells); } } var breakRow = table.AddRow(); totalRows = iteration; } if (totalRows % common.PdfTableHelper.ItemsPerPage > 0) { section.AddPageBreak(); } var column = table.AddRow(); column.Borders.Style = BorderStyle.None; column = table.AddRow(); column.Format.Font.Bold = true; column.Cells[2].AddParagraph("Start date"); column.Cells[3].AddParagraph(string.Format("{0:yyyy-M-d}", common.StartDate)); column = table.AddRow(); column.Format.Font.Bold = true; column.Cells[2].AddParagraph("Due date"); column.Cells[3].AddParagraph(string.Format("{0:yyyy-M-d}", common.DueDate)); column = table.AddRow(); column.Format.Font.Bold = true; column.Cells[2].AddParagraph("Total Estimated:"); column.Cells[3].AddParagraph(request.TotalEstimatedTine.ToString("0.00")); column = table.AddRow(); column.Format.Font.Bold = true; column.Cells[2].AddParagraph("Total Logged:"); column.Cells[3].AddParagraph(request.TotalLoggedTime.ToString("0.00")); table = CreateTableHeader(ref section, common.PdfTableHelper, tableCells); table.Rows.Alignment = RowAlignment.Center; #endregion }