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");
Well.. the page size is known to you. You can set it or get it from the section. And you can generally control the size of the objects you add to the page. Most have a Height and a Width. But as for suggestions, the only way you can really do this is one object at a time and keep track of where you are on the page. It's probably going to be pretty tough slogging through adding each element and determining whether it fits on the page or not. As far as I am aware there aren't any methods in the Documents engine to determine the amount of space left on the page, so you will probably need to keep track of that starting with the PageSize and then accounting for the margins, headers, etc.
I have been able to get the headers and footers working. If I use header.AddBand() and add all content to the band, then I can use band.measure() to get the size and set the height.
Now I get to the hard part of porting the old code. These are reports of data from lab instruments. The report pages have a header and footer and the content consists of some text tables and many charts. The code creates these tables and charts and then adds them to the report. Before each object is added to the report, it is determined if the object will fit on the current pdf page. If it will not, a new pdf page is added to the report.
I have some ideas on how to accomplish this, but if you have any ideas, please let me know.
Al
No, there is no reliably way to measure text in the document. You could, in theory, try to measure the same text on the screen in DotNet and then convert pixels to points. This is actually the way the WinGrid Document exporter does it. So you would use Graphics.MeasureString to measure the text using the screen's graphics and then convert the returned value (which is in pixels) into points. I don't think this is an exact measurement so you might have to add some padding just to be safe, but it works pretty well.
I am trying to use Flow and FlowColumn in my report. To set the column widths I need to measure the width of the strings. IText.Width returns a MaxWidth object, which does not give the string's width. Is there a way to determine a string's width in points?
What I am trying to accomplish is to have four columns in total in the header. Column1(label), Column2(value), Column3(label) - starts in middle of page, Column4(value).
To do this I need to know the width of the strings and the width of the header.
Thanks for any help.
Oh, sorry, I thought I mentioned it. All of the samples install optionally when you install the product. So if you installed the samples when you installed the controls, it's already on your hard drive. If you didn't install the sample, then I think you will have to run the installer again to get them.