Infragistics Home

Infragistics Forums

Infragistics community online discussions.
Welcome to Infragistics Forums Sign in | FAQ
in Search

How to determine the number of pages in a report.

Last post 04-08-2008 16:40 by [Infragistics] Tom Puglisi. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 03-12-2008 6:38

    How to determine the number of pages in a report.

    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.

    • Post Points: 20
  • 03-12-2008 9:30 In reply to

    Re: How to determine the number of pages in a report.

    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

    --Geoff
    Software Engineer in Release I
    • Post Points: 20
  • 03-13-2008 5:15 In reply to

    Re: How to determine the number of pages in a report.

    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.

    e.g.

    report.Publish(pathAndNameToPdf_FiileSystemPath, Infragistics.Documents.Report.FileFormat.PDF);

    Is there some type of pre-publish option?

    Thanks.    -- David

    • Post Points: 20
  • 04-07-2008 10:49 In reply to

    Re: How to determine the number of pages in a report.

    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:

    IProjectionPageCollection pages = report.Generate();

    Bitmap theBitMap = null;

    Graphics theGraphics = null;

    Infragistics.Documents.Graphics.Graphics infraGraphics = null;

    string ImageFile = string.Empty;

    int pageNum = 1; foreach (IProjectionPage page in pages)

    {

     

    int width = (int)Infragistics.Documents.Utils.Converter.PointsToPixels(page.Width);int height = (int)Infragistics.Documents.Utils.Converter.PointsToPixels(page.Height);

     

    theBitMap = new Bitmap(width, height);

    theGraphics = Graphics.FromImage(theBitMap);infraGraphics = new Infragistics.Documents.Graphics.Graphics(theGraphics);

    page.Draw(infraGraphics);

    infraGraphics.DrawString(20, 20, "Page: " + pageNum.ToString());

    infraGraphics.DrawString(20, 30, "Hey! This Was Drawn Directly Onto The Infragistics ");

    infraGraphics.DrawString(20, 40, "Graphics Object!");

    ImageFile = Application.StartupPath + @"\" + DateTime.Now.Ticks.ToString() + ".jpg";

     

    theBitMap.Save(ImageFile, System.Drawing.Imaging.
    ImageFormat.Jpeg);System.Diagnostics.Process.Start(ImageFile);

    pageNum ++;

    }

    Tom Puglisi
    Technical Program Manager, Documentation, MCP
    Infragistics, Inc
    • Post Points: 20
  • 04-08-2008 8:59 In reply to

    Re: How to determine the number of pages in a report.

    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

    • Post Points: 20
  • 04-08-2008 16:40 In reply to

    Re: How to determine the number of pages in a report.

    Hey David,

    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:

     

    protected void Button1_Click(

    object sender,

    EventArgs e)

    {

    this.CreateReport(this.UltraWebGrid1, this.Response, false);

    }

    /// <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>

    public void CreateReport(

    UltraWebGrid theGrid,

    HttpResponse theResponse, bool openInline)

    {

    Report theReport = new Report();

    ISection theSection = theReport.AddSection();

    //Table Pattern (think of this as a kind of "Style Sheet" for ITable

    TablePattern theTablePattern = new TablePattern();

    theTablePattern.Header.Repeat = true;

    theTablePattern.Header.Cell.Background = new Background(Infragistics.Documents.Graphics.Brushes.Red);

    theTablePattern.Row.Cell.Background = new Background(Infragistics.Documents.Graphics.Brushes.LemonChiffon);

    ITable theTable = theSection.AddTable();theSection.PageMargins = new Margins(20f);

    theTable.ApplyPattern(theTablePattern);

    ITableCell theHeaderCell = null;

    IText theHeaderText = null;

    //Iterate through the Grid Cols and create corresponding headers in the ITable

    foreach (UltraGridColumn c in theGrid.Columns)

    {

    theHeaderCell = theTable.Header.AddCell();

    theHeaderText = theHeaderCell.AddText();

    theHeaderText.Style.Brush =
    new Infragistics.Documents.Graphics.SolidColorBrush(Infragistics.Documents.Graphics.Colors.WhiteSmoke);

    theHeaderText.AddContent(c.Header.Caption);

    }

    ITableRow theRow = null;

    ITableCell theRowCell = null;

    IText theRowText = null;

    //Now create your rows:

    foreach (UltraGridRow r in theGrid.Rows)

    {

    theRow = theTable.AddRow();

    foreach (UltraGridColumn c in this.UltraWebGrid1.Columns)

    {

    theRowCell = theRow.AddCell();

    theRowText = theRowCell.AddText();

    theRowText.Style.Brush =
    new Infragistics.Documents.Graphics.SolidColorBrush(Infragistics.Documents.Graphics.Colors.Black);

    theRowText.AddContent(r.Cells.FromKey(c.Key).Value.ToString());

    }

    }

     

    int thePageCount = 0;

     

    //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;

    if (thePageCount % 2 != 0)

    {

    theSection.AddPage().AddText(50f, 50f).AddContent(
    "This page intentionally left blank #1");

    }

    else

    {

    theSection.AddPage().AddText(50f, 50f).AddContent(
    "This page intentionally left blank #2");theSection.AddPage().AddText(50f, 50f).AddContent("This page intentionally left blank #3");

    }

    //add an image:

    theSection = theReport.AddSection();

    theSection.AddText().AddContent(
    this.GetImage(@"http://www.infragistics.com/App_Themes/Default/images/logo.gif"));

    //Set up the response for publishing the Report:

    theResponse.ContentType = "application/pdf";if (openInline)

    {

    //Opens in Browser Itself.

    theResponse.AddHeader("content-disposition", "inline; filename=Document.pdf");

    }

    else

    {

    //Prompts user for a file download.

    theResponse.AddHeader("content-disposition", "attachment; filename=Document.pdf");

    }

    //Write out to the response.Output Stream and you are done.

    theReport.Publish(theResponse.OutputStream, FileFormat.PDF);

    }

    /// <summary>

    /// This method returns an Infragistics

    /// Image object that represents the

    /// Image that exists at an accessible URL

    /// </summary>

    /// <param name="theImageURL">

    /// This is the URL to your image.

    /// E.G.

    /// http://www.infragistics.com/App_Themes/Default/images/logo.gif</param>

    /// <returns>The Infragistics.Documents.Graphics.Image object that is used in your Report</returns>

    public Infragistics.Documents.Graphics.Image GetImage(string theImageURL)

    {

    System.Drawing.
    Image theImage = null;

    WebRequest theRequest = WebRequest.Create(theImageURL);

    WebResponse theResponse = theRequest.GetResponse();

     

    theImage = System.Drawing.
    Image.FromStream(theResponse.GetResponseStream());

    theResponse.Close();

    theResponse =
    null;

    theRequest = null;

    return new Infragistics.Documents.Graphics.Image(theImage);

    }

    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 Puglisi
    Technical Program Manager, Documentation, MCP
    Infragistics, Inc
    • Post Points: 5
Page 1 of 1 (6 items)
Powered by Community Server (Commercial Edition), by Telligent Systems