After adding all the content I need to a report (which will be published as a PDF document) I need to know how many pages the exported PDF document will have. How do I determine the number of pages in my report?
Thanks.
You might look into the following documentation topic the explains how to Add Page numbers to a report.
http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/DocumentEngine_Add_Page_Numbering.html
Thanks for your reply.
This article is helpful for basic page numbering but unfortunately doesn't help me understand how I can make logic decisions in my code based upon the current page count. This count probably isn't available until the report is actually published.
report.Publish(pathAndNameToPdf_FiileSystemPath, Infragistics.Documents.Report.FileFormat.PDF);
Is there some type of pre-publish option?
Thanks. -- David
Hey David,
To accomplish your task you can try this:
IProjectionPageCollection pages = report.Generate();
You can get a count from this class. Here is the API reference for your convenience:
http://help.infragistics.com/Help/NetAdvantage/NET/2008.1/CLR2.0/html/Infragistics2.Documents.v8.1~Infragistics.Documents.Report.Projection.IProjectionPageCollection_members.html
**** The following is slightly off topic, but it shows an example on how one can use the IProjectionPageCollection to create graphics objects of each page, draw to them and then save each page to a JPG image file:
//Get the pages and loop through them:
Graphics theGraphics = null;
string ImageFile = string.Empty;
{
theBitMap = new Bitmap(width, height);
page.Draw(infraGraphics);
infraGraphics.DrawString(20, 20, "Page: " + pageNum.ToString());
infraGraphics.DrawString(20, 40, "Graphics Object!");
pageNum ++;
}
we are using Infragistics.Documents.Reports and we observed that while generating report PDF - our contents are getting truncated if those are more than 2 pages in the grid. It shows total 3 page report where 3rd page displays with footer information and 1st page displays header part and detail report part and 2nd page also displays detail part. Data are coming properly as if i decrease padding then it shows me some of the truncated data which could fit into 2nd page but after 2nd page - it won't show any remaining data of the detail.
Any way to identify or recalculate page generation logic of the content if its now generating enough pages then can we generate explicitly but for that we need to know how many pages would be required to show this content and build up that logic as well..
any solution is recommended.
Hi,
This issue was never brought to Developer Support by the first customer in this thread. We figured this scenario was no longer an issue. However, I have sent this to Developer Support myself so that they created an incident. This has to go through development to see why this happens and if they can do something about it. I understand how the document engine works very well and one thing I can speak to is that the design of the engine is pretty much that of a "linear" execution model. This means that the code (both internal and external to the engine) executes top-down. There are no collections or accessible objects as we know them in OOP land, however, this model offers much greater performance and a much more tighter code base.
In the meantime while this is being looked at, as a work-around, you may want to try and use logic similar to the following:
Execute your code until it reaches the point where you need to determine the number of pages. Once you determine that number, discard the report and then start over again and then go PAST the point where you discovered the page count. This way you can create your document from start to finish on the second pass with knowledge of how many pages you have.
Here is the case number for the incident that was submitted for you:
CAS-26127-CB532K
You can use that number to refer to your case / incident when going through Developer Support:
http://ko.infragistics.com/support/default.aspx#Overview
Was this ever submitted as a bug? I've noticed this same behavior in v2009.1, which was just recently released. I also just submitted a support request today related to this same issue. I'm hoping that this is already in the list of known bugs and that it is already being worked on. Having the ability to determine the number of pages so that I can add content afterwards is key to the project that I am working on.
I think you may be experiencing unintended behavior.
I add new pages in a slightly different manner than yours:
theSection.AddPage().AddText(50f, 50f).AddContent("This page intentionally left blank #1");
I do this rather than adding a page break however, both should work similarly.
I notice that whenever I call theReport.Generate( ), anything I add afterwards is not added. It seems that something internal to the Report is causing anything that is added after the Generate( ) method to not be added.
At this point there are 2 things you can do:
1: If you need to make this work right away without any delay, you will have to execute your logic 2 times: First to determine your page count and then a second time to use the page count (without calling Report.Generate() ) to perform your page adding logic.
2: Submit a bug to Developer Support. Use the following code to create a sample based on your particular assembly build:
Create a Web Project and add a WebGrid that is bound to some dummy data. Add a button and handle its Click event handler. Put this code in the Page to make it all work:
object sender,
/// <summary>
/// Creates a PDF Document by walking a flat WebGrid
/// </summary>
/// <param name="theGrid">This is the Grid that will be walked</param>
/// <param name="theResponse"> This is the current HTTP Response object that will receive the PDF</param>
/// <param name="openInline">Option to show the PDF within the Browser itself OR to present it as a download prompt. </param>
UltraWebGrid theGrid,
Report theReport = new Report();
//Table Pattern (think of this as a kind of "Style Sheet" for ITable
theTablePattern.Header.Repeat = true;
theTablePattern.Row.Cell.Background = new Background(Infragistics.Documents.Graphics.Brushes.LemonChiffon);
theTable.ApplyPattern(theTablePattern);
ITableCell theHeaderCell = null;
//Iterate through the Grid Cols and create corresponding headers in the ITable
theHeaderCell = theTable.Header.AddCell();
theHeaderText = theHeaderCell.AddText();
theHeaderText.AddContent(c.Header.Caption);
ITableCell theRowCell = null;
//Now create your rows:
theRow = theTable.AddRow();
theRowCell = theRow.AddCell();
theRowText = theRowCell.AddText();
theRowText.AddContent(r.Cells.FromKey(c.Key).Value.ToString());
//UNCOMMENT THIS LINE AND THE PAGES AND IMAGE THAT ARE ADDED AFTER THIS LINE
//DO NOT SHOW UP IN THE GENERATED REPORT: TomP
//thePageCount = theReport.Generate().Count; //1;
else
//add an image:
theSection = theReport.AddSection();
//Set up the response for publishing the Report:
//Opens in Browser Itself.
//Prompts user for a file download.
//Write out to the response.Output Stream and you are done.
/// This method returns an Infragistics
/// Image object that represents the
/// Image that exists at an accessible URL
/// <param name="theImageURL">
/// This is the URL to your image.
/// E.G.
/// http://ko.infragistics.com/App_Themes/Default/images/logo.gif</param>
/// <returns>The Infragistics.Documents.Graphics.Image object that is used in your Report</returns>
WebRequest theRequest = WebRequest.Create(theImageURL);
theResponse.Close();
theRequest = null;
Now David, when you put together your sample for Developer Support, be aware of the code comment I placed in my CreateReport( ) method. If you run the sample without calling the Report.Generate( ) then the resulting PDF is going to have the Rows of data, a blank page and then the Infragistics image on the last page.
If you uncomment the line where it says so, it WILL call the Report.Generate( ) method and therefore cause anything else added to the report (the blank pages and image) to not be included in the PUBLISHED report.
If this is indeed a bug, it will be checked out by a developer and the bug will be associated with your incident and therefore be expedited as quickly as possible. This is why I am asking you to submit the support incident, so that you get the quickest response.
Thanks,
Tom
Tom,Thanks for this information.After executing the Generate() method the pages that I add to the Report object don’t show up in the PDF. Any thoughts as to why?Thanks.
This is my code:
IProjectionPageCollection pages = report.Generate();bool needTwoAdditionalPage = ((pages.Count % 2) != 0);
Infragistics.Documents.Report.Section.ISection section = report.AddSection();
Infragistics.Documents.Report.Band.IBand band = section.AddBand();
// We want a blank page (front and back) so add a new page if needed in order// to get a double sided blank page.band.AddPageBreak();if (needTwoAdditionalPage){ band.AddPageBreak();}
Infragistics.Documents.Report.Text.IText text = band.AddText();text.Margins.Top = 450;text.Margins.Bottom = 15;
string appPath = MapPath(PATH_STARTING_POINT);text.AddContent(new Infragistics.Documents.Graphics.Image(appPath + "\\Images\\ContactHQ.jpg") , new Infragistics.Documents.Report.Indents(5) , Infragistics.Documents.Report.ImageAlignment.Middle);
-- David