private void NewPage(object previousRow, object row) { if (previousRow != null && PageFooter != null) { PageFooter.Render(previousRow, renderEngine, xOffset, PageLength - PageFooter.Height - BottomMargin, DefaultStyle); } renderEngine.NewPage(); yOffset = TopMargin; pagenumber++; if (previousRow == null && ReportHeader != null) { double growth = ReportHeader.Render(row, renderEngine, xOffset, yOffset, DefaultStyle); yOffset += ReportHeader.Height + growth; } if (PageHeader != null) { double growth = PageHeader.Render(row, renderEngine, xOffset, yOffset, DefaultStyle); yOffset += PageHeader.Height + growth; } if (ShowGrid) { Pen gridPen = new Pen(Color.LightGray, 0.5f); for (int i = 0; i < PrintableAreaWidth; i += 25) { ReportObjectLine l = new ReportObjectLine() { XLeft = i, XRight = i, YTop = 0, YBottom = PrintableAreaLength, Pen = gridPen }; l.Render(null, renderEngine, xOffset, yOffset, DefaultStyle, null); } for (int i = 0; i < PrintableAreaLength; i += 25) { ReportObjectLine l = new ReportObjectLine() { XLeft = 0, XRight = PrintableAreaWidth, YTop = i, YBottom = i, Pen = gridPen }; l.Render(null, renderEngine, xOffset, yOffset, DefaultStyle, null); } } }
public void GeneratePDF(string FileName, bool OpenWhenDone = true) { renderEngine = new RenderToPDF(SelectedPageType, SelectedOrientation); rep = new genericReport(); yOffset = TopMargin; xOffset = LeftMargin; object previousRow = null; bool pageBreak = true; pagenumber = 0; foreach (object row in DataSource) { if (pageBreak || IsPageBreakNeeded()) { NewPage(previousRow, row); pageBreak = false; } //GroupFooters Footers(previousRow, row); //GroupHeaders foreach (ReportGroup reportGroup in ReportGroups) { if (reportGroup.GroupingHasChanged(row)) { if ((reportGroup.StartOnNewPage && yOffset > TopMargin) || IsPageBreakNeeded(reportGroup.HeaderSection.Height)) { NewPage(previousRow, row); } double growthForThisSection = reportGroup.HeaderSection.Render(row, renderEngine, xOffset, yOffset, DefaultStyle); yOffset += reportGroup.HeaderSection.Height + growthForThisSection; reportGroup.FooterSection.aggregatedValues = null; } } //Alternating detail color if (AlternatingRowsPrimaryColor != null && AlternatingRowsSecondaryColor != null) { Brush brush = applyAlternateColor ? new SolidBrush(AlternatingRowsPrimaryColor) : new SolidBrush(AlternatingRowsSecondaryColor); renderEngine.DrawRectangle(null, brush, LeftMargin, yOffset, PrintableAreaWidth, DetailSection.Height); applyAlternateColor = !applyAlternateColor; } if (IsPageBreakNeeded(DetailSection.Height)) { NewPage(previousRow, row); } double growthForDetailSection = DetailSection.Render(row, renderEngine, xOffset, yOffset, DefaultStyle); yOffset += DetailSection.Height + growthForDetailSection; if (PageFooter != null) { PageFooter.calculateAggregates(row); } foreach (ReportGroup reportGroup in ReportGroups) { reportGroup.FooterSection.calculateAggregates(row); reportGroup.previousRow = row; } previousRow = row; } if (previousRow != null) { Footers(previousRow, null); if (PageFooter != null) { double y = PageLength - (PageFooter != null ? PageFooter.Height : 0) - (ReportHeader != null ? ReportHeader.Height : 0) - BottomMargin; if (y < yOffset) { renderEngine.NewPage(); yOffset = TopMargin; pagenumber++; } double growth = PageFooter.Render(previousRow, renderEngine, xOffset, y, DefaultStyle); yOffset += PageFooter.Height + growth; } if (ReportFooter != null) { double y = PageLength - ReportHeader.Height; double growth = ReportFooter.Render(previousRow, renderEngine, xOffset, y, DefaultStyle); yOffset += PageFooter.Height + growth; } } renderEngine.Save(FileName); if (OpenWhenDone) { Process.Start(FileName); } }