I have written single page reports but I am now working on multiple page reports and have questions.
These reports have headers and footers with different content on the pages. The pages have different content for the headers, but the footers have the same content (file name and page number).
ISection has AddHeader(), AddFooter(), AddPage(), and AddPageBreak(). AddPage() returns a ISectionPaage object.
I am confused about how to add pages with different headers and using continuous page numbering in the footers.
I am looking for recommendations.
Hi Alf,
I'm not aware of any way to have different headers and footers on each page. The headers and footers can only implement repeating patterns as far as I know. Of course, you can use AddPageBreak and then add whatever content you want on a page, so you could put some content at the top of each page outside of the header/footer.
Here's some sample code that shows how to do page numbers in the footer.
private void button1_Click(object sender, EventArgs e) { Report report = new Report(); var section = report.AddSection(); section.PageNumbering = new Infragistics.Documents.Reports.Report.Section.PageNumbering(); section.PageNumbering.Template = "Page [Page #] of [TotalPages]"; section.PageNumbering.Continue = true; section.PageNumbering.SkipFirst = false; section.PageNumbering.Alignment = Infragistics.Documents.Reports.Report.PageNumberAlignment.Right; section.PageNumbering.OffsetX = -10; var text = section.AddText(); text.AddContent("This is the first page and it has some text on it."); section.AddPageBreak(); text = section.AddText(); text.AddContent("This is the second page and it has some text on it."); string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "test.pdf"); report.Publish(filename, FileFormat.PDF); Process.Start(filename); }
private void button1_Click(object sender, EventArgs e) { Report report = new Report(); var section = report.AddSection();
section.PageNumbering = new Infragistics.Documents.Reports.Report.Section.PageNumbering(); section.PageNumbering.Template = "Page [Page #] of [TotalPages]"; section.PageNumbering.Continue = true; section.PageNumbering.SkipFirst = false; section.PageNumbering.Alignment = Infragistics.Documents.Reports.Report.PageNumberAlignment.Right; section.PageNumbering.OffsetX = -10;
var text = section.AddText(); text.AddContent("This is the first page and it has some text on it.");
section.AddPageBreak();
text = section.AddText(); text.AddContent("This is the second page and it has some text on it.");
string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "test.pdf"); report.Publish(filename, FileFormat.PDF); Process.Start(filename); }
Thank you for the reply. I was able to generate different headers for the first page and subsequent pages. Use section.AddHeader() and then section.AddPage().
The project I am working on is to convert existing code from using Component One controls to Infragistics WPF & Reporting.
Now I am trying to figure out how to have two equal width columns in the header. I know I can use band.AddFlow() and Flow.AddColumn(), but how do I set the column width to half of the page?
What I would do is add a grid into your header and then put two columns into the grid. Then you can populate the cells of the grid with the text you want.
var header = section.AddHeader(); var grid = header.AddGrid(0, 0); grid.Width = AutoWidth.Instance; grid.Height = AutoHeight.Instance; var col0 = grid.AddColumn(); var col1 = grid.AddColumn(); var row0 = grid.AddRow(); var cell0 = row0.AddCell(); var cellText = cell0.AddText(); cellText.AddContent("This is the left side of the header"); var cell1 = row0.AddCell(); cellText = cell1.AddText(); cellText.AddContent("This is the Right side of the header");
I am getting very frustrated trying to generate a multiple page report with headers and footers. I can get headers to appear, but not footers. Page numbers appear at the bottom of the page as expected. When I add text to a page it overwrites the header. Is there any example code for a multi page report?
Some of the code I am using:
report = new Report()
mainSection = report.AddSection()
mainSectionHeader = mainSection.AddHeader()
mainSectionFooter = mainSection.AddFooter()
hdrTxt = mainSectionHeader.AddText(0,0)
hdrTxt.AddContent("any text", fontstyle)
mainSectionFooter.Repeat = true;
ftrTxt = mainSectionFooter.AddText(0,0)
ftrTxt.AddContent("any text", fontstyle)
page = mainSection.AddPage()
pageHeader = mainSection.AddHeader()
I don't understand why the footer will not appear and why when I add content to a page it overwrites the header.
Did you check out the DocumentExporterGallery sample I mentioned? It uses footers for a couple of the samples.
I compared your code to the code in that sample and the only thing it's doing differently than your code is that it's setting the Height of the Footer. So I added setting the height to your code and it works:
mainSectionFooter.Height = 50;
think the header overlapping the text is the same issue. If I explicitly set the height of the header, it works:
mainSectionHeader.Height = 50;